update existing tests

This commit is contained in:
Vandal
2025-03-28 22:22:19 +05:30
parent 26fd41da92
commit 7020f0530a
3 changed files with 111 additions and 98 deletions
+8 -5
View File
@@ -1,6 +1,5 @@
import logging
import shlex
from datetime import datetime
import borgmatic.borg.environment
import borgmatic.config.paths
@@ -76,10 +75,14 @@ def recreate_archive(
+ (('--timestamp', recreate_arguments.timestamp) if recreate_arguments.timestamp else ())
+ (('--compression', compression) if compression else ())
+ (('--chunker-params', chunker_params) if chunker_params else ())
+ flags.make_match_archives_flags(
recreate_arguments.match_archives or archive or config.get('match_archives'),
config.get('archive_name_format'),
local_borg_version,
+ (
flags.make_match_archives_flags(
recreate_arguments.match_archives or archive or config.get('match_archives'),
config.get('archive_name_format'),
local_borg_version,
)
if recreate_arguments.match_archives
else ()
)
+ (('--recompress', recreate_arguments.recompress) if recreate_arguments.recompress else ())
+ exclude_flags
+1
View File
@@ -1591,6 +1591,7 @@ def make_parsers():
'-a',
'--match-archives',
'--glob-archives',
dest='match_archives',
metavar='PATTERN',
help='Only consider archive names, hashes, or series matching this pattern',
)
+102 -93
View File
@@ -28,7 +28,17 @@ def test_recreate_archive_dry_run_skips_execution():
).and_return(('repo::archive',))
flexmock(module.borgmatic.execute).should_receive('execute_command').never()
recreate_arguments = flexmock(repository=flexmock(), list=None, path=None)
recreate_arguments = flexmock(
repository=flexmock(),
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
)
result = module.recreate_archive(
repository='repo',
@@ -44,11 +54,6 @@ def test_recreate_archive_dry_run_skips_execution():
def test_recreate_calls_borg_with_required_flags():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
module.recreate_archive(
@@ -56,7 +61,16 @@ def test_recreate_calls_borg_with_required_flags():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
remote_path=None,
@@ -64,30 +78,7 @@ def test_recreate_calls_borg_with_required_flags():
)
def test_recreate_calls_borg_without_archive():
logger_mock = flexmock(module.logger)
logger_mock.should_receive('error').with_args('Please provide a valid archive name.').once()
flexmock(module.borgmatic.execute).should_receive('execute_command').never()
module.recreate_archive(
repository='repo',
archive=None,
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
)
def test_recreate_with_remote_path():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', '--remote-path', 'borg1', 'repo::archive'))
module.recreate_archive(
@@ -95,7 +86,16 @@ def test_recreate_with_remote_path():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
remote_path='borg1',
@@ -104,11 +104,6 @@ def test_recreate_with_remote_path():
def test_recreate_with_lock_wait():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', '--lock-wait', '5', 'repo::archive'))
module.recreate_archive(
@@ -116,7 +111,16 @@ def test_recreate_with_lock_wait():
archive='archive',
config={'lock_wait': '5'},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
@@ -124,11 +128,6 @@ def test_recreate_with_lock_wait():
def test_recreate_with_log_info():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', '--info', 'repo::archive'))
insert_logging_mock(logging.INFO)
@@ -138,7 +137,16 @@ def test_recreate_with_log_info():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
@@ -146,11 +154,6 @@ def test_recreate_with_log_info():
def test_recreate_with_log_debug():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', '--debug', '--show-rc', 'repo::archive'))
insert_logging_mock(logging.DEBUG)
@@ -159,7 +162,16 @@ def test_recreate_with_log_debug():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
@@ -167,11 +179,6 @@ def test_recreate_with_log_debug():
def test_recreate_with_log_json():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', '--log-json', 'repo::archive'))
module.recreate_archive(
@@ -179,38 +186,23 @@ def test_recreate_with_log_json():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=True),
local_path='borg',
patterns=None,
)
def test_recreate_with_path_flag():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(('borg', 'recreate', '--path', '/some/path', 'repo::archive'))
module.recreate_archive(
repository='repo',
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path='/some/path', list=None),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
)
def test_recreate_with_list_filter_flags():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return('AME+-')
insert_execute_command_mock(
('borg', 'recreate', '--list', '--filter', 'AME+-', 'repo::archive')
@@ -221,7 +213,16 @@ def test_recreate_with_list_filter_flags():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=True),
recreate_arguments=flexmock(
list=True,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
@@ -229,12 +230,8 @@ def test_recreate_with_list_filter_flags():
def test_recreate_with_patterns_from_flag():
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo::archive',)
)
mock_patterns_file = flexmock(name='patterns_file')
flexmock(module).should_receive('write_patterns_file').and_return(mock_patterns_file)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
insert_execute_command_mock(
('borg', 'recreate', '--patterns-from', 'patterns_file', 'repo::archive')
)
@@ -244,7 +241,16 @@ def test_recreate_with_patterns_from_flag():
archive='archive',
config={},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=['pattern1', 'pattern2'],
@@ -252,14 +258,7 @@ def test_recreate_with_patterns_from_flag():
def test_recreate_with_exclude_flags():
flexmock(module.borgmatic.borg.flags).should_receive(
'make_repository_archive_flags'
).and_return(('repo::archive',))
flexmock(module).should_receive('write_patterns_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return(None)
# Mock the make_exclude_flags to return a sample exclude flag
flexmock(module).should_receive('make_exclude_flags').and_return(('--exclude', 'pattern'))
insert_execute_command_mock(('borg', 'recreate', '--exclude', 'pattern', 'repo::archive'))
module.recreate_archive(
@@ -267,8 +266,18 @@ def test_recreate_with_exclude_flags():
archive='archive',
config={'exclude_patterns': ['pattern']},
local_borg_version='1.2.3',
recreate_arguments=flexmock(path=None, list=None),
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
compression=None,
chunker_params=None,
match_archives=None,
recompress=None,
),
global_arguments=flexmock(dry_run=False, log_json=False),
local_path='borg',
patterns=None,
)