Next raft of suggested fixes.

This commit is contained in:
lingfish
2026-02-23 11:03:25 +11:00
parent 4f25581a12
commit 42c006cf1d
5 changed files with 60 additions and 38 deletions
+9 -6
View File
@@ -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'],
+42 -9
View File
@@ -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,
)
+9 -18
View File
@@ -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,
@@ -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,
@@ -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,