# Verbose, notice, and spam log levels for Python's logging module.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: July 26, 2016
# URL: https://verboselogs.readthedocs.io

"""Test suite for the `verboselogs` package."""

# Standard library modules.
import logging
import random
import string
import sys
import unittest

# Modules included in our package.
import verboselogs

# Test dependencies.
import coloredlogs
import mock


class VerboseLogsTestCase(unittest.TestCase):

    """Container for the `verboselogs` tests."""

    def setUp(self):
        """Enable logging to the terminal."""
        coloredlogs.install(level='DEBUG')

    def test_install(self):
        """Test the :func:`verboselogs.install()` function."""
        default_logger = logging.getLogger(random_string())
        assert isinstance(default_logger, logging.Logger)
        verboselogs.install()
        custom_logger = logging.getLogger(random_string())
        assert isinstance(custom_logger, verboselogs.VerboseLogger)

    def test_custom_methods(self):
        """
        Test logging functions.

        Test :func:`~verboselogs.VerboseLogger.verbose()`,
        :func:`~verboselogs.VerboseLogger.notice()`, and
        :func:`~verboselogs.VerboseLogger.spam()`.
        """
        for name in 'notice', 'verbose', 'spam':
            logger = verboselogs.VerboseLogger(random_string())
            logger._log = mock.MagicMock()
            level = getattr(verboselogs, name.upper())
            method = getattr(logger, name.lower())
            message = "Any random message"
            method(message)
            logger._log.assert_called_with(level, message, ())

    def test_pylint_plugin(self):
        """Test the :mod:`verboselogs.pylint` module."""
        saved_args = sys.argv
        try:
            sys.argv = ['pylint', '--load-plugins', 'verboselogs.pylint', '--errors-only', 'verboselogs']
            __import__('pylint').run_pylint()
        except SystemExit:
            pass
        finally:
            sys.argv = saved_args


def random_string(length=25):
    """Generate a random string."""
    return ''.join(random.choice(string.ascii_letters) for i in range(length))

@@ -129,21 +129,22 @@
 ge: 
-July 26
+August 7
 , 201
-6
+7
 %0A# U
@@ -1032,22 +1032,21 @@
 est_
-custom
+notice
 _method
-s
 (sel
@@ -1064,41 +1064,149 @@
  %22%22%22
-%0A        Test logging functions.%0A
+Test the :func:%60~verboselogs.VerboseLogger.notice()%60 method.%22%22%22%0A        self.check_custom_level('notice')%0A%0A    def test_verbose_method(self):
 %0A   
@@ -1210,21 +1210,28 @@
         
+%22%22%22
 Test 
+the 
 :func:%60~
@@ -1270,74 +1270,115 @@
 e()%60
-,%0A        :func:%60~verboselogs.VerboseLogger.notice()%60, and%0A       
+ method.%22%22%22%0A        self.check_custom_level('verbose')%0A%0A    def test_spam_method(self):%0A        %22%22%22Test the
  :fu
@@ -1419,18 +1419,16 @@
 m()%60
-.%0A        
+ method.
 %22%22%22%0A
@@ -1439,61 +1439,130 @@
     
-for name in 'notice', 'verbose', 'spam':%0A     
+self.check_custom_level('spam')%0A%0A    def check_custom_level(self, name):%0A        %22%22%22Check a custom log method.%22%22%22%0A
        
+ 
 logg
@@ -1609,36 +1609,32 @@
 ring())%0A        
-    
 logger._log = mo
@@ -1656,20 +1656,16 @@
         
-  
-  
 level = 
@@ -1695,28 +1695,24 @@
 me.upper())%0A
-    
         meth
@@ -1754,20 +1754,16 @@
         
-    
 message 
@@ -1789,28 +1789,24 @@
 ge%22%0A        
-    
 method(messa
@@ -1809,20 +1809,16 @@
 essage)%0A
-    
         

Make breakage in test suite more apparent