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
This commit is contained in:
Florian Lindner 2018-09-02 17:48:04 +02:00
parent 9628e385a6
commit b35c047648
11 changed files with 28 additions and 38 deletions

View File

@ -1,11 +1,12 @@
Dan Helfman <witten@torsion.org>: 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

View File

@ -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 ())
)

View File

@ -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 ())
)

View File

@ -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, {})

View File

@ -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']})

View File

@ -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(

View File

@ -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(

View File

@ -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')

View File

@ -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')

View File

@ -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'),

View File

@ -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