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_handler():
"""
Tests prepare_logging() use case.
Tests that prepare_logging() will set logger level appropriately, attach a
FileHandler if a directory is passed, and set log file to the correct mode.
"""
logger.prepare_logging('logfiles', 'debug')
this_logger = logging.getLogger()
if logger.HAS_PYWIN32:
log_hdlr = this_logger.handlers.pop()
assert isinstance(log_hdlr, logging.handlers.NTEventLogHandler)
assert log_hdlr.level == logging.DEBUG
log_hdlr = this_logger.handlers.pop()
assert isinstance(log_hdlr, logging.FileHandler)
assert log_hdlr.level == logging.DEBUG
assert oschmod.get_mode(
os.path.join('logfiles', 'watchmaker.log')) == 0o600
def test_log_if_no_log_directory_given(caplog):
"""
Tests prepare_logging() use case.
Tests that not passing in a path to a logging directory will
produce a logging message.
"""
logger.prepare_logging(None, 'info')
assert 'Watchmaker will not be logging to a file!' in caplog.text
def main(extra_arguments=None, **kwargs):
"""Entry point for Watchmaker cli."""
prepare_logging(kwargs['log_dir'], kwargs['log_level'])
sys.excepthook = exception_hook
watchmaker_arguments = watchmaker.Arguments(**dict(
extra_arguments=extra_arguments,
**kwargs
))
watchmaker_client = watchmaker.Client(watchmaker_arguments)
sys.exit(watchmaker_client.install())