Update automated tests (#1122).

This commit is contained in:
Dan Helfman
2025-09-12 12:54:38 -07:00
parent 947dc77a50
commit f60007545b
2 changed files with 52 additions and 51 deletions
+3 -9
View File
@@ -108,11 +108,7 @@ def check_planned_backup_paths(
f'The runtime directory {os.path.normpath(borgmatic_runtime_directory)} overlaps with the configured excludes or patterns with excludes. Please ensure the runtime directory is not excluded.',
)
return tuple(
path
for path in paths
if path not in paths_containing_runtime_directory
)
return tuple(path for path in paths if path not in paths_containing_runtime_directory)
MAX_SPECIAL_FILE_PATHS_LENGTH = 1000
@@ -229,7 +225,7 @@ def make_base_create_command(
)
working_directory = borgmatic.config.paths.get_working_directory(config)
logger.debug('Checking file paths Borg plans to backup')
logger.debug('Checking file paths Borg plans to include')
planned_backup_paths = check_planned_backup_paths(
dry_run,
create_flags + create_positional_arguments,
@@ -247,9 +243,7 @@ def make_base_create_command(
)
special_file_paths = tuple(
path
for path in planned_backup_paths
if special_file(path, working_directory)
path for path in planned_backup_paths if special_file(path, working_directory)
)
if special_file_paths:
+49 -42
View File
@@ -59,7 +59,7 @@ def test_any_parent_directories_treats_unrelated_paths_as_non_match():
module.any_parent_directories('/foo/bar.txt', ('/usr', '/etc'))
def test_collect_special_file_paths_parses_special_files_from_borg_dry_run_file_list():
def test_check_planned_backup_paths_parses_borg_dry_run_file_list():
flexmock(module.flags).should_receive('omit_flag').replace_with(
lambda arguments, flag: arguments,
)
@@ -70,11 +70,10 @@ def test_collect_special_file_paths_parses_special_files_from_borg_dry_run_file_
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
'Processing files ...\n- /foo\n+ /bar\n- /baz',
)
flexmock(module).should_receive('special_file').and_return(True)
flexmock(module.os.path).should_receive('exists').and_return(False)
flexmock(module).should_receive('any_parent_directories').never()
assert module.collect_special_file_paths(
assert module.check_planned_backup_paths(
dry_run=False,
create_command=('borg', 'create'),
config={},
@@ -84,7 +83,7 @@ def test_collect_special_file_paths_parses_special_files_from_borg_dry_run_file_
) == ('/foo', '/bar', '/baz')
def test_collect_special_file_paths_skips_borgmatic_runtime_directory():
def test_check_planned_backup_paths_skips_borgmatic_runtime_directory():
flexmock(module.flags).should_receive('omit_flag').replace_with(
lambda arguments, flag: arguments,
)
@@ -95,7 +94,6 @@ def test_collect_special_file_paths_skips_borgmatic_runtime_directory():
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
'+ /foo\n- /run/borgmatic/bar\n- /baz',
)
flexmock(module).should_receive('special_file').and_return(True)
flexmock(module.os.path).should_receive('exists').and_return(True)
flexmock(module).should_receive('any_parent_directories').with_args(
'/foo',
@@ -110,7 +108,7 @@ def test_collect_special_file_paths_skips_borgmatic_runtime_directory():
('/run/borgmatic',),
).and_return(False)
assert module.collect_special_file_paths(
assert module.check_planned_backup_paths(
dry_run=False,
create_command=('borg', 'create'),
config={},
@@ -120,7 +118,7 @@ def test_collect_special_file_paths_skips_borgmatic_runtime_directory():
) == ('/foo', '/baz')
def test_collect_special_file_paths_with_borgmatic_runtime_directory_missing_from_paths_output_errors():
def test_check_planned_backup_paths_with_borgmatic_runtime_directory_missing_from_paths_output_errors():
flexmock(module.flags).should_receive('omit_flag').replace_with(
lambda arguments, flag: arguments,
)
@@ -131,12 +129,11 @@ def test_collect_special_file_paths_with_borgmatic_runtime_directory_missing_fro
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
'+ /foo\n- /bar\n- /baz',
)
flexmock(module).should_receive('special_file').and_return(True)
flexmock(module.os.path).should_receive('exists').and_return(True)
flexmock(module).should_receive('any_parent_directories').and_return(False)
with pytest.raises(ValueError):
module.collect_special_file_paths(
module.check_planned_backup_paths(
dry_run=False,
create_command=('borg', 'create'),
config={},
@@ -146,7 +143,7 @@ def test_collect_special_file_paths_with_borgmatic_runtime_directory_missing_fro
)
def test_collect_special_file_paths_with_dry_run_and_borgmatic_runtime_directory_missing_from_paths_output_does_not_raise():
def test_check_planned_backup_paths_with_dry_run_and_borgmatic_runtime_directory_missing_from_paths_output_does_not_raise():
flexmock(module.flags).should_receive('omit_flag').replace_with(
lambda arguments, flag: arguments,
)
@@ -157,11 +154,10 @@ def test_collect_special_file_paths_with_dry_run_and_borgmatic_runtime_directory
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
'+ /foo\n- /bar\n- /baz',
)
flexmock(module).should_receive('special_file').and_return(True)
flexmock(module.os.path).should_receive('exists').and_return(True)
flexmock(module).should_receive('any_parent_directories').and_return(False)
assert module.collect_special_file_paths(
assert module.check_planned_backup_paths(
dry_run=True,
create_command=('borg', 'create'),
config={},
@@ -171,33 +167,6 @@ def test_collect_special_file_paths_with_dry_run_and_borgmatic_runtime_directory
) == ('/foo', '/bar', '/baz')
def test_collect_special_file_paths_excludes_non_special_files():
flexmock(module.flags).should_receive('omit_flag').replace_with(
lambda arguments, flag: arguments,
)
flexmock(module.flags).should_receive('omit_flag_and_value').replace_with(
lambda arguments, flag: arguments,
)
flexmock(module.environment).should_receive('make_environment').and_return(None)
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
'+ /foo\n+ /bar\n+ /baz',
)
flexmock(module).should_receive('special_file').and_return(True).and_return(False).and_return(
True,
)
flexmock(module.os.path).should_receive('exists').and_return(False)
flexmock(module).should_receive('any_parent_directories').never()
assert module.collect_special_file_paths(
dry_run=False,
create_command=('borg', 'create'),
config={},
local_path=None,
working_directory=None,
borgmatic_runtime_directory='/run/borgmatic',
) == ('/foo', '/baz')
DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
REPO_ARCHIVE = (f'repo::{DEFAULT_ARCHIVE_NAME}',)
@@ -211,6 +180,7 @@ def test_make_base_create_produces_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -246,6 +216,7 @@ def test_make_base_create_command_includes_patterns_file_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -278,6 +249,7 @@ def test_make_base_create_command_with_store_config_false_omits_config_files():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -346,6 +318,7 @@ def test_make_base_create_command_includes_configuration_option_as_command_flag(
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -378,6 +351,7 @@ def test_make_base_create_command_includes_dry_run_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=True,
@@ -410,6 +384,7 @@ def test_make_base_create_command_includes_comment_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -443,6 +418,7 @@ def test_make_base_create_command_includes_local_path_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -475,6 +451,7 @@ def test_make_base_create_command_includes_remote_path_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -507,6 +484,7 @@ def test_make_base_create_command_includes_log_json_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -539,6 +517,7 @@ def test_make_base_create_command_includes_list_flags_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -578,7 +557,18 @@ def test_make_base_create_command_with_stream_processes_ignores_read_special_fal
)
flexmock(module.logger).should_receive('warning').twice()
flexmock(module.environment).should_receive('make_environment')
flexmock(module).should_receive('collect_special_file_paths').and_return(('/dev/null',)).once()
flexmock(module).should_receive('check_planned_backup_paths').and_return(
(
'/non/special',
'/dev/null',
)
)
flexmock(module).should_receive('special_file').with_args(
'/non/special', working_directory=None
).and_return(False)
flexmock(module).should_receive('special_file').with_args(
'/dev/null', working_directory=None
).and_return(True)
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').with_args(
(
Pattern(
@@ -630,7 +620,18 @@ def test_make_base_create_command_without_patterns_and_with_stream_processes_ign
)
flexmock(module.logger).should_receive('warning').twice()
flexmock(module.environment).should_receive('make_environment')
flexmock(module).should_receive('collect_special_file_paths').and_return(('/dev/null',)).once()
flexmock(module).should_receive('check_planned_backup_paths').and_return(
(
'/non/special',
'/dev/null',
)
)
flexmock(module).should_receive('special_file').with_args(
'/non/special', working_directory=None
).and_return(False)
flexmock(module).should_receive('special_file').with_args(
'/dev/null', working_directory=None
).and_return(True)
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').with_args(
(
Pattern(
@@ -678,7 +679,7 @@ def test_make_base_create_command_with_stream_processes_and_read_special_true_sk
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module.logger).should_receive('warning').never()
flexmock(module).should_receive('collect_special_file_paths').never()
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -712,6 +713,7 @@ def test_make_base_create_command_includes_archive_name_format_in_borg_command()
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::ARCHIVE_NAME',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -744,6 +746,7 @@ def test_make_base_create_command_includes_default_archive_name_format_in_borg_c
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::{hostname}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -775,6 +778,7 @@ def test_make_base_create_command_includes_archive_name_format_with_placeholders
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(repository_archive_pattern,),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -807,6 +811,7 @@ def test_make_base_create_command_includes_repository_and_archive_name_format_wi
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(repository_archive_pattern,),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -835,6 +840,7 @@ def test_make_base_create_command_includes_archive_suffix_in_borg_command():
DEFAULT_ARCHIVE_NAME,
)
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
@@ -867,6 +873,7 @@ def test_make_base_create_command_includes_extra_borg_options_in_borg_command():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('check_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,