From 3b5564babff62dca3e46fffe77f3363d5a1e786e Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Sun, 15 Jul 2018 10:04:34 +0200 Subject: [PATCH 1/9] First version that uses the log level for verboseness Still needs some renaming and fine tuning of log settings. --- borgmatic/borg/check.py | 16 ++++---- borgmatic/borg/create.py | 10 ++--- borgmatic/borg/extract.py | 16 ++++---- borgmatic/borg/info.py | 11 ++---- borgmatic/borg/list.py | 11 ++---- borgmatic/borg/prune.py | 13 +++---- borgmatic/commands/borgmatic.py | 9 +---- borgmatic/tests/unit/borg/test_check.py | 20 +++++----- borgmatic/tests/unit/borg/test_create.py | 46 ++++++++--------------- borgmatic/tests/unit/borg/test_extract.py | 16 ++++---- borgmatic/tests/unit/borg/test_info.py | 17 ++++----- borgmatic/tests/unit/borg/test_list.py | 19 +++++----- borgmatic/tests/unit/borg/test_prune.py | 23 ++++++------ 13 files changed, 93 insertions(+), 134 deletions(-) diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index d5bdb820..f17f3508 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -3,7 +3,6 @@ import os import subprocess from borgmatic.borg import extract -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS DEFAULT_CHECKS = ('repository', 'archives') @@ -74,8 +73,7 @@ def _make_check_flags(checks, check_last=None, prefix=None): ) + last_flags + prefix_flags -def check_archives(verbosity, repository, storage_config, consistency_config, local_path='borg', - remote_path=None): +def check_archives(repository, storage_config, consistency_config, local_path='borg', remote_path=None): ''' Given a verbosity flag, a local or remote repository path, a storage config dict, a consistency config dict, and a local/remote commands to run, check the contained Borg archives for @@ -91,10 +89,12 @@ def check_archives(verbosity, repository, storage_config, consistency_config, lo remote_path_flags = ('--remote-path', remote_path) if remote_path else () lock_wait = storage_config.get('lock_wait', None) lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else () - verbosity_flags = { - VERBOSITY_SOME: ('--info',), - VERBOSITY_LOTS: ('--debug',), - }.get(verbosity, ()) + verbosity_flags = () + if logger.isEnabledFor(logging.INFO): + verbosity_flags = ('--info',) + if logger.isEnabledFor(logging.DEBUG): + verbosity_flags = ('--debug',) + prefix = consistency_config.get('prefix') full_command = ( @@ -109,4 +109,4 @@ def check_archives(verbosity, repository, storage_config, consistency_config, lo subprocess.check_call(full_command, stdout=stdout, stderr=subprocess.STDOUT) if 'extract' in checks: - extract.extract_last_archive_dry_run(verbosity, repository, lock_wait, local_path, remote_path) + extract.extract_last_archive_dry_run(repository, lock_wait, local_path, remote_path) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 632f39c1..eef2adcd 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -5,8 +5,6 @@ import os import subprocess import tempfile -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS - logger = logging.getLogger(__name__) @@ -105,7 +103,7 @@ def _make_exclude_flags(location_config, exclude_filename=None): def create_archive( - verbosity, dry_run, repository, location_config, storage_config, local_path='borg', remote_path=None, + dry_run, repository, location_config, storage_config, local_path='borg', remote_path=None, ): ''' Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a @@ -148,10 +146,8 @@ def create_archive( + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + { - VERBOSITY_SOME: ('--info',) if dry_run else ('--info', '--stats',), - VERBOSITY_LOTS: ('--debug', '--list',) if dry_run else ('--debug', '--list', '--stats',), - }.get(verbosity, ()) + + (('--list', '--filter', 'AME', '--info', '--stats') if logger.isEnabledFor(logging.INFO) else ()) + + (('--debug', ) if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) ) diff --git a/borgmatic/borg/extract.py b/borgmatic/borg/extract.py index d3d62a3c..9b0cb408 100644 --- a/borgmatic/borg/extract.py +++ b/borgmatic/borg/extract.py @@ -2,23 +2,23 @@ import logging import sys import subprocess -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS - logger = logging.getLogger(__name__) -def extract_last_archive_dry_run(verbosity, repository, lock_wait=None, local_path='borg', remote_path=None): +def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', remote_path=None): ''' Perform an extraction dry-run of just the most recent archive. If there are no archives, skip the dry-run. ''' remote_path_flags = ('--remote-path', remote_path) if remote_path else () lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else () - verbosity_flags = { - VERBOSITY_SOME: ('--info',), - VERBOSITY_LOTS: ('--debug',), - }.get(verbosity, ()) + if logger.isEnabledFor(logging.DEBUG): + verbosity_flags = ('--debug',) + elif logger.isEnabledFor(logging.INFO): + verbosity_flags = ('--info',) + else: + verbosity_flags = () full_list_command = ( local_path, 'list', @@ -32,7 +32,7 @@ def extract_last_archive_dry_run(verbosity, repository, lock_wait=None, local_pa if not last_archive_name: return - list_flag = ('--list',) if verbosity == VERBOSITY_LOTS else () + list_flag = ('--list',) if logger.isEnabledFor(logging.DEBUG) else () full_extract_command = ( local_path, 'extract', '--dry-run', diff --git a/borgmatic/borg/info.py b/borgmatic/borg/info.py index c55e3651..89a18a6f 100644 --- a/borgmatic/borg/info.py +++ b/borgmatic/borg/info.py @@ -1,14 +1,11 @@ import logging import subprocess -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS - logger = logging.getLogger(__name__) -def display_archives_info(verbosity, repository, storage_config, local_path='borg', - remote_path=None): +def display_archives_info(repository, storage_config, local_path='borg', remote_path=None): ''' Given a verbosity flag, a local or remote repository path, and a storage config dict, display summary information for Borg archives in the repository. @@ -19,10 +16,8 @@ def display_archives_info(verbosity, repository, storage_config, local_path='bor (local_path, 'info', repository) + (('--remote-path', remote_path) if remote_path else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + { - VERBOSITY_SOME: ('--info',), - VERBOSITY_LOTS: ('--debug',), - }.get(verbosity, ()) + + (('--info',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ()) ) logger.debug(' '.join(full_command)) diff --git a/borgmatic/borg/list.py b/borgmatic/borg/list.py index 989f8817..af89e553 100644 --- a/borgmatic/borg/list.py +++ b/borgmatic/borg/list.py @@ -1,13 +1,11 @@ import logging import subprocess -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS - logger = logging.getLogger(__name__) -def list_archives(verbosity, repository, storage_config, local_path='borg', remote_path=None): +def list_archives(repository, storage_config, local_path='borg', remote_path=None): ''' Given a verbosity flag, a local or remote repository path, and a storage config dict, list Borg archives in the repository. @@ -18,11 +16,8 @@ def list_archives(verbosity, repository, storage_config, local_path='borg', remo (local_path, 'list', repository) + (('--remote-path', remote_path) if remote_path else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + { - VERBOSITY_SOME: ('--info',), - VERBOSITY_LOTS: ('--debug',), - }.get(verbosity, ()) + + (('--info',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ()) ) - logger.debug(' '.join(full_command)) subprocess.check_call(full_command) diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index 09e1c9b3..61e12097 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -1,7 +1,6 @@ import logging import subprocess -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS logger = logging.getLogger(__name__) @@ -32,10 +31,9 @@ def _make_prune_flags(retention_config): ) -def prune_archives(verbosity, dry_run, repository, storage_config, retention_config, - local_path='borg', remote_path=None): +def prune_archives(dry_run, repository, storage_config, retention_config, local_path='borg', remote_path=None): ''' - Given verbosity/dry-run flags, a local or remote repository path, a storage config dict, and a + Given dry-run flag, a local or remote repository path, a storage config dict, and a retention config dict, prune Borg archives according to the retention policy specified in that configuration. ''' @@ -54,10 +52,9 @@ def prune_archives(verbosity, dry_run, repository, storage_config, retention_con + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + { - VERBOSITY_SOME: ('--info', '--stats',), - VERBOSITY_LOTS: ('--debug', '--stats', '--list'), - }.get(verbosity, ()) + + (('--stats',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--info',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--debug', '--list') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) ) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index a5e4b7a6..c26ffdc1 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -10,7 +10,7 @@ from borgmatic.borg import check as borg_check, create as borg_create, prune as from borgmatic.commands import hook from borgmatic.config import collect, convert, validate from borgmatic.signals import configure_signals -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS, verbosity_to_log_level +from borgmatic.verbosity import verbosity_to_log_level logger = logging.getLogger(__name__) @@ -83,7 +83,7 @@ def parse_arguments(*arguments): parser.add_argument( '-v', '--verbosity', type=int, - help='Display verbose progress (1 for some, 2 for lots)', + help='Display verbose progress (1 for INFO, 2 for DEBUG)', ) args = parser.parse_args(arguments) @@ -123,7 +123,6 @@ def run_configuration(config_filename, args): # pragma: no cover if args.prune: logger.info('{}: Pruning archives{}'.format(repository, dry_run_label)) borg_prune.prune_archives( - args.verbosity, args.dry_run, repository, storage, @@ -134,7 +133,6 @@ def run_configuration(config_filename, args): # pragma: no cover if args.create: logger.info('{}: Creating archive{}'.format(repository, dry_run_label)) borg_create.create_archive( - args.verbosity, args.dry_run, repository, location, @@ -145,7 +143,6 @@ def run_configuration(config_filename, args): # pragma: no cover if args.check: logger.info('{}: Running consistency checks'.format(repository)) borg_check.check_archives( - args.verbosity, repository, storage, consistency, @@ -155,7 +152,6 @@ def run_configuration(config_filename, args): # pragma: no cover if args.list: logger.info('{}: Listing archives'.format(repository)) borg_list.list_archives( - args.verbosity, repository, storage, local_path=local_path, @@ -164,7 +160,6 @@ def run_configuration(config_filename, args): # pragma: no cover if args.info: logger.info('{}: Displaying summary info for archives'.format(repository)) borg_info.display_archives_info( - args.verbosity, repository, storage, local_path=local_path, diff --git a/borgmatic/tests/unit/borg/test_check.py b/borgmatic/tests/unit/borg/test_check.py index b5d83786..bf59aed8 100644 --- a/borgmatic/tests/unit/borg/test_check.py +++ b/borgmatic/tests/unit/borg/test_check.py @@ -1,11 +1,10 @@ from subprocess import STDOUT -import sys +import logging, sys from flexmock import flexmock import pytest from borgmatic.borg import check as module -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS def insert_subprocess_mock(check_call_command, **kwargs): @@ -17,6 +16,12 @@ def insert_subprocess_never(): subprocess = flexmock(module.subprocess) subprocess.should_receive('check_call').never() + +def insert_logging_mock(log_level): + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) + + def test_parse_checks_returns_them_as_tuple(): checks = module._parse_checks({'checks': ['foo', 'disabled', 'bar']}) @@ -125,7 +130,6 @@ def test_check_archives_calls_borg_with_parameters(checks): flexmock(module.os).should_receive('devnull') module.check_archives( - verbosity=None, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -142,7 +146,6 @@ def test_check_archives_with_extract_check_calls_extract_only(): insert_subprocess_never() module.check_archives( - verbosity=None, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -154,13 +157,13 @@ def test_check_archives_with_verbosity_some_calls_borg_with_info_parameter(): consistency_config = {'check_last': None} flexmock(module).should_receive('_parse_checks').and_return(checks) flexmock(module).should_receive('_make_check_flags').and_return(()) + insert_logging_mock(logging.INFO) insert_subprocess_mock( ('borg', 'check', 'repo', '--info'), stdout=None, stderr=STDOUT, ) module.check_archives( - verbosity=VERBOSITY_SOME, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -172,13 +175,13 @@ def test_check_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): consistency_config = {'check_last': None} flexmock(module).should_receive('_parse_checks').and_return(checks) flexmock(module).should_receive('_make_check_flags').and_return(()) + insert_logging_mock(logging.DEBUG) insert_subprocess_mock( ('borg', 'check', 'repo', '--debug'), stdout=None, stderr=STDOUT, ) module.check_archives( - verbosity=VERBOSITY_LOTS, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -191,7 +194,6 @@ def test_check_archives_without_any_checks_bails(): insert_subprocess_never() module.check_archives( - verbosity=None, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -213,7 +215,6 @@ def test_check_archives_with_local_path_calls_borg_via_local_path(): flexmock(module.os).should_receive('devnull') module.check_archives( - verbosity=None, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -236,7 +237,6 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters( flexmock(module.os).should_receive('devnull') module.check_archives( - verbosity=None, repository='repo', storage_config={}, consistency_config=consistency_config, @@ -259,7 +259,6 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters(): flexmock(module.os).should_receive('devnull') module.check_archives( - verbosity=None, repository='repo', storage_config={'lock_wait': 5}, consistency_config=consistency_config, @@ -283,7 +282,6 @@ def test_check_archives_with_retention_prefix(): flexmock(module.os).should_receive('devnull') module.check_archives( - verbosity=None, repository='repo', storage_config={}, consistency_config=consistency_config, diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index 411893c9..27274c57 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -1,9 +1,12 @@ -import os +import logging, os from flexmock import flexmock from borgmatic.borg import create as module -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS + +def insert_logging_mock(log_level): + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) def test_initialize_environment_with_passcommand_should_set_environment(): @@ -216,7 +219,6 @@ def test_create_archive_calls_borg_with_parameters(): insert_subprocess_mock(CREATE_COMMAND) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -237,7 +239,6 @@ def test_create_archive_with_patterns_calls_borg_with_patterns(): insert_subprocess_mock(CREATE_COMMAND + pattern_flags) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -258,7 +259,6 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes(): insert_subprocess_mock(CREATE_COMMAND + exclude_flags) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -276,10 +276,10 @@ def test_create_archive_with_verbosity_some_calls_borg_with_info_parameter(): flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--info', '--stats',)) - + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats',)) + insert_logging_mock(logging.INFO) + module.create_archive( - verbosity=VERBOSITY_SOME, dry_run=False, repository='repo', location_config={ @@ -296,10 +296,10 @@ def test_create_archive_with_verbosity_lots_calls_borg_with_debug_parameter(): flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--stats')) + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats', '--debug')) + insert_logging_mock(logging.DEBUG) module.create_archive( - verbosity=VERBOSITY_LOTS, dry_run=False, repository='repo', location_config={ @@ -320,7 +320,6 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter(): insert_subprocess_mock(CREATE_COMMAND + ('--dry-run',)) module.create_archive( - verbosity=None, dry_run=True, repository='repo', location_config={ @@ -338,10 +337,10 @@ def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--info', '--dry-run')) + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats', '--dry-run')) + insert_logging_mock(logging.INFO) module.create_archive( - verbosity=VERBOSITY_SOME, dry_run=True, repository='repo', location_config={ @@ -359,10 +358,10 @@ def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--dry-run')) - + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats', '--debug', '--dry-run')) + insert_logging_mock(logging.DEBUG) + module.create_archive( - verbosity=VERBOSITY_LOTS, dry_run=True, repository='repo', location_config={ @@ -382,7 +381,6 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters( insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -402,7 +400,6 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_ insert_subprocess_mock(CREATE_COMMAND + ('--remote-ratelimit', '100')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -422,7 +419,6 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',)) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -443,7 +439,6 @@ def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parame insert_subprocess_mock(CREATE_COMMAND) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -464,7 +459,6 @@ def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_paramete insert_subprocess_mock(CREATE_COMMAND + ('--nobsdflags',)) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -485,7 +479,6 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters( insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -506,7 +499,6 @@ def test_create_archive_with_local_path_calls_borg_via_local_path(): insert_subprocess_mock(('borg1',) + CREATE_COMMAND[1:]) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -527,7 +519,6 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters( insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -548,7 +539,6 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters(): insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -568,7 +558,6 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters(): insert_subprocess_mock(CREATE_COMMAND + ('--lock-wait', '5')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -589,7 +578,6 @@ def test_create_archive_with_source_directories_glob_expands(): flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food']) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -610,7 +598,6 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([]) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -630,7 +617,6 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories(): insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -650,7 +636,6 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name(): insert_subprocess_mock(('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ @@ -672,7 +657,6 @@ def test_create_archive_with_archive_name_format_accepts_borg_placeholders(): insert_subprocess_mock(('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar')) module.create_archive( - verbosity=None, dry_run=False, repository='repo', location_config={ diff --git a/borgmatic/tests/unit/borg/test_extract.py b/borgmatic/tests/unit/borg/test_extract.py index 9811a786..6facdabe 100644 --- a/borgmatic/tests/unit/borg/test_extract.py +++ b/borgmatic/tests/unit/borg/test_extract.py @@ -1,4 +1,4 @@ -import sys +import logging, sys from flexmock import flexmock @@ -21,6 +21,11 @@ def insert_subprocess_check_output_mock(check_output_command, result, **kwargs): subprocess.should_receive('check_output').with_args(check_output_command, **kwargs).and_return(result).once() +def insert_logging_mock(log_level): + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) + + def test_extract_last_archive_dry_run_should_call_borg_with_last_archive(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( @@ -32,7 +37,6 @@ def test_extract_last_archive_dry_run_should_call_borg_with_last_archive(): ) module.extract_last_archive_dry_run( - verbosity=None, repository='repo', lock_wait=None, ) @@ -47,7 +51,6 @@ def test_extract_last_archive_dry_run_without_any_archives_should_bail(): insert_subprocess_never() module.extract_last_archive_dry_run( - verbosity=None, repository='repo', lock_wait=None, ) @@ -62,9 +65,9 @@ def test_extract_last_archive_dry_run_with_verbosity_some_should_call_borg_with_ insert_subprocess_mock( ('borg', 'extract', '--dry-run', 'repo::archive2', '--info'), ) + insert_logging_mock(logging.INFO) module.extract_last_archive_dry_run( - verbosity=VERBOSITY_SOME, repository='repo', lock_wait=None, ) @@ -79,9 +82,9 @@ def test_extract_last_archive_dry_run_with_verbosity_lots_should_call_borg_with_ insert_subprocess_mock( ('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--list'), ) + insert_logging_mock(logging.DEBUG) module.extract_last_archive_dry_run( - verbosity=VERBOSITY_LOTS, repository='repo', lock_wait=None, ) @@ -98,7 +101,6 @@ def test_extract_last_archive_dry_run_should_call_borg_via_local_path(): ) module.extract_last_archive_dry_run( - verbosity=None, repository='repo', lock_wait=None, local_path='borg1', @@ -116,7 +118,6 @@ def test_extract_last_archive_dry_run_should_call_borg_with_remote_path_paramete ) module.extract_last_archive_dry_run( - verbosity=None, repository='repo', lock_wait=None, remote_path='borg1', @@ -134,7 +135,6 @@ def test_extract_last_archive_dry_run_should_call_borg_with_lock_wait_parameters ) module.extract_last_archive_dry_run( - verbosity=None, repository='repo', lock_wait=5, ) diff --git a/borgmatic/tests/unit/borg/test_info.py b/borgmatic/tests/unit/borg/test_info.py index 7a1cbbe7..3e9d24af 100644 --- a/borgmatic/tests/unit/borg/test_info.py +++ b/borgmatic/tests/unit/borg/test_info.py @@ -1,15 +1,19 @@ +import logging from collections import OrderedDict from flexmock import flexmock from borgmatic.borg import info as module -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS def insert_subprocess_mock(check_call_command, **kwargs): subprocess = flexmock(module.subprocess) subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once() +def insert_logging_mock(log_level): + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) + INFO_COMMAND = ('borg', 'info', 'repo') @@ -18,7 +22,6 @@ def test_display_archives_info_calls_borg_with_parameters(): insert_subprocess_mock(INFO_COMMAND) module.display_archives_info( - verbosity=None, repository='repo', storage_config={}, ) @@ -26,21 +29,20 @@ def test_display_archives_info_calls_borg_with_parameters(): def test_display_archives_info_with_verbosity_some_calls_borg_with_info_parameter(): insert_subprocess_mock(INFO_COMMAND + ('--info',)) - + insert_logging_mock(logging.INFO) module.display_archives_info( repository='repo', storage_config={}, - verbosity=VERBOSITY_SOME, ) def test_display_archives_info_with_verbosity_lots_calls_borg_with_debug_parameter(): - insert_subprocess_mock(INFO_COMMAND + ('--debug',)) + insert_subprocess_mock(INFO_COMMAND + ('--info', '--debug',)) + insert_logging_mock(logging.DEBUG) module.display_archives_info( repository='repo', storage_config={}, - verbosity=VERBOSITY_LOTS, ) @@ -48,7 +50,6 @@ def test_display_archives_info_with_local_path_calls_borg_via_local_path(): insert_subprocess_mock(('borg1',) + INFO_COMMAND[1:]) module.display_archives_info( - verbosity=None, repository='repo', storage_config={}, local_path='borg1', @@ -59,7 +60,6 @@ def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_para insert_subprocess_mock(INFO_COMMAND + ('--remote-path', 'borg1')) module.display_archives_info( - verbosity=None, repository='repo', storage_config={}, remote_path='borg1', @@ -71,7 +71,6 @@ def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_paramete insert_subprocess_mock(INFO_COMMAND + ('--lock-wait', '5')) module.display_archives_info( - verbosity=None, repository='repo', storage_config=storage_config, ) diff --git a/borgmatic/tests/unit/borg/test_list.py b/borgmatic/tests/unit/borg/test_list.py index 1c6a69f7..15b5143e 100644 --- a/borgmatic/tests/unit/borg/test_list.py +++ b/borgmatic/tests/unit/borg/test_list.py @@ -1,15 +1,20 @@ +import logging from collections import OrderedDict from flexmock import flexmock from borgmatic.borg import list as module -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS def insert_subprocess_mock(check_call_command, **kwargs): subprocess = flexmock(module.subprocess) subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once() +def insert_logging_mock(log_level): + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) + + LIST_COMMAND = ('borg', 'list', 'repo') @@ -18,7 +23,6 @@ def test_list_archives_calls_borg_with_parameters(): insert_subprocess_mock(LIST_COMMAND) module.list_archives( - verbosity=None, repository='repo', storage_config={}, ) @@ -26,21 +30,21 @@ def test_list_archives_calls_borg_with_parameters(): def test_list_archives_with_verbosity_some_calls_borg_with_info_parameter(): insert_subprocess_mock(LIST_COMMAND + ('--info',)) + insert_logging_mock(logging.INFO) module.list_archives( repository='repo', storage_config={}, - verbosity=VERBOSITY_SOME, ) def test_list_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): - insert_subprocess_mock(LIST_COMMAND + ('--debug',)) - + insert_subprocess_mock(LIST_COMMAND + ('--info', '--debug',)) + insert_logging_mock(logging.DEBUG) + module.list_archives( repository='repo', storage_config={}, - verbosity=VERBOSITY_LOTS, ) @@ -48,7 +52,6 @@ def test_list_archives_with_local_path_calls_borg_via_local_path(): insert_subprocess_mock(('borg1',) + LIST_COMMAND[1:]) module.list_archives( - verbosity=None, repository='repo', storage_config={}, local_path='borg1', @@ -59,7 +62,6 @@ def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters() insert_subprocess_mock(LIST_COMMAND + ('--remote-path', 'borg1')) module.list_archives( - verbosity=None, repository='repo', storage_config={}, remote_path='borg1', @@ -71,7 +73,6 @@ def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters(): insert_subprocess_mock(LIST_COMMAND + ('--lock-wait', '5')) module.list_archives( - verbosity=None, repository='repo', storage_config=storage_config, ) diff --git a/borgmatic/tests/unit/borg/test_prune.py b/borgmatic/tests/unit/borg/test_prune.py index 6e3a20df..512facaf 100644 --- a/borgmatic/tests/unit/borg/test_prune.py +++ b/borgmatic/tests/unit/borg/test_prune.py @@ -1,9 +1,9 @@ +import logging from collections import OrderedDict from flexmock import flexmock from borgmatic.borg import prune as module -from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS def insert_subprocess_mock(check_call_command, **kwargs): @@ -11,6 +11,11 @@ def insert_subprocess_mock(check_call_command, **kwargs): subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once() +def insert_logging_mock(log_level): + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) + + BASE_PRUNE_FLAGS = ( ('--keep-daily', '1'), ('--keep-weekly', '2'), @@ -63,7 +68,6 @@ def test_prune_archives_calls_borg_with_parameters(): insert_subprocess_mock(PRUNE_COMMAND) module.prune_archives( - verbosity=None, dry_run=False, repository='repo', storage_config={}, @@ -76,12 +80,12 @@ def test_prune_archives_with_verbosity_some_calls_borg_with_info_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS, ) - insert_subprocess_mock(PRUNE_COMMAND + ('--info', '--stats',)) + insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--info',)) + insert_logging_mock(logging.INFO) module.prune_archives( repository='repo', storage_config={}, - verbosity=VERBOSITY_SOME, dry_run=False, retention_config=retention_config, ) @@ -92,12 +96,12 @@ def test_prune_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS, ) - insert_subprocess_mock(PRUNE_COMMAND + ('--debug', '--stats', '--list')) - + insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--info', '--debug', '--list')) + insert_logging_mock(logging.DEBUG) + module.prune_archives( repository='repo', storage_config={}, - verbosity=VERBOSITY_LOTS, dry_run=False, retention_config=retention_config, ) @@ -113,7 +117,6 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter(): module.prune_archives( repository='repo', storage_config={}, - verbosity=None, dry_run=True, retention_config=retention_config, ) @@ -127,7 +130,6 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path(): insert_subprocess_mock(('borg1',) + PRUNE_COMMAND[1:]) module.prune_archives( - verbosity=None, dry_run=False, repository='repo', storage_config={}, @@ -144,7 +146,6 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters( insert_subprocess_mock(PRUNE_COMMAND + ('--remote-path', 'borg1')) module.prune_archives( - verbosity=None, dry_run=False, repository='repo', storage_config={}, @@ -162,7 +163,6 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters(): insert_subprocess_mock(PRUNE_COMMAND + ('--umask', '077')) module.prune_archives( - verbosity=None, dry_run=False, repository='repo', storage_config=storage_config, @@ -179,7 +179,6 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters(): insert_subprocess_mock(PRUNE_COMMAND + ('--lock-wait', '5')) module.prune_archives( - verbosity=None, dry_run=False, repository='repo', storage_config=storage_config, -- 2.40.1 From 53bd9b13009a7764571de15830db2ee4df1f75ac Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Wed, 18 Jul 2018 23:12:07 +0200 Subject: [PATCH 2/9] Raise default log level to INFO. --- borgmatic/verbosity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/borgmatic/verbosity.py b/borgmatic/verbosity.py index 91264e4a..b52dd816 100644 --- a/borgmatic/verbosity.py +++ b/borgmatic/verbosity.py @@ -12,4 +12,4 @@ def verbosity_to_log_level(verbosity): return { VERBOSITY_SOME: logging.INFO, VERBOSITY_LOTS: logging.DEBUG, - }.get(verbosity, logging.WARNING) + }.get(verbosity, logging.INFO) -- 2.40.1 From 4246be7a3a8a5951f0e2aca89b48826ca6865a31 Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Fri, 3 Aug 2018 15:09:38 +0200 Subject: [PATCH 3/9] Demote parse configuration message to debug. --- borgmatic/commands/borgmatic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index d80c69c4..01c2faa2 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -104,7 +104,7 @@ def run_configuration(config_filename, args): # pragma: no cover Parse a single configuration file, and execute its defined pruning, backups, and/or consistency checks. ''' - logger.info('{}: Parsing configuration file'.format(config_filename)) + logger.debug('{}: Parsing configuration file'.format(config_filename)) config = validate.parse_configuration(config_filename, validate.schema_filename()) (location, storage, retention, consistency, hooks) = ( config.get(section_name, {}) -- 2.40.1 From bc7d123c361bccc4be527c776fcd41cdac55cccb Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Thu, 9 Aug 2018 20:16:59 +0200 Subject: [PATCH 4/9] Assume unknown verbosity == INFO Not WARNING, I think INFO is a much safer choice. And for now, it's equivalent to WARNING, since we use only DEBUG and INFO. --- borgmatic/tests/unit/test_verbosity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/borgmatic/tests/unit/test_verbosity.py b/borgmatic/tests/unit/test_verbosity.py index f62eec27..953faac9 100644 --- a/borgmatic/tests/unit/test_verbosity.py +++ b/borgmatic/tests/unit/test_verbosity.py @@ -8,4 +8,4 @@ def test_verbosity_to_log_level_maps_known_verbosity_to_log_level(): def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level(): - assert module.verbosity_to_log_level('my pants') == logging.WARNING + assert module.verbosity_to_log_level('my pants') == logging.INFO -- 2.40.1 From b35c0476482c7ae185840cc8f41f71e20c2345bc Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Sun, 2 Sep 2018 17:48:04 +0200 Subject: [PATCH 5/9] Address issues raised in review of pull request #90. + Add my name to AUTHORS. Also dared to move one name up, so it's sorted alphabetically. + Do not compile --dry-run with --stats, adapt test accordingly. + Minor cleanups + Print configuration file path at INFO level. + Factor out insert_logging_mock test utility functions + Fix function name for test_verbosity_to_log_level_maps_unknown_verbosity_to_info_level --- AUTHORS | 3 ++- borgmatic/borg/create.py | 3 ++- borgmatic/borg/prune.py | 3 +-- borgmatic/commands/borgmatic.py | 4 ++-- borgmatic/tests/unit/borg/test_check.py | 8 +------- borgmatic/tests/unit/borg/test_create.py | 13 +++++++------ borgmatic/tests/unit/borg/test_extract.py | 6 +----- borgmatic/tests/unit/borg/test_info.py | 5 +---- borgmatic/tests/unit/borg/test_list.py | 6 +----- borgmatic/tests/unit/borg/test_prune.py | 5 +---- borgmatic/tests/unit/test_verbosity.py | 10 +++++++++- 11 files changed, 28 insertions(+), 38 deletions(-) diff --git a/AUTHORS b/AUTHORS index 32b105f5..d66be94f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,11 +1,12 @@ Dan Helfman : Main developer Alexander Görtz: Python 3 compatibility +Florian Lindner: Logging rewrite Henning Schroeder: Copy editing Johannes Feichtner: Support for user hooks Michele Lazzeri: Custom archive names +Nick Whyte: Support prefix filtering for archive consistency checks newtonne: Read encryption password from external file Robin `ypid` Schneider: Support additional options of Borg Scott Squires: Custom archive names Thomas LÉVEIL: Support for a keep_minutely prune option. Support for the --json option -Nick Whyte: Support prefix filtering for archive consistency checks diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 278fa5e5..fa96554c 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -148,7 +148,8 @@ def create_archive( + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + (('--list', '--filter', 'AME', '--info', '--stats') if logger.isEnabledFor(logging.INFO) else ()) + + (('--list', '--filter', 'AME', '--info') if logger.isEnabledFor(logging.INFO) else ()) + + (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) ) diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index 34f21881..a692c802 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -52,8 +52,7 @@ def prune_archives(dry_run, repository, storage_config, retention_config, local_ + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + (('--stats',) if logger.isEnabledFor(logging.INFO) else ()) - + (('--info',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--stats', '--info') if logger.isEnabledFor(logging.INFO) else ()) + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) ) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 5b1ccb8b..051179d9 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -92,7 +92,7 @@ def parse_arguments(*arguments): parser.add_argument( '-v', '--verbosity', type=int, - help='Display verbose progress (1 for INFO, 2 for DEBUG)', + help='Display verbose progress (1 for some, 2 for lots)', ) args = parser.parse_args(arguments) @@ -121,7 +121,7 @@ def run_configuration(config_filename, args): # pragma: no cover Parse a single configuration file, and execute its defined pruning, backups, and/or consistency checks. ''' - logger.debug('{}: Parsing configuration file'.format(config_filename)) + logger.info('{}: Parsing configuration file'.format(config_filename)) config = validate.parse_configuration(config_filename, validate.schema_filename()) (location, storage, retention, consistency, hooks) = ( config.get(section_name, {}) diff --git a/borgmatic/tests/unit/borg/test_check.py b/borgmatic/tests/unit/borg/test_check.py index e0bb01b6..71c1d96c 100644 --- a/borgmatic/tests/unit/borg/test_check.py +++ b/borgmatic/tests/unit/borg/test_check.py @@ -5,7 +5,7 @@ from flexmock import flexmock import pytest from borgmatic.borg import check as module - +from borgmatic.tests.unit.test_verbosity import insert_logging_mock def insert_subprocess_mock(check_call_command, **kwargs): subprocess = flexmock(module.subprocess) @@ -16,12 +16,6 @@ def insert_subprocess_never(): subprocess = flexmock(module.subprocess) subprocess.should_receive('check_call').never() - -def insert_logging_mock(log_level): - logging = flexmock(module.logging.Logger) - logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) - - def test_parse_checks_returns_them_as_tuple(): checks = module._parse_checks({'checks': ['foo', 'disabled', 'bar']}) diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index b16a4c5f..50be6a78 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -3,10 +3,7 @@ import logging, os from flexmock import flexmock from borgmatic.borg import create as module - -def insert_logging_mock(log_level): - logging = flexmock(module.logging.Logger) - logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) +from borgmatic.tests.unit.test_verbosity import insert_logging_mock def test_initialize_environment_with_passcommand_should_set_environment(): @@ -332,12 +329,14 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter(): def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats_parameter(): + """ --dry-run and --stats are mutually exclusive, see: + https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """ flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats', '--dry-run')) + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--dry-run')) insert_logging_mock(logging.INFO) module.create_archive( @@ -353,12 +352,14 @@ def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats_parameter(): + """ --dry-run and --stats are mutually exclusive, see: + https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """ flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats', '--debug', '--show-rc', '--dry-run')) + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--debug', '--show-rc', '--dry-run')) insert_logging_mock(logging.DEBUG) module.create_archive( diff --git a/borgmatic/tests/unit/borg/test_extract.py b/borgmatic/tests/unit/borg/test_extract.py index f23f8483..5cf233dc 100644 --- a/borgmatic/tests/unit/borg/test_extract.py +++ b/borgmatic/tests/unit/borg/test_extract.py @@ -4,6 +4,7 @@ from flexmock import flexmock from borgmatic.borg import extract as module from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS +from borgmatic.tests.unit.test_verbosity import insert_logging_mock def insert_subprocess_mock(check_call_command, **kwargs): @@ -21,11 +22,6 @@ def insert_subprocess_check_output_mock(check_output_command, result, **kwargs): subprocess.should_receive('check_output').with_args(check_output_command, **kwargs).and_return(result).once() -def insert_logging_mock(log_level): - logging = flexmock(module.logging.Logger) - logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) - - def test_extract_last_archive_dry_run_should_call_borg_with_last_archive(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( diff --git a/borgmatic/tests/unit/borg/test_info.py b/borgmatic/tests/unit/borg/test_info.py index 2564b951..88460fea 100644 --- a/borgmatic/tests/unit/borg/test_info.py +++ b/borgmatic/tests/unit/borg/test_info.py @@ -4,16 +4,13 @@ from collections import OrderedDict from flexmock import flexmock from borgmatic.borg import info as module +from borgmatic.tests.unit.test_verbosity import insert_logging_mock def insert_subprocess_mock(check_call_command, **kwargs): subprocess = flexmock(module.subprocess) subprocess.should_receive('check_output').with_args(check_call_command, **kwargs).once() -def insert_logging_mock(log_level): - logging = flexmock(module.logging.Logger) - logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) - INFO_COMMAND = ('borg', 'info', 'repo') diff --git a/borgmatic/tests/unit/borg/test_list.py b/borgmatic/tests/unit/borg/test_list.py index 7a610e44..92cbc4ec 100644 --- a/borgmatic/tests/unit/borg/test_list.py +++ b/borgmatic/tests/unit/borg/test_list.py @@ -4,17 +4,13 @@ from collections import OrderedDict from flexmock import flexmock from borgmatic.borg import list as module +from borgmatic.tests.unit.test_verbosity import insert_logging_mock def insert_subprocess_mock(check_call_command, **kwargs): subprocess = flexmock(module.subprocess) subprocess.should_receive('check_output').with_args(check_call_command, **kwargs).once() -def insert_logging_mock(log_level): - logging = flexmock(module.logging.Logger) - logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) - - LIST_COMMAND = ('borg', 'list', 'repo') diff --git a/borgmatic/tests/unit/borg/test_prune.py b/borgmatic/tests/unit/borg/test_prune.py index 9927bbe7..1bcc83bc 100644 --- a/borgmatic/tests/unit/borg/test_prune.py +++ b/borgmatic/tests/unit/borg/test_prune.py @@ -4,6 +4,7 @@ from collections import OrderedDict from flexmock import flexmock from borgmatic.borg import prune as module +from borgmatic.tests.unit.test_verbosity import insert_logging_mock def insert_subprocess_mock(check_call_command, **kwargs): @@ -11,10 +12,6 @@ def insert_subprocess_mock(check_call_command, **kwargs): subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once() -def insert_logging_mock(log_level): - logging = flexmock(module.logging.Logger) - logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level) - BASE_PRUNE_FLAGS = ( ('--keep-daily', '1'), diff --git a/borgmatic/tests/unit/test_verbosity.py b/borgmatic/tests/unit/test_verbosity.py index 953faac9..e2f252ef 100644 --- a/borgmatic/tests/unit/test_verbosity.py +++ b/borgmatic/tests/unit/test_verbosity.py @@ -1,11 +1,19 @@ import logging +from flexmock import flexmock + from borgmatic import verbosity as module +def insert_logging_mock(log_level): + """ Mocks the isEnabledFor from python logging. """ + logging = flexmock(module.logging.Logger) + logging.should_receive('isEnabledFor').replace_with(lambda lvl : lvl >= log_level) + def test_verbosity_to_log_level_maps_known_verbosity_to_log_level(): assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO + assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG -def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level(): +def test_verbosity_to_log_level_maps_unknown_verbosity_to_info_level(): assert module.verbosity_to_log_level('my pants') == logging.INFO -- 2.40.1 From bfbb3bd72ed6a6b850fae98d39e4d9636718de65 Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Tue, 4 Sep 2018 19:46:59 +0200 Subject: [PATCH 6/9] Use logger.getEffectiveLevel for arguments that should ONLY be at a certain log level. Extend the verbosity mock, s.t. it also mocks getEffectiveLevel Found one more disallowed --debug --stats combination. --- borgmatic/borg/create.py | 3 ++- borgmatic/borg/extract.py | 4 ++-- borgmatic/borg/info.py | 2 +- borgmatic/borg/list.py | 2 +- borgmatic/borg/prune.py | 3 ++- borgmatic/tests/unit/borg/test_create.py | 4 ++-- borgmatic/tests/unit/borg/test_info.py | 2 +- borgmatic/tests/unit/borg/test_list.py | 2 +- borgmatic/tests/unit/borg/test_prune.py | 2 +- borgmatic/tests/unit/test_verbosity.py | 1 + 10 files changed, 14 insertions(+), 11 deletions(-) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index fa96554c..a5e4ea5b 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -148,7 +148,8 @@ def create_archive( + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + (('--list', '--filter', 'AME', '--info') if logger.isEnabledFor(logging.INFO) else ()) + + (('--list', '--filter', 'AME',) if logger.isEnabledFor(logging.INFO) else ()) + + (( '--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) diff --git a/borgmatic/borg/extract.py b/borgmatic/borg/extract.py index 327d3f9a..d9eb62b5 100644 --- a/borgmatic/borg/extract.py +++ b/borgmatic/borg/extract.py @@ -13,12 +13,12 @@ def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', ''' remote_path_flags = ('--remote-path', remote_path) if remote_path else () lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else () + verbosity_flags = () if logger.isEnabledFor(logging.DEBUG): verbosity_flags = ('--debug', '--show-rc') elif logger.isEnabledFor(logging.INFO): verbosity_flags = ('--info',) - else: - verbosity_flags = () + full_list_command = ( local_path, 'list', diff --git a/borgmatic/borg/info.py b/borgmatic/borg/info.py index 5990e1ff..0051e4fc 100644 --- a/borgmatic/borg/info.py +++ b/borgmatic/borg/info.py @@ -16,7 +16,7 @@ def display_archives_info(repository, storage_config, local_path='borg', remote_ (local_path, 'info', repository) + (('--remote-path', remote_path) if remote_path else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + (('--info',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--json',) if json else ()) ) diff --git a/borgmatic/borg/list.py b/borgmatic/borg/list.py index e93d67bd..882fefa6 100644 --- a/borgmatic/borg/list.py +++ b/borgmatic/borg/list.py @@ -16,7 +16,7 @@ def list_archives(repository, storage_config, local_path='borg', remote_path=Non (local_path, 'list', repository) + (('--remote-path', remote_path) if remote_path else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + (('--info',) if logger.isEnabledFor(logging.INFO) else ()) + + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--json',) if json else ()) ) diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index a692c802..ba22dc8f 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -52,7 +52,8 @@ def prune_archives(dry_run, repository, storage_config, retention_config, local_ + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + (('--stats', '--info') if logger.isEnabledFor(logging.INFO) else ()) + + (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ()) + + (( '--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) ) diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index 50be6a78..a2d9038c 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -293,7 +293,7 @@ def test_create_archive_with_verbosity_lots_calls_borg_with_debug_parameter(): flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats', '--debug', '--show-rc')) + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME','--stats', '--debug', '--show-rc')) insert_logging_mock(logging.DEBUG) module.create_archive( @@ -359,7 +359,7 @@ def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) - insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--debug', '--show-rc', '--dry-run')) + insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--debug', '--show-rc', '--dry-run')) insert_logging_mock(logging.DEBUG) module.create_archive( diff --git a/borgmatic/tests/unit/borg/test_info.py b/borgmatic/tests/unit/borg/test_info.py index 88460fea..27ed2ea0 100644 --- a/borgmatic/tests/unit/borg/test_info.py +++ b/borgmatic/tests/unit/borg/test_info.py @@ -34,7 +34,7 @@ def test_display_archives_info_with_verbosity_some_calls_borg_with_info_paramete def test_display_archives_info_with_verbosity_lots_calls_borg_with_debug_parameter(): - insert_subprocess_mock(INFO_COMMAND + ('--info', '--debug', '--show-rc')) + insert_subprocess_mock(INFO_COMMAND + ('--debug', '--show-rc')) insert_logging_mock(logging.DEBUG) module.display_archives_info( diff --git a/borgmatic/tests/unit/borg/test_list.py b/borgmatic/tests/unit/borg/test_list.py index 92cbc4ec..2f1c6bc4 100644 --- a/borgmatic/tests/unit/borg/test_list.py +++ b/borgmatic/tests/unit/borg/test_list.py @@ -35,7 +35,7 @@ def test_list_archives_with_verbosity_some_calls_borg_with_info_parameter(): def test_list_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): - insert_subprocess_mock(LIST_COMMAND + ('--info', '--debug', '--show-rc')) + insert_subprocess_mock(LIST_COMMAND + ('--debug', '--show-rc')) insert_logging_mock(logging.DEBUG) module.list_archives( diff --git a/borgmatic/tests/unit/borg/test_prune.py b/borgmatic/tests/unit/borg/test_prune.py index 1bcc83bc..9d7a7674 100644 --- a/borgmatic/tests/unit/borg/test_prune.py +++ b/borgmatic/tests/unit/borg/test_prune.py @@ -93,7 +93,7 @@ def test_prune_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS, ) - insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--info', '--debug', '--list', '--show-rc')) + insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc')) insert_logging_mock(logging.DEBUG) module.prune_archives( diff --git a/borgmatic/tests/unit/test_verbosity.py b/borgmatic/tests/unit/test_verbosity.py index e2f252ef..733afa61 100644 --- a/borgmatic/tests/unit/test_verbosity.py +++ b/borgmatic/tests/unit/test_verbosity.py @@ -8,6 +8,7 @@ def insert_logging_mock(log_level): """ Mocks the isEnabledFor from python logging. """ logging = flexmock(module.logging.Logger) logging.should_receive('isEnabledFor').replace_with(lambda lvl : lvl >= log_level) + logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level) def test_verbosity_to_log_level_maps_known_verbosity_to_log_level(): -- 2.40.1 From 40ee9338f21e158fd5dacfd88b1b06d87c6e99da Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Fri, 7 Sep 2018 10:27:12 +0200 Subject: [PATCH 7/9] Revert default log level from INFO to WARNING --- borgmatic/tests/unit/test_verbosity.py | 4 ++-- borgmatic/verbosity.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/borgmatic/tests/unit/test_verbosity.py b/borgmatic/tests/unit/test_verbosity.py index 733afa61..99d8fd12 100644 --- a/borgmatic/tests/unit/test_verbosity.py +++ b/borgmatic/tests/unit/test_verbosity.py @@ -16,5 +16,5 @@ def test_verbosity_to_log_level_maps_known_verbosity_to_log_level(): assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG -def test_verbosity_to_log_level_maps_unknown_verbosity_to_info_level(): - assert module.verbosity_to_log_level('my pants') == logging.INFO +def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level(): + assert module.verbosity_to_log_level('my pants') == logging.WARNING diff --git a/borgmatic/verbosity.py b/borgmatic/verbosity.py index b52dd816..91264e4a 100644 --- a/borgmatic/verbosity.py +++ b/borgmatic/verbosity.py @@ -12,4 +12,4 @@ def verbosity_to_log_level(verbosity): return { VERBOSITY_SOME: logging.INFO, VERBOSITY_LOTS: logging.DEBUG, - }.get(verbosity, logging.INFO) + }.get(verbosity, logging.WARNING) -- 2.40.1 From c62a93396e068e827da030281bb03b60c1244181 Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Fri, 7 Sep 2018 10:36:47 +0200 Subject: [PATCH 8/9] Rename test functions: verbosity -> log level Also update doc string here and there. --- borgmatic/borg/check.py | 5 ++--- borgmatic/borg/list.py | 2 +- borgmatic/tests/unit/borg/test_check.py | 4 ++-- borgmatic/tests/unit/borg/test_create.py | 8 ++++---- borgmatic/tests/unit/borg/test_extract.py | 4 ++-- borgmatic/tests/unit/borg/test_info.py | 4 ++-- borgmatic/tests/unit/borg/test_list.py | 4 ++-- borgmatic/tests/unit/borg/test_prune.py | 4 ++-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 9b5b7d36..04d15196 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -75,9 +75,8 @@ def _make_check_flags(checks, check_last=None, prefix=None): def check_archives(repository, storage_config, consistency_config, local_path='borg', remote_path=None): ''' - Given a verbosity flag, a local or remote repository path, a storage config dict, a consistency - config dict, and a local/remote commands to run, check the contained Borg archives for - consistency. + Given a local or remote repository path, a storage config dict, a consistency config dict, + and a local/remote commands to run, check the contained Borg archives for consistency. If there are no consistency checks to run, skip running them. ''' diff --git a/borgmatic/borg/list.py b/borgmatic/borg/list.py index 882fefa6..2c0888e1 100644 --- a/borgmatic/borg/list.py +++ b/borgmatic/borg/list.py @@ -7,7 +7,7 @@ logger = logging.getLogger(__name__) def list_archives(repository, storage_config, local_path='borg', remote_path=None, json=False): ''' - Given a verbosity flag, a local or remote repository path, and a storage config dict, + Given a local or remote repository path, and a storage config dict, list Borg archives in the repository. ''' lock_wait = storage_config.get('lock_wait', None) diff --git a/borgmatic/tests/unit/borg/test_check.py b/borgmatic/tests/unit/borg/test_check.py index 71c1d96c..a49aa4fa 100644 --- a/borgmatic/tests/unit/borg/test_check.py +++ b/borgmatic/tests/unit/borg/test_check.py @@ -146,7 +146,7 @@ def test_check_archives_with_extract_check_calls_extract_only(): ) -def test_check_archives_with_verbosity_some_calls_borg_with_info_parameter(): +def test_check_archives_with_log_info_calls_borg_with_info_parameter(): checks = ('repository',) consistency_config = {'check_last': None} flexmock(module).should_receive('_parse_checks').and_return(checks) @@ -164,7 +164,7 @@ def test_check_archives_with_verbosity_some_calls_borg_with_info_parameter(): ) -def test_check_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): +def test_check_archives_with_log_debug_calls_borg_with_debug_parameter(): checks = ('repository',) consistency_config = {'check_last': None} flexmock(module).should_receive('_parse_checks').and_return(checks) diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index a2d9038c..a7b98ad2 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -267,7 +267,7 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes(): ) -def test_create_archive_with_verbosity_some_calls_borg_with_info_parameter(): +def test_create_archive_with_log_info_calls_borg_with_info_parameter(): flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) @@ -288,7 +288,7 @@ def test_create_archive_with_verbosity_some_calls_borg_with_info_parameter(): ) -def test_create_archive_with_verbosity_lots_calls_borg_with_debug_parameter(): +def test_create_archive_with_log_debug_calls_borg_with_debug_parameter(): flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None) flexmock(module).should_receive('_make_pattern_flags').and_return(()) @@ -328,7 +328,7 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter(): ) -def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats_parameter(): +def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter(): """ --dry-run and --stats are mutually exclusive, see: https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """ flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) @@ -351,7 +351,7 @@ def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats ) -def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats_parameter(): +def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter(): """ --dry-run and --stats are mutually exclusive, see: https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """ flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) diff --git a/borgmatic/tests/unit/borg/test_extract.py b/borgmatic/tests/unit/borg/test_extract.py index 5cf233dc..e609ec95 100644 --- a/borgmatic/tests/unit/borg/test_extract.py +++ b/borgmatic/tests/unit/borg/test_extract.py @@ -52,7 +52,7 @@ def test_extract_last_archive_dry_run_without_any_archives_should_bail(): ) -def test_extract_last_archive_dry_run_with_verbosity_some_should_call_borg_with_info_parameter(): +def test_extract_last_archive_dry_run_with_log_info_should_call_borg_with_info_parameter(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo', '--info'), @@ -69,7 +69,7 @@ def test_extract_last_archive_dry_run_with_verbosity_some_should_call_borg_with_ ) -def test_extract_last_archive_dry_run_with_verbosity_lots_should_call_borg_with_debug_parameter(): +def test_extract_last_archive_dry_run_with_log_debug_should_call_borg_with_debug_parameter(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo', '--debug', '--show-rc'), diff --git a/borgmatic/tests/unit/borg/test_info.py b/borgmatic/tests/unit/borg/test_info.py index 27ed2ea0..36651d79 100644 --- a/borgmatic/tests/unit/borg/test_info.py +++ b/borgmatic/tests/unit/borg/test_info.py @@ -24,7 +24,7 @@ def test_display_archives_info_calls_borg_with_parameters(): ) -def test_display_archives_info_with_verbosity_some_calls_borg_with_info_parameter(): +def test_display_archives_info_with_log_info_calls_borg_with_info_parameter(): insert_subprocess_mock(INFO_COMMAND + ('--info',)) insert_logging_mock(logging.INFO) module.display_archives_info( @@ -33,7 +33,7 @@ def test_display_archives_info_with_verbosity_some_calls_borg_with_info_paramete ) -def test_display_archives_info_with_verbosity_lots_calls_borg_with_debug_parameter(): +def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter(): insert_subprocess_mock(INFO_COMMAND + ('--debug', '--show-rc')) insert_logging_mock(logging.DEBUG) diff --git a/borgmatic/tests/unit/borg/test_list.py b/borgmatic/tests/unit/borg/test_list.py index 2f1c6bc4..f20359fa 100644 --- a/borgmatic/tests/unit/borg/test_list.py +++ b/borgmatic/tests/unit/borg/test_list.py @@ -24,7 +24,7 @@ def test_list_archives_calls_borg_with_parameters(): ) -def test_list_archives_with_verbosity_some_calls_borg_with_info_parameter(): +def test_list_archives_with_log_info_calls_borg_with_info_parameter(): insert_subprocess_mock(LIST_COMMAND + ('--info',)) insert_logging_mock(logging.INFO) @@ -34,7 +34,7 @@ def test_list_archives_with_verbosity_some_calls_borg_with_info_parameter(): ) -def test_list_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): +def test_list_archives_with_log_debug_calls_borg_with_debug_parameter(): insert_subprocess_mock(LIST_COMMAND + ('--debug', '--show-rc')) insert_logging_mock(logging.DEBUG) diff --git a/borgmatic/tests/unit/borg/test_prune.py b/borgmatic/tests/unit/borg/test_prune.py index 9d7a7674..acbb2218 100644 --- a/borgmatic/tests/unit/borg/test_prune.py +++ b/borgmatic/tests/unit/borg/test_prune.py @@ -72,7 +72,7 @@ def test_prune_archives_calls_borg_with_parameters(): ) -def test_prune_archives_with_verbosity_some_calls_borg_with_info_parameter(): +def test_prune_archives_with_log_info_calls_borg_with_info_parameter(): retention_config = flexmock() flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS, @@ -88,7 +88,7 @@ def test_prune_archives_with_verbosity_some_calls_borg_with_info_parameter(): ) -def test_prune_archives_with_verbosity_lots_calls_borg_with_debug_parameter(): +def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter(): retention_config = flexmock() flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS, -- 2.40.1 From a022133c3f331cc7f7adcc549253802198e3bd7a Mon Sep 17 00:00:00 2001 From: Florian Lindner Date: Fri, 7 Sep 2018 10:43:51 +0200 Subject: [PATCH 9/9] Update NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 4b92e4de..0b182113 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ * #88: Fix declared pykwalify compatibility version range in setup.py to prevent use of ancient versions of pykwalify with large version numbers. * #89: Pass --show-rc option to Borg when at highest verbosity level. + * #90: Rewrite of logging system. Now verbosity flags passed to borg are derived from borgmatic's + log level. Note that the output of borgmatic might slightly change. 1.2.2 * #85: Fix compatibility issue between pykwalify and ruamel.yaml 0.15.52, which manifested in -- 2.40.1