Exemple #1
0
class LoggingTestCase(unittest.TestCase):
    def setUp(self):
        self.log_file_path = "/tmp/test.log"
        self.logging = Logging(
            log_file_path=self.log_file_path,
            debug=True
        )
        
    def test_warning(self):
        self.logging.warning("LoggingTestCase", "test_warning", "Test log message")
        
        # test that the log file has been generated
        self.assertTrue(os.path.exists(self.logging.log_file_path))
        
        # test that the correct output has been stored in the first line of the log file
        file_buffer = open(self.logging.log_file_path, "rb")
        self.assertIn('WARNING [LoggingTestCase.test_warning', file_buffer.read())
        file_buffer.close()
        
    def test_info(self):
        self.logging.info("LoggingTestCase", "test_info", "Test log message")
        
        # test that the log file has been generated
        self.assertTrue(os.path.exists(self.logging.log_file_path))
        
        # test that the correct output has been stored in the first line of the log file
        file_buffer = open(self.logging.log_file_path, "rb")
        self.assertIn('INFO [LoggingTestCase.test_info', file_buffer.read())
        file_buffer.close()
        
    def test_error(self):
        self.logging.error("LoggingTestCase", "test_warning", "Test log message")
        
        # test that the log file has been generated
        self.assertTrue(os.path.exists(self.logging.log_file_path))
        
        # test that the correct output has been stored in the first line of the log file
        file_buffer = open(self.logging.log_file_path, "rb")
        self.assertIn('ERROR [LoggingTestCase.test_error', file_buffer.read())
        file_buffer.close()
        
    def test_critical(self):
        self.logging.critical("LoggingTestCase", "test_warning", "Test log message")
        
        # test that the log file has been generated
        self.assertTrue(os.path.exists(self.logging.log_file_path))
        
        # test that the correct output has been stored in the first line of the log file
        file_buffer = open(self.logging.log_file_path, "rb")
        self.assertIn('CRITICAL [LoggingTestCase.test_critical]', file_buffer.read())
        file_buffer.close()
        
    def tearDown(self):
        clear_log(self.logging.log_file_path)
Exemple #2
0
 def setUp(self):
     self.log_file_path = "/tmp/test.log"
     self.logging = Logging(
         log_file_path=self.log_file_path,
         debug=True
     )