From 4f728b1cd49fa7b0118c08f7bd3903504e76a6e3 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 8 May 2026 22:16:41 -0700 Subject: [PATCH] Get rest of tests passing (#1267). --- borgmatic/actions/check.py | 9 ++++-- borgmatic/actions/config/bootstrap.py | 5 ++- borgmatic/actions/create.py | 4 ++- borgmatic/actions/restore.py | 4 ++- borgmatic/config/paths.py | 5 +-- tests/unit/actions/config/test_bootstrap.py | 2 ++ tests/unit/actions/test_check.py | 20 +++--------- tests/unit/actions/test_create.py | 14 ++++----- tests/unit/actions/test_restore.py | 10 +++--- tests/unit/commands/test_borgmatic.py | 35 +++++++++++++++++++-- tests/unit/config/test_paths.py | 30 ++++++++++++++---- 11 files changed, 94 insertions(+), 44 deletions(-) diff --git a/borgmatic/actions/check.py b/borgmatic/actions/check.py index 33b58cc7..8a669da4 100644 --- a/borgmatic/actions/check.py +++ b/borgmatic/actions/check.py @@ -20,7 +20,6 @@ import borgmatic.borg.environment import borgmatic.borg.extract import borgmatic.borg.list import borgmatic.borg.pattern -import borgmatic.borg.repo_info import borgmatic.borg.repo_list import borgmatic.config.paths import borgmatic.execute @@ -820,7 +819,9 @@ def run_check( remote_path=remote_path, ) for check in borg_specific_checks: - write_check_time(make_check_time_path(config, repository['id'], check, archives_check_id)) + write_check_time( + make_check_time_path(config, repository['id'], check, archives_check_id) + ) if 'extract' in checks: logger.info('Running extract check') @@ -837,7 +838,9 @@ def run_check( if 'spot' in checks: logger.info('Running spot check') - with borgmatic.config.paths.Runtime_directory(config, repository['id']) as borgmatic_runtime_directory: + with borgmatic.config.paths.Runtime_directory( + config, repository['id'] + ) as borgmatic_runtime_directory: spot_check( repository, config, diff --git a/borgmatic/actions/config/bootstrap.py b/borgmatic/actions/config/bootstrap.py index b00d96c3..6f572594 100644 --- a/borgmatic/actions/config/bootstrap.py +++ b/borgmatic/actions/config/bootstrap.py @@ -3,6 +3,7 @@ import logging import os import borgmatic.borg.extract +import borgmatic.borg.repo_info import borgmatic.borg.repo_list import borgmatic.config.paths @@ -118,7 +119,9 @@ def run_bootstrap(bootstrap_arguments, global_arguments, local_borg_version): remote_path=bootstrap_arguments.remote_path, ) - with borgmatic.config.paths.Runtime_directory(config, repository_id) as borgmatic_runtime_directory: + with borgmatic.config.paths.Runtime_directory( + config, repository_id + ) as borgmatic_runtime_directory: manifest_config_paths = load_config_paths_from_archive( bootstrap_arguments.repository, archive_name, diff --git a/borgmatic/actions/create.py b/borgmatic/actions/create.py index 5a3453e8..2c85803e 100644 --- a/borgmatic/actions/create.py +++ b/borgmatic/actions/create.py @@ -43,7 +43,9 @@ def run_create( logger.info(f'Creating archive{dry_run_label}') working_directory = borgmatic.config.paths.get_working_directory(config) - with borgmatic.config.paths.Runtime_directory(config, repository['id']) as borgmatic_runtime_directory: + with borgmatic.config.paths.Runtime_directory( + config, repository['id'] + ) as borgmatic_runtime_directory: patterns = pattern.process_patterns( pattern.collect_patterns(config, working_directory), config, diff --git a/borgmatic/actions/restore.py b/borgmatic/actions/restore.py index c31669e0..814388c6 100644 --- a/borgmatic/actions/restore.py +++ b/borgmatic/actions/restore.py @@ -537,7 +537,9 @@ def run_restore( logger.info(f'Restoring data sources from archive {restore_arguments.archive}') working_directory = borgmatic.config.paths.get_working_directory(config) - with borgmatic.config.paths.Runtime_directory(config, repository['id']) as borgmatic_runtime_directory: + with borgmatic.config.paths.Runtime_directory( + config, repository['id'] + ) as borgmatic_runtime_directory: patterns = borgmatic.actions.pattern.process_patterns( borgmatic.actions.pattern.collect_patterns(config, working_directory), config, diff --git a/borgmatic/config/paths.py b/borgmatic/config/paths.py index 0ba5368f..1d7db174 100644 --- a/borgmatic/config/paths.py +++ b/borgmatic/config/paths.py @@ -1,8 +1,8 @@ import contextlib import logging import os -import tempfile import shutil +import tempfile from enum import Enum logger = logging.getLogger(__name__) @@ -90,6 +90,7 @@ class Fixed_name_temporary_directory: A class whose instances can stand-in for tempfile.TemporaryDirectory's, except the temporary filename path is fixed rather than randomly generated. ''' + def __init__(self, path): ''' Given a temporary directory path, save it off for later. @@ -100,7 +101,7 @@ class Fixed_name_temporary_directory: ''' Remove the temporary directory path. ''' - shutil.rmtree(self.name) + shutil.rmtree(self.name, ignore_errors=True) class Runtime_directory: diff --git a/tests/unit/actions/config/test_bootstrap.py b/tests/unit/actions/config/test_bootstrap.py index 6aa967a9..87eedc2e 100644 --- a/tests/unit/actions/config/test_bootstrap.py +++ b/tests/unit/actions/config/test_bootstrap.py @@ -171,6 +171,7 @@ def test_run_bootstrap_does_not_raise(): flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return( 'archive', ) + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('Runtime_directory').and_return( flexmock(), ) @@ -222,6 +223,7 @@ def test_run_bootstrap_translates_ssh_command_argument_to_config(): local_path='borg7', remote_path='borg8', ).and_return('archive') + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('Runtime_directory').and_return( flexmock(), ) diff --git a/tests/unit/actions/test_check.py b/tests/unit/actions/test_check.py index b4a07504..4b95516c 100644 --- a/tests/unit/actions/test_check.py +++ b/tests/unit/actions/test_check.py @@ -1838,9 +1838,6 @@ def test_spot_check_without_any_source_paths_errors(): def test_run_check_checks_archives_for_configured_repository(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return( - flexmock() - ) flexmock(module).should_receive('upgrade_check_times') flexmock(module).should_receive('parse_checks') flexmock(module.borgmatic.borg.check).should_receive('make_archive_filter_flags').and_return(()) @@ -1863,7 +1860,7 @@ def test_run_check_checks_archives_for_configured_repository(): module.run_check( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'repositories': ['repo']}, local_borg_version=None, check_arguments=check_arguments, @@ -1875,9 +1872,6 @@ def test_run_check_checks_archives_for_configured_repository(): def test_run_check_runs_configured_extract_check(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return( - flexmock() - ) flexmock(module).should_receive('upgrade_check_times') flexmock(module).should_receive('parse_checks') flexmock(module.borgmatic.borg.check).should_receive('make_archive_filter_flags').and_return(()) @@ -1898,7 +1892,7 @@ def test_run_check_runs_configured_extract_check(): module.run_check( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'repositories': ['repo']}, local_borg_version=None, check_arguments=check_arguments, @@ -1910,9 +1904,6 @@ def test_run_check_runs_configured_extract_check(): def test_run_check_runs_configured_spot_check(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return( - flexmock() - ) flexmock(module).should_receive('upgrade_check_times') flexmock(module).should_receive('parse_checks') flexmock(module.borgmatic.borg.check).should_receive('make_archive_filter_flags').and_return(()) @@ -1936,7 +1927,7 @@ def test_run_check_runs_configured_spot_check(): module.run_check( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'repositories': ['repo']}, local_borg_version=None, check_arguments=check_arguments, @@ -1948,9 +1939,6 @@ def test_run_check_runs_configured_spot_check(): def test_run_check_without_checks_runs_nothing_except_hooks(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return( - flexmock() - ) flexmock(module).should_receive('upgrade_check_times') flexmock(module).should_receive('parse_checks') flexmock(module.borgmatic.borg.check).should_receive('make_archive_filter_flags').and_return(()) @@ -1971,7 +1959,7 @@ def test_run_check_without_checks_runs_nothing_except_hooks(): module.run_check( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'repositories': ['repo']}, local_borg_version=None, check_arguments=check_arguments, diff --git a/tests/unit/actions/test_create.py b/tests/unit/actions/test_create.py index 98752daf..983f179f 100644 --- a/tests/unit/actions/test_create.py +++ b/tests/unit/actions/test_create.py @@ -34,7 +34,7 @@ def test_run_create_executes_and_calls_hooks_for_configured_repository(): list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={}, config_paths=['/tmp/test.yaml'], local_borg_version=None, @@ -65,7 +65,7 @@ def test_run_create_with_both_list_and_json_errors(): list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'list_details': True}, config_paths=['/tmp/test.yaml'], local_borg_version=None, @@ -96,7 +96,7 @@ def test_run_create_with_both_list_and_progress_errors(): list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'list_details': True, 'progress': True}, config_paths=['/tmp/test.yaml'], local_borg_version=None, @@ -138,7 +138,7 @@ def test_run_create_produces_json(): assert list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={}, config_paths=['/tmp/test.yaml'], local_borg_version=None, @@ -194,7 +194,7 @@ def test_run_create_with_active_dumps_roundtrips_via_checkpoint_archive(): list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={}, config_paths=['/tmp/test.yaml'], local_borg_version=None, @@ -277,7 +277,7 @@ def test_run_create_with_active_dumps_json_updates_archive_info(): assert list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={}, config_paths=['/tmp/test.yaml'], local_borg_version=None, @@ -360,7 +360,7 @@ def test_run_create_with_active_dumps_removes_data_source_dumps_with_original_pa list( module.run_create( config_filename='test.yaml', - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={}, config_paths=['/tmp/test.yaml'], local_borg_version=None, diff --git a/tests/unit/actions/test_restore.py b/tests/unit/actions/test_restore.py index b413a48c..40b62158 100644 --- a/tests/unit/actions/test_restore.py +++ b/tests/unit/actions/test_restore.py @@ -1222,7 +1222,7 @@ def test_run_restore_restores_each_data_source(): flexmock(module).should_receive('ensure_requested_dumps_restored') module.run_restore( - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config=flexmock(), local_borg_version=flexmock(), restore_arguments=flexmock( @@ -1283,7 +1283,7 @@ def test_run_restore_restores_data_source_by_falling_back_to_all_name(): flexmock(module).should_receive('ensure_requested_dumps_restored') module.run_restore( - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config=flexmock(), local_borg_version=flexmock(), restore_arguments=flexmock( @@ -1367,7 +1367,7 @@ def test_run_restore_restores_data_source_configured_with_all_name(): flexmock(module).should_receive('ensure_requested_dumps_restored') module.run_restore( - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config=flexmock(), local_borg_version=flexmock(), restore_arguments=flexmock( @@ -1451,7 +1451,7 @@ def test_run_restore_skips_missing_data_source(): flexmock(module).should_receive('ensure_requested_dumps_restored') module.run_restore( - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config=flexmock(), local_borg_version=flexmock(), restore_arguments=flexmock( @@ -1531,7 +1531,7 @@ def test_run_restore_restores_data_sources_from_different_hooks(): flexmock(module).should_receive('ensure_requested_dumps_restored') module.run_restore( - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config=flexmock(), local_borg_version=flexmock(), restore_arguments=flexmock( diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 73ae1a09..bda2f4ae 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -940,6 +940,7 @@ def test_run_actions_runs_repo_create(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -967,6 +968,7 @@ def test_run_actions_with_matching_repository_flag_runs_repo_create(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True) + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -996,6 +998,7 @@ def test_run_actions_with_non_matching_repository_flag_bails(): flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return( False ) + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').never() flexmock(module.command).should_receive('Before_after_hooks').never() flexmock(borgmatic.actions.repo_create).should_receive('run_repo_create').never() @@ -1021,6 +1024,7 @@ def test_run_actions_adds_label_file_to_hook_context(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1028,7 +1032,7 @@ def test_run_actions_adds_label_file_to_hook_context(): expected = flexmock() flexmock(borgmatic.actions.create).should_receive('run_create').with_args( config_filename=object, - repository={'path': 'repo', 'label': 'my repo'}, + repository={'path': 'repo', 'id': 'repo', 'label': 'my repo'}, config={'repositories': []}, config_paths=[], local_borg_version=object, @@ -1058,6 +1062,7 @@ def test_run_actions_adds_log_file_to_hook_context(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1065,7 +1070,7 @@ def test_run_actions_adds_log_file_to_hook_context(): expected = flexmock() flexmock(borgmatic.actions.create).should_receive('run_create').with_args( config_filename=object, - repository={'path': 'repo'}, + repository={'path': 'repo', 'id': 'repo'}, config={'repositories': [], 'log_file': 'foo'}, config_paths=[], local_borg_version=object, @@ -1095,6 +1100,7 @@ def test_run_actions_runs_transfer(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1119,6 +1125,7 @@ def test_run_actions_runs_create(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1145,6 +1152,7 @@ def test_run_actions_with_skip_actions_does_not_run_action_or_action_command_hoo flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return(['create']) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1182,6 +1190,7 @@ def test_run_actions_runs_recreate(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1207,6 +1216,7 @@ def test_run_actions_runs_prune(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1231,6 +1241,7 @@ def test_run_actions_runs_compact(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1255,6 +1266,7 @@ def test_run_actions_runs_check_when_repository_enabled_for_checks(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1280,6 +1292,7 @@ def test_run_actions_skips_check_when_repository_not_enabled_for_checks(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1305,6 +1318,7 @@ def test_run_actions_runs_extract(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1329,6 +1343,7 @@ def test_run_actions_runs_export_tar(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1353,6 +1368,7 @@ def test_run_actions_runs_mount(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1377,6 +1393,7 @@ def test_run_actions_runs_restore(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1401,6 +1418,7 @@ def test_run_actions_runs_repo_list(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1427,6 +1445,7 @@ def test_run_actions_runs_list(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1453,6 +1472,7 @@ def test_run_actions_runs_repo_info(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1479,6 +1499,7 @@ def test_run_actions_runs_info(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1505,6 +1526,7 @@ def test_run_actions_runs_break_lock(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1529,6 +1551,7 @@ def test_run_actions_runs_export_key(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1553,6 +1576,7 @@ def test_run_actions_runs_import_key(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1577,6 +1601,7 @@ def test_run_actions_runs_change_passphrase(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1604,6 +1629,7 @@ def test_run_actions_runs_delete(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1628,6 +1654,7 @@ def test_run_actions_runs_repo_delete(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1655,6 +1682,7 @@ def test_run_actions_runs_borg(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1679,6 +1707,7 @@ def test_run_actions_runs_multiple_actions_in_argument_order(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -1708,6 +1737,7 @@ def test_run_actions_runs_action_hooks_for_one_action_at_a_time(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) @@ -2712,6 +2742,7 @@ def test_run_actions_runs_diff(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.repo_info).should_receive('get_repository_id').and_return('repo') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( flexmock(), ) diff --git a/tests/unit/config/test_paths.py b/tests/unit/config/test_paths.py index 06e9b4c7..1d19d670 100644 --- a/tests/unit/config/test_paths.py +++ b/tests/unit/config/test_paths.py @@ -62,8 +62,16 @@ def test_replace_temporary_subdirectory_with_glob_uses_custom_temporary_director ) +def test_fixed_name_temporary_directory_cleanup_does_not_raise(): + flexmock(module.shutil).should_receive('rmtree') + + module.Fixed_name_temporary_directory('/path').cleanup() + + def test_runtime_directory_uses_config_option(): - flexmock(module).should_receive('Fixed_name_temporary_directory').and_return(flexmock(cleanup=lambda: None)) + flexmock(module).should_receive('Fixed_name_temporary_directory').and_return( + flexmock(cleanup=lambda: None) + ) flexmock(module).should_receive('expand_user_in_path').replace_with(lambda path: path) flexmock(module.os).should_receive('makedirs') config = {'user_runtime_directory': '/run', 'borgmatic_source_directory': '/nope'} @@ -81,7 +89,9 @@ def test_runtime_directory_with_relative_config_option_errors(): def test_runtime_directory_falls_back_to_xdg_runtime_dir(monkeypatch): - flexmock(module).should_receive('Fixed_name_temporary_directory').and_return(flexmock(cleanup=lambda: None)) + flexmock(module).should_receive('Fixed_name_temporary_directory').and_return( + flexmock(cleanup=lambda: None) + ) flexmock(module).should_receive('expand_user_in_path').replace_with(lambda path: path) monkeypatch.setenv('XDG_RUNTIME_DIR', '/run') flexmock(module.os).should_receive('makedirs') @@ -99,7 +109,9 @@ def test_runtime_directory_with_relative_xdg_runtime_dir_errors(monkeypatch): def test_runtime_directory_falls_back_to_runtime_directory(monkeypatch): - flexmock(module).should_receive('Fixed_name_temporary_directory').and_return(flexmock(cleanup=lambda: None)) + flexmock(module).should_receive('Fixed_name_temporary_directory').and_return( + flexmock(cleanup=lambda: None) + ) flexmock(module).should_receive('expand_user_in_path').replace_with(lambda path: path) monkeypatch.delenv('XDG_RUNTIME_DIR', raising=False) flexmock(module).should_receive('resolve_systemd_directory').with_args( @@ -126,7 +138,9 @@ def test_runtime_directory_with_relative_runtime_directory_errors(monkeypatch): pass -def test_runtime_directory_falls_back_to_tmpdir_and_adds_temporary_subdirectory_that_get_cleaned_up(monkeypatch): +def test_runtime_directory_falls_back_to_tmpdir_and_adds_temporary_subdirectory_that_get_cleaned_up( + monkeypatch, +): flexmock(module).should_receive('expand_user_in_path').replace_with(lambda path: path) monkeypatch.delenv('XDG_RUNTIME_DIR', raising=False) flexmock(module).should_receive('resolve_systemd_directory').with_args( @@ -162,7 +176,9 @@ def test_runtime_directory_with_relative_tmpdir_errors(monkeypatch): pass -def test_runtime_directory_falls_back_to_temp_and_adds_temporary_subdirectory_that_get_cleaned_up(monkeypatch): +def test_runtime_directory_falls_back_to_temp_and_adds_temporary_subdirectory_that_get_cleaned_up( + monkeypatch, +): flexmock(module).should_receive('expand_user_in_path').replace_with(lambda path: path) monkeypatch.delenv('XDG_RUNTIME_DIR', raising=False) flexmock(module).should_receive('resolve_systemd_directory').with_args( @@ -200,7 +216,9 @@ def test_runtime_directory_with_relative_temp_errors(monkeypatch): pass -def test_runtime_directory_falls_back_to_hard_coded_tmp_path_and_adds_temporary_subdirectory_that_get_cleaned_up(monkeypatch): +def test_runtime_directory_falls_back_to_hard_coded_tmp_path_and_adds_temporary_subdirectory_that_get_cleaned_up( + monkeypatch, +): flexmock(module).should_receive('expand_user_in_path').replace_with(lambda path: path) monkeypatch.delenv('XDG_RUNTIME_DIR', raising=False) flexmock(module).should_receive('resolve_systemd_directory').with_args(