2017-10-26 07:36:23 +02:00
|
|
|
import logging
|
|
|
|
|
2018-09-08 22:53:37 +02:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
2017-10-26 07:36:23 +02:00
|
|
|
from borgmatic import verbosity as module
|
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
|
2018-09-08 22:53:37 +02:00
|
|
|
def insert_logging_mock(log_level):
|
2018-12-11 07:20:57 +01:00
|
|
|
'''
|
|
|
|
Mock the isEnabledFor from Python logging.
|
|
|
|
'''
|
2018-09-08 22:53:37 +02:00
|
|
|
logging = flexmock(module.logging.Logger)
|
2018-12-11 07:20:57 +01:00
|
|
|
logging.should_receive('isEnabledFor').replace_with(lambda level: level >= log_level)
|
2018-09-08 22:53:37 +02:00
|
|
|
logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
|
|
|
|
|
2017-10-26 07:36:23 +02:00
|
|
|
|
|
|
|
def test_verbosity_to_log_level_maps_known_verbosity_to_log_level():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
|
|
|
|
|
assert module.verbosity_to_log_level(module.VERBOSITY_ERROR) == logging.ERROR
|
|
|
|
assert module.verbosity_to_log_level(module.VERBOSITY_ANSWER) == module.borgmatic.logger.ANSWER
|
2017-10-26 07:36:23 +02:00
|
|
|
assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO
|
2018-09-08 22:53:37 +02:00
|
|
|
assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG
|
2017-10-26 07:36:23 +02:00
|
|
|
|
|
|
|
|
2018-03-04 07:17:39 +01:00
|
|
|
def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
|
|
2018-03-04 07:17:39 +01:00
|
|
|
assert module.verbosity_to_log_level('my pants') == logging.WARNING
|