From 42c006cf1d2748d7e51d9dad595befdb430e8fe8 Mon Sep 17 00:00:00 2001 From: lingfish Date: Mon, 23 Feb 2026 11:03:25 +1100 Subject: [PATCH] Next raft of suggested fixes. --- borgmatic/actions/diff.py | 15 +++--- tests/unit/actions/test_diff.py | 51 ++++++++++++++++---- tests/unit/borg/test_diff.py | 27 ++++------- tests/unit/commands/test_borgmatic_diff.py | 3 -- tests/unit/commands/test_run_actions_diff.py | 2 - 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/borgmatic/actions/diff.py b/borgmatic/actions/diff.py index 119d7bd7..a40c4a5a 100644 --- a/borgmatic/actions/diff.py +++ b/borgmatic/actions/diff.py @@ -19,12 +19,15 @@ def run_diff( Run the "diff" action for the given repository. ''' - # Collect and process patterns. - processed_patterns = borgmatic.actions.pattern.process_patterns( - (*borgmatic.actions.pattern.collect_patterns(config),), - config, - borgmatic.config.paths.get_working_directory(config), - ) + # Only process patterns if only_patterns flag is set + if diff_arguments.only_patterns: + processed_patterns = borgmatic.actions.pattern.process_patterns( + (*borgmatic.actions.pattern.collect_patterns(config),), + config, + borgmatic.config.paths.get_working_directory(config), + ) + else: + processed_patterns = None archive = borgmatic.borg.repo_list.resolve_archive_name( repository['path'], diff --git a/tests/unit/actions/test_diff.py b/tests/unit/actions/test_diff.py index da6bf0b7..ab1bf71e 100644 --- a/tests/unit/actions/test_diff.py +++ b/tests/unit/actions/test_diff.py @@ -1,24 +1,24 @@ from flexmock import flexmock -import borgmatic.actions.diff -import borgmatic.actions.pattern -import borgmatic.borg.diff -import borgmatic.borg.repo_list +from borgmatic.actions import diff as module def test_run_diff_calls_borg_diff(): - flexmock(borgmatic.actions.pattern).should_receive('process_patterns').and_return([]) - flexmock(borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return('archive') - flexmock(borgmatic.borg.diff).should_receive('diff').once() + flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return( + 'archive' + ) + flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( + flexmock(), + ) + flexmock(module.borgmatic.borg.diff).should_receive('diff').once() - borgmatic.actions.diff.run_diff( + module.borgmatic.actions.diff.run_diff( repository={'path': 'repo'}, config={}, local_borg_version=None, diff_arguments=flexmock( archive='archive', same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -28,3 +28,36 @@ def test_run_diff_calls_borg_diff(): local_path=None, remote_path=None, ) + + +def test_run_diff_with_only_patterns(): + flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return( + flexmock(), + ) + flexmock(module.borgmatic.actions.pattern).should_receive('collect_patterns').once().and_return( + [] + ) + flexmock(module.borgmatic.actions.pattern).should_receive('process_patterns').once().and_return( + [] + ) + flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return( + 'archive' + ) + flexmock(module.borgmatic.borg.diff).should_receive('diff').once() + + module.borgmatic.actions.diff.run_diff( + repository={'path': 'repo'}, + config={}, + local_borg_version=None, + diff_arguments=flexmock( + archive='archive', + same_chunker_params=False, + sort_keys=[], + content_only=False, + second_archive=None, + only_patterns=True, + ), + global_arguments=flexmock(), + local_path=None, + remote_path=None, + ) diff --git a/tests/unit/borg/test_diff.py b/tests/unit/borg/test_diff.py index 3488f913..92c908ef 100644 --- a/tests/unit/borg/test_diff.py +++ b/tests/unit/borg/test_diff.py @@ -3,15 +3,11 @@ from flexmock import flexmock import borgmatic.borg.diff import borgmatic.borg.environment import borgmatic.borg.feature -import borgmatic.config.paths import borgmatic.execute from borgmatic.borg import flags def test_diff_calls_execute_command(): - flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) - flexmock(borgmatic.config.paths).should_receive('get_working_directory').and_return(None) - flexmock(borgmatic.execute).should_receive('execute_command').once() flexmock(borgmatic.borg.feature).should_receive('available').and_return(False) flexmock(flags).should_receive('make_repository_flags').and_return(()) flexmock(flags).should_receive('make_match_archives_flags').and_return(()) @@ -19,6 +15,8 @@ def test_diff_calls_execute_command(): flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( flexmock(name='test') ) + flexmock(borgmatic.execute).should_receive('execute_command').once() + flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) borgmatic.borg.diff.diff( repository='repo', @@ -27,7 +25,6 @@ def test_diff_calls_execute_command(): local_borg_version=None, diff_arguments=flexmock( same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -41,9 +38,6 @@ def test_diff_calls_execute_command(): def test_diff_with_numeric_ids_flag(): - flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) - flexmock(borgmatic.config.paths).should_receive('get_working_directory').and_return(None) - flexmock(borgmatic.execute).should_receive('execute_command').once() flexmock(borgmatic.borg.feature).should_receive('available').and_return(True) flexmock(flags).should_receive('make_repository_flags').and_return(()) flexmock(flags).should_receive('make_match_archives_flags').and_return(()) @@ -51,6 +45,8 @@ def test_diff_with_numeric_ids_flag(): flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( flexmock(name='test') ) + flexmock(borgmatic.execute).should_receive('execute_command').once() + flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) borgmatic.borg.diff.diff( repository='repo', @@ -59,7 +55,6 @@ def test_diff_with_numeric_ids_flag(): local_borg_version=None, diff_arguments=flexmock( same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -73,9 +68,6 @@ def test_diff_with_numeric_ids_flag(): def test_diff_with_numeric_ids_flag_false(): - flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) - flexmock(borgmatic.config.paths).should_receive('get_working_directory').and_return(None) - flexmock(borgmatic.execute).should_receive('execute_command').once() flexmock(borgmatic.borg.feature).should_receive('available').and_return(True) flexmock(flags).should_receive('make_repository_flags').and_return(()) flexmock(flags).should_receive('make_match_archives_flags').and_return(()) @@ -83,6 +75,8 @@ def test_diff_with_numeric_ids_flag_false(): flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( flexmock(name='test') ) + flexmock(borgmatic.execute).should_receive('execute_command').once() + flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) borgmatic.borg.diff.diff( repository='repo', @@ -91,7 +85,6 @@ def test_diff_with_numeric_ids_flag_false(): local_borg_version=None, diff_arguments=flexmock( same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -105,9 +98,6 @@ def test_diff_with_numeric_ids_flag_false(): def test_diff_with_only_patterns(): - flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) - flexmock(borgmatic.config.paths).should_receive('get_working_directory').and_return(None) - flexmock(borgmatic.execute).should_receive('execute_command').once() flexmock(borgmatic.borg.feature).should_receive('available').and_return(True) flexmock(flags).should_receive('make_repository_flags').and_return(()) flexmock(flags).should_receive('make_match_archives_flags').and_return(()) @@ -115,15 +105,16 @@ def test_diff_with_only_patterns(): flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( flexmock(name='test') ) + flexmock(borgmatic.execute).should_receive('execute_command').once() + flexmock(borgmatic.borg.environment).should_receive('make_environment').and_return({}) borgmatic.borg.diff.diff( repository='repo', archive='archive', - config={'numeric_ids': True}, + config={}, local_borg_version=None, diff_arguments=flexmock( same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, diff --git a/tests/unit/commands/test_borgmatic_diff.py b/tests/unit/commands/test_borgmatic_diff.py index 5bf443c4..9bf340fe 100644 --- a/tests/unit/commands/test_borgmatic_diff.py +++ b/tests/unit/commands/test_borgmatic_diff.py @@ -11,7 +11,6 @@ def test_run_configuration_with_diff_action_calls_run_diff(): 'diff': flexmock( archive='archive1', same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -32,7 +31,6 @@ def test_run_configuration_with_diff_action_and_verbose_calls_run_diff(): 'diff': flexmock( archive='archive1', same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -49,7 +47,6 @@ def test_run_configuration_with_diff_action_and_verbose_calls_run_diff(): 'diff': flexmock( archive='archive1', same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, diff --git a/tests/unit/commands/test_run_actions_diff.py b/tests/unit/commands/test_run_actions_diff.py index 2c4b2962..d60a6dbd 100644 --- a/tests/unit/commands/test_run_actions_diff.py +++ b/tests/unit/commands/test_run_actions_diff.py @@ -11,7 +11,6 @@ def test_run_actions_with_diff_calls_diff_action(): 'diff': flexmock( archive='archive1', same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None, @@ -42,7 +41,6 @@ def test_run_actions_with_diff_and_dry_run_calls_diff_action(): 'diff': flexmock( archive='archive1', same_chunker_params=False, - sort_by=None, sort_keys=[], content_only=False, second_archive=None,