update tests and formatting

This commit is contained in:
Divyansh Singh 2023-05-16 23:17:35 +05:30
parent b10148844b
commit ee32b076eb
3 changed files with 59 additions and 59 deletions

View file

@ -1,15 +1,17 @@
import json
import os
import logging
import os
try:
import importlib_metadata
except ModuleNotFoundError: # pragma: nocover
import importlib.metadata as importlib_metadata
import borgmatic.borg.create
import borgmatic.config.validate
import borgmatic.hooks.command
import borgmatic.hooks.dispatch
import borgmatic.hooks.dump
from borgmatic.borg.state import DEFAULT_BORGMATIC_SOURCE_DIRECTORY
logger = logging.getLogger(__name__)
@ -23,10 +25,8 @@ def create_borgmatic_manifest(location, config_paths, dry_run):
if dry_run:
return
borgmatic_source_directory = (
location.get('borgmatic_source_directory')
if location.get('borgmatic_source_directory')
else DEFAULT_BORGMATIC_SOURCE_DIRECTORY
borgmatic_source_directory = location.get(
'borgmatic_source_directory', DEFAULT_BORGMATIC_SOURCE_DIRECTORY
)
borgmatic_manifest_path = os.path.expanduser(
@ -36,13 +36,13 @@ def create_borgmatic_manifest(location, config_paths, dry_run):
if not os.path.exists(borgmatic_manifest_path):
os.makedirs(os.path.dirname(borgmatic_manifest_path), exist_ok=True)
with open(borgmatic_manifest_path, 'w') as f:
with open(borgmatic_manifest_path, 'w') as config_list_file:
json.dump(
{
'borgmatic_version': importlib_metadata.version('borgmatic'),
'config_paths': config_paths,
},
f,
config_list_file,
)

View file

@ -19,7 +19,7 @@ def test_run_create_executes_and_calls_hooks_for_configured_repository():
json=flexmock(),
list_files=flexmock(),
)
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False, used_config_paths=[])
list(
module.run_create(
@ -52,7 +52,7 @@ def test_run_create_runs_with_selected_repository():
json=flexmock(),
list_files=flexmock(),
)
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False, used_config_paths=[])
list(
module.run_create(
@ -85,7 +85,7 @@ def test_run_create_bails_if_repository_does_not_match():
json=flexmock(),
list_files=flexmock(),
)
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False, used_config_paths=[])
list(
module.run_create(

View file

@ -492,7 +492,7 @@ def test_create_archive_calls_borg_with_parameters():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -536,7 +536,7 @@ def test_create_archive_calls_borg_with_environment():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -582,7 +582,7 @@ def test_create_archive_with_patterns_calls_borg_with_patterns_including_convert
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -628,7 +628,7 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -672,7 +672,7 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -713,7 +713,7 @@ def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
json=True,
)
@ -758,7 +758,7 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -799,7 +799,7 @@ def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
json=True,
)
@ -843,7 +843,7 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -889,7 +889,7 @@ def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_paramete
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
stats=True,
)
@ -933,7 +933,7 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
},
storage_config={'checkpoint_interval': 600},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -976,7 +976,7 @@ def test_create_archive_with_checkpoint_volume_calls_borg_with_checkpoint_volume
},
storage_config={'checkpoint_volume': 1024},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1019,7 +1019,7 @@ def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_param
},
storage_config={'chunker_params': '1,2,3,4'},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1062,7 +1062,7 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
},
storage_config={'compression': 'rle'},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1111,7 +1111,7 @@ def test_create_archive_with_upload_rate_limit_calls_borg_with_upload_ratelimit_
},
storage_config={'upload_rate_limit': 100},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1157,7 +1157,7 @@ def test_create_archive_with_working_directory_calls_borg_with_working_directory
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1201,7 +1201,7 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1251,7 +1251,7 @@ def test_create_archive_with_numeric_ids_calls_borg_with_numeric_ids_parameter(
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1305,7 +1305,7 @@ def test_create_archive_with_read_special_calls_borg_with_read_special_parameter
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1361,7 +1361,7 @@ def test_create_archive_with_basic_option_calls_borg_with_corresponding_paramete
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1416,7 +1416,7 @@ def test_create_archive_with_atime_option_calls_borg_with_corresponding_paramete
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1471,7 +1471,7 @@ def test_create_archive_with_flags_option_calls_borg_with_corresponding_paramete
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1515,7 +1515,7 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1558,7 +1558,7 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
local_path='borg1',
)
@ -1602,7 +1602,7 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
remote_path='borg1',
)
@ -1646,7 +1646,7 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
},
storage_config={'umask': 740},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1689,7 +1689,7 @@ def test_create_archive_with_log_json_calls_borg_with_log_json_parameters():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=True),
global_arguments=flexmock(log_json=True, used_config_paths=[]),
)
@ -1732,7 +1732,7 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
},
storage_config={'lock_wait': 5},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -1775,7 +1775,7 @@ def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_answer_ou
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
stats=True,
)
@ -1819,7 +1819,7 @@ def test_create_archive_with_files_calls_borg_with_list_parameter_and_answer_out
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
list_files=True,
)
@ -1869,7 +1869,7 @@ def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_para
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
progress=True,
)
@ -1913,7 +1913,7 @@ def test_create_archive_with_progress_calls_borg_with_progress_parameter():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
progress=True,
)
@ -1974,7 +1974,7 @@ def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progr
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
progress=True,
stream_processes=processes,
)
@ -2039,7 +2039,7 @@ def test_create_archive_with_stream_processes_ignores_read_special_false_and_log
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
stream_processes=processes,
)
@ -2107,7 +2107,7 @@ def test_create_archive_with_stream_processes_adds_special_files_to_excludes():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
stream_processes=processes,
)
@ -2172,7 +2172,7 @@ def test_create_archive_with_stream_processes_and_read_special_does_not_add_spec
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
stream_processes=processes,
)
@ -2213,7 +2213,7 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
json=True,
)
@ -2256,7 +2256,7 @@ def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter()
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
json=True,
stats=True,
)
@ -2304,7 +2304,7 @@ def test_create_archive_with_source_directories_glob_expands():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2348,7 +2348,7 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2391,7 +2391,7 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories():
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2434,7 +2434,7 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
},
storage_config={'archive_name_format': 'ARCHIVE_NAME'},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2478,7 +2478,7 @@ def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
},
storage_config={'archive_name_format': 'Documents_{hostname}-{now}'}, # noqa: FS003
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2522,7 +2522,7 @@ def test_create_archive_with_repository_accepts_borg_placeholders():
},
storage_config={'archive_name_format': 'Documents_{hostname}-{now}'}, # noqa: FS003
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2565,7 +2565,7 @@ def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
},
storage_config={'extra_borg_options': {'create': '--extra --options'}},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)
@ -2626,7 +2626,7 @@ def test_create_archive_with_stream_processes_calls_borg_with_processes_and_read
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
stream_processes=processes,
)
@ -2652,7 +2652,7 @@ def test_create_archive_with_non_existent_directory_and_source_directories_must_
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False),
global_arguments=flexmock(log_json=False, used_config_paths=[]),
)