class LoggingTestCase(unittest.TestCase): def setUp(self): self.log_file_name = "test.log" self.logging = Logging( log_file_name=self.log_file_name, 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)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse(file_buffer.read().find('WARNING [LoggingTestCase.test_warning') == -1) 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)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse(file_buffer.read().find('INFO [LoggingTestCase.test_info') == -1) file_buffer.close() def test_error(self): self.assertRaises(Exception, self.logging.error, ("LoggingTestCase", "test_error", "Test log message")) # test that the log file has been generated self.assertTrue(os.path.exists(self.logging.log_file)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse(file_buffer.read().find('ERROR [LoggingTestCase.test_error') == -1) file_buffer.close() def test_critical(self): self.assertRaises(Exception, self.logging.critical, ("LoggingTestCase", "test_critical", "Test log message")) # test that the log file has been generated self.assertTrue(os.path.exists(self.logging.log_file)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse(file_buffer.read().find('CRITICAL [LoggingTestCase.test_critical]') == -1) file_buffer.close() def tearDown(self): pass#clear_log(self.logging.log_file)
class LoggingTestCase(unittest.TestCase): def setUp(self): self.log_file_name = "test.log" self.logging = Logging( log_file_name=self.log_file_name, 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)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse(file_buffer.read().find( 'WARNING [LoggingTestCase.test_warning') == -1) 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)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse( file_buffer.read().find('INFO [LoggingTestCase.test_info') == -1) file_buffer.close() def test_error(self): self.assertRaises( Exception, self.logging.error, ("LoggingTestCase", "test_error", "Test log message")) # test that the log file has been generated self.assertTrue(os.path.exists(self.logging.log_file)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse( file_buffer.read().find('ERROR [LoggingTestCase.test_error') == -1) file_buffer.close() def test_critical(self): self.assertRaises( Exception, self.logging.critical, ("LoggingTestCase", "test_critical", "Test log message")) # test that the log file has been generated self.assertTrue(os.path.exists(self.logging.log_file)) # test that the correct output has been stored in the first line of the log file file_buffer = open(self.logging.log_file, "rb") self.assertFalse(file_buffer.read().find( 'CRITICAL [LoggingTestCase.test_critical]') == -1) file_buffer.close() def tearDown(self): pass #clear_log(self.logging.log_file)