def setUp(self):
     self.saveDir = os.path.abspath('.')
     os.chdir( _THIS_DIR )
     self.OUT = RunContext( 'runcontexttest' )
     self.log_main = get_list( 'main' )
     del self.log_main[:]
     self.log_root = get_list( 'root' )
     del self.log_root[:]
     self.log_sql = get_list( 'sql' )
     del self.log_sql[:]
    def test_logger_isolation(self):
        rc_independent = RunContext( 'independent' )
        self.OUT.info( "Message 1" )
        rc_independent.info( "Message 2" )
        expected_list = [
            r'INFO  runcontexttest ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 1',
        ]
        
        for expected, actual in zip( expected_list, get_list( 'main' ) ):
            if not re.match(expected, actual):
                self.fail( "Expected message \"{}\", found \"{}\"".format( expected, actual ) )

        expected_list = [
            r'INFO  independent ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 2',
        ]
        
        for expected, actual in zip( expected_list, get_list( 'independent' ) ):
            if not re.match(expected, actual):
                self.fail( "Expected message \"{}\", found \"{}\"".format( expected, actual ) )
 def test_logger_SQL1(self):
     logger = self.OUT.get_sql_logger()
     logger.debug( 'Message 1' )
     logger.info( 'Message 2' )
     logger.warning( 'Message 3' )
     logger.error( 'This error is only a drill. In the event of a real error, the unit test would fail.' )
     expected_list = [
         r'ERROR runcontexttest\.sql ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: This error is only a drill\. In the event of a real error, the unit test would fail\.',
     ]
     
     for expected, actual in zip( expected_list, get_list( 'sql' ) ):
         if not re.match(expected, actual):
             self.fail( "Expected message \"{}\", found \"{}\"".format( expected, actual ) )
 def test_logger_main1(self):
     self.OUT.debug( 'Message 1' )
     self.OUT.info( 'Message 2' )
     self.OUT.warning( 'Message 3' )
     self.OUT.error( 'This error is only a drill. In the event of a real error, the unit test would fail.' )
     expected_list = [
         r'DEBUG runcontexttest ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 1',
         r'INFO  runcontexttest ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 2',
         r'WARNING runcontexttest ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 3',
         r'ERROR runcontexttest ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: This error is only a drill\. In the event of a real error, the unit test would fail\.',
     ]
     
     for expected, actual in zip( expected_list, get_list( 'main' ) ):
         if not re.match(expected, actual):
             self.fail( "Expected message \"{}\", found \"{}\"".format( expected, actual ) )
 def test_logger_another(self):
     logger = self.OUT.get_logger( 'some.class' )
     self.assertEqual( 'runcontexttest.some.class', logger.name,
                       "Expected logger named runcontexttest.some.class, found {}".format( logger.name ) )
     logger.debug( 'Message 1' )
     logger.info( 'Message 2' )
     logger.warning( 'Message 3' )
     logger.error( 'This error is only a drill. In the event of a real error, the unit test would fail.' )
     expected_list = [
         r'DEBUG runcontexttest\.some\.class ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 1',
         r'INFO  runcontexttest\.some\.class ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 2',
         r'WARNING runcontexttest\.some\.class ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: Message 3',
         r'ERROR runcontexttest\.some\.class ....-..-.. ..:..:..,... test_runcontext.py      \[...  ]: This error is only a drill\. In the event of a real error, the unit test would fail\.',
     ]
     
     for expected, actual in zip( expected_list, get_list( 'main' ) ):
         if not re.match(expected, actual):
             self.fail( "Expected message \"{}\", found \"{}\"".format( expected, actual ) )