#!/usr/bin/env python
# -*- coding: utf8 -*-

# ============================================================================
#  Copyright (c) 2014-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#      http://www.apache.org/licenses/LICENSE-2.0
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
# ============================================================================

from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

from attributecode import CRITICAL
from attributecode import DEBUG
from attributecode import ERROR
from attributecode import INFO
from attributecode import NOTSET
from attributecode import WARNING
from attributecode import cmd
from attributecode import Error


# NB: these tests depends on py.test stdout/err capture capabilities
def test_log_errors(capsys):
    quiet = False
    errors = [Error(CRITICAL, 'msg1'),
              Error(ERROR, 'msg2'),
              Error(INFO, 'msg3'),
              Error(WARNING, 'msg4'),
              Error(DEBUG, 'msg4'),
              Error(NOTSET, 'msg4'),
              ]
    cmd.log_errors(errors, quiet, base_dir='')
    out, err = capsys.readouterr()
    expected_out = '''CRITICAL: msg1
ERROR: msg2
INFO: msg3
WARNING: msg4
DEBUG: msg4
NOTSET: msg4
'''
    assert '' == err
    assert expected_out == out


def test_log_errors_with_quiet(capsys):
    quiet = True
    errors = [Error(CRITICAL, 'msg1'),
              Error(ERROR, 'msg2'),
              Error(INFO, 'msg3'),
              Error(WARNING, 'msg4'),
              Error(DEBUG, 'msg4'),
              Error(NOTSET, 'msg4'),
              ]
    cmd.log_errors(errors, quiet, base_dir='')
    out, err = capsys.readouterr()
    assert '' == out
    assert '' == err
@@ -1323,16 +1323,36 @@
 = False%0A
+    show_all = True%0A
     erro
@@ -1374,32 +1374,32 @@
 TICAL, 'msg1'),%0A
-
               Er
@@ -1605,32 +1605,42 @@
 s(errors, quiet,
+ show_all,
  base_dir='')%0A  
@@ -1829,16 +1829,551 @@
 = out%0A%0A%0A
+def test_log_errors_without_show_all(capsys):%0A    quiet = False%0A    show_all = False%0A    errors = %5BError(CRITICAL, 'msg1'),%0A              Error(ERROR, 'msg2'),%0A              Error(INFO, 'msg3'),%0A              Error(WARNING, 'msg4'),%0A              Error(DEBUG, 'msg4'),%0A              Error(NOTSET, 'msg4'),%0A              %5D%0A    cmd.log_errors(errors, quiet, show_all, base_dir='')%0A    out, err = capsys.readouterr()%0A    expected_out = '''CRITICAL: msg1%0AERROR: msg2%0AWARNING: msg4%0A'''%0A    assert '' == err%0A    assert expected_out == out%0A%0A%0A
 def test
@@ -2413,32 +2413,52 @@
    quiet = True%0A
+    show_all = True%0A
     errors = %5BEr
@@ -2670,32 +2670,32 @@
               %5D%0A
-
     cmd.log_erro
@@ -2711,16 +2711,26 @@
 , quiet,
+ show_all,
  base_di

Add test code for `--show-all` option.