Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_logger_tqdm_fallback(self):
logging.setLoggerClass(IPDLogger)
logger = logging.getLogger("icloudpd-test")
logger.log = MagicMock()
logger.set_tqdm_description("foo")
logger.log.assert_called_once_with(logging.INFO, "foo")
logger.log = MagicMock()
logger.tqdm_write("bar")
logger.log.assert_called_once_with(logging.INFO, "bar")
logger.set_tqdm(MagicMock())
logger.tqdm.write = MagicMock()
logger.tqdm.set_description = MagicMock()
logger.log = MagicMock()
logger.set_tqdm_description("baz")
logger.tqdm.set_description.assert_called_once_with("baz")
logger.tqdm_write("qux")
def setup_logger(loglevel=DEBUG):
"""Set up logger and add stdout handler"""
logging.setLoggerClass(IPDLogger)
logger = logging.getLogger("icloudpd")
logger.setLevel(loglevel)
has_stdout_handler = False
for handler in logger.handlers:
if handler.name == "stdoutLogger":
has_stdout_handler = True
if not has_stdout_handler:
formatter = logging.Formatter(
fmt="%(asctime)s %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
stdout_handler = logging.StreamHandler(stream=sys.stdout)
stdout_handler.setFormatter(formatter)
stdout_handler.name = "stdoutLogger"
logger.addHandler(stdout_handler)
return logger