From 06e2b4f2c726f16904149b30125e83ca14c747c0 Mon Sep 17 00:00:00 2001 From: lingfish Date: Tue, 24 Feb 2026 11:28:36 +1100 Subject: [PATCH] Attempt to use with_args(). --- tests/unit/borg/test_diff.py | 110 ++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/tests/unit/borg/test_diff.py b/tests/unit/borg/test_diff.py index 92c908ef..2828e630 100644 --- a/tests/unit/borg/test_diff.py +++ b/tests/unit/borg/test_diff.py @@ -1,24 +1,24 @@ +import logging + from flexmock import flexmock -import borgmatic.borg.diff -import borgmatic.borg.environment -import borgmatic.borg.feature -import borgmatic.execute -from borgmatic.borg import flags +from borgmatic.borg import diff as module def test_diff_calls_execute_command(): - 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(()) - flexmock(flags).should_receive('make_repository_archive_flags').and_return(()) - flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( + flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(False) + flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive( + 'make_repository_archive_flags' + ).and_return(()) + flexmock(module.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({}) + flexmock(module.borgmatic.execute).should_receive('execute_command').once() + flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return({}) - borgmatic.borg.diff.diff( + module.borgmatic.borg.diff.diff( repository='repo', archive='archive', config={}, @@ -38,17 +38,19 @@ def test_diff_calls_execute_command(): def test_diff_with_numeric_ids_flag(): - 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(()) - flexmock(flags).should_receive('make_repository_archive_flags').and_return(()) - flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( + flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True) + flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive( + 'make_repository_archive_flags' + ).and_return(()) + flexmock(module.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({}) + flexmock(module.borgmatic.execute).should_receive('execute_command').once() + flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return({}) - borgmatic.borg.diff.diff( + module.borgmatic.borg.diff.diff( repository='repo', archive='archive', config={'numeric_ids': True}, @@ -68,17 +70,19 @@ def test_diff_with_numeric_ids_flag(): def test_diff_with_numeric_ids_flag_false(): - 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(()) - flexmock(flags).should_receive('make_repository_archive_flags').and_return(()) - flexmock(borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( + flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True) + flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive( + 'make_repository_archive_flags' + ).and_return(()) + flexmock(module.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({}) + flexmock(module.borgmatic.execute).should_receive('execute_command').once() + flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return({}) - borgmatic.borg.diff.diff( + module.borgmatic.borg.diff.diff( repository='repo', archive='archive', config={'numeric_ids': False}, @@ -98,17 +102,45 @@ def test_diff_with_numeric_ids_flag_false(): def test_diff_with_only_patterns(): - 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(()) - flexmock(flags).should_receive('make_repository_archive_flags').and_return(()) - 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({}) + # Mock the feature check + flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True) - borgmatic.borg.diff.diff( + flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return( + ('--repo', 'repo') + ) + flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(()) + flexmock(module.borgmatic.borg.flags).should_receive( + 'make_repository_archive_flags' + ).and_return(()) + + environment = flexmock() + flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return( + environment + ) + + flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return( + '/tmp/test_patterns' + ) + + expected_command = ( + 'borg', + 'diff', + '--log-json', # Add this flag + '--repo', + 'repo', + None, + ) + + flexmock(module.borgmatic.execute).should_receive('execute_command').with_args( + full_command=expected_command, + output_log_level=logging.ANSWER, + environment=environment, + working_directory=None, + borg_local_path='borg', + borg_exit_codes=None, + ).once() + + module.borgmatic.borg.diff.diff( repository='repo', archive='archive', config={},