def test_logger_log_level(self): # type: () -> None for envvar in ("CALIBRE_DEVELOP_FROM", "CALIBRE_DEBUG"): if envvar in os.environ: del os.environ[envvar] logger = common.Logger() self.assertEqual(logger.log_level, "INFO") os.environ["CALIBRE_DEVELOP_FROM"] = "true" logger = common.Logger() self.assertEqual(logger.log_level, "DEBUG") del os.environ["CALIBRE_DEVELOP_FROM"] os.environ["CALIBRE_DEBUG"] = "1" logger = common.Logger() self.assertEqual(logger.log_level, "DEBUG") del os.environ["CALIBRE_DEBUG"]
def test_logger_logs(self): logger = common.Logger() logger.debug("Hello, World") logger.print_formatted_log.assert_called_with("DEBUG", "Hello, World") logger("Hello, World") logger.print_formatted_log.assert_called_with("INFO", "Hello, World") logger.print_formatted_log.reset_mock() logger._prints.reset_mock() logger._tag_args.reset_mock() logger.exception("Oh noes!") logger._tag_args.assert_called_with("ERROR", "Oh noes!") self.assertEqual(logger._prints.call_count, 2)
def test_logger_ensure_unicode_from_bytes(self) -> None: for o in TEST_STRINGS: for enc in o["encodings"]: with mock.patch( "calibre_plugins.kobotouch_extended.common.preferred_encoding", enc ), mock.patch( "calibre_plugins.kobotouch_extended.common.time.strftime", mock.MagicMock(return_value=TEST_TIME), ): logger = common.Logger() for msg in o["test_strings"]: test_tagged = logger._tag_args("DEBUG", msg) self.assertListEqual( test_tagged, [ "{timestr} [{level}] {msg}".format( timestr=TEST_TIME, level="DEBUG", msg=msg ), ], )