def test_add_file_handler(self): logger = logging.getLogger("file") add_file_handler("file") self.assertEqual(len(logger.handlers), 1) add_file_handler("file") self.assertEqual(len(logger.handlers), 1)
def test_add_file_and_screen_handlers(self): logger = logging.getLogger("both") add_screen_handler("both") self.assertEqual(len(logger.handlers), 1) add_file_handler("both") self.assertEqual(len(logger.handlers), 2)
def test_add_file_handler_new_filename(self): logger = logging.getLogger("file") add_file_handler("file") self.assertTrue(os.path.exists(self.logfile)) self.assertEqual(len(logger.handlers), 1) new_logfile = os.path.join(self.output_test_dir, "test.log") add_file_handler("file", filename=new_logfile) self.assertTrue(os.path.exists(new_logfile)) self.assertEqual(len(logger.handlers), 1)
def test_setup_logger_debug(self): setup_logger("uncertainpy", level="debug") logger = logging.getLogger("uncertainpy") add_file_handler("uncertainpy", filename=self.full_path) logger.debug("debug message") logger.info("info message") logger.warning("warning message") logger.error("error message") logger.critical("critical message") time.sleep(0.1) self.assertEqual(len(open(self.full_path).readlines()), 5)
def test_setup_setup_module_logger(self): model = Model(logger_level=None) setup_module_logger(class_instance=model, level="info") logger = logging.getLogger("uncertainpy.models.model.Model") add_file_handler("uncertainpy", filename=self.full_path) logger.debug("debug message") logger.info("info message") logger.warning("warning message") logger.error("error message") logger.critical("critical message") time.sleep(0.1) self.assertEqual(len(open(self.full_path).readlines()), 4)