From 9407f246748114fd02fa92c968efd62b02bd2768 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 3 Apr 2025 11:28:32 -0700 Subject: [PATCH] Fix setting of "--checks" on the command-line (#303). --- borgmatic/actions/check.py | 2 +- borgmatic/config/arguments.py | 7 ++++--- tests/unit/config/test_arguments.py | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/borgmatic/actions/check.py b/borgmatic/actions/check.py index 1e65eecb..13023ff9 100644 --- a/borgmatic/actions/check.py +++ b/borgmatic/actions/check.py @@ -170,7 +170,7 @@ def filter_checks_on_frequency( if calendar.day_name[datetime_now().weekday()] not in days: logger.info( - f"Skipping {check} check due to day of the week; check only runs on {'/'.join(days)} (use --force to check anyway)" + f"Skipping {check} check due to day of the week; check only runs on {'/'.join(day.title() for day in days)} (use --force to check anyway)" ) filtered_checks.remove(check) continue diff --git a/borgmatic/config/arguments.py b/borgmatic/config/arguments.py index e23587d7..d5996f0a 100644 --- a/borgmatic/config/arguments.py +++ b/borgmatic/config/arguments.py @@ -46,7 +46,7 @@ def set_values(config, keys, value): config[list_key] = [] set_values(config[list_key][list_index], keys[1:], value) - except IndexError: + except (IndexError, KeyError): raise ValueError(f'Argument list index {first_key} is out of range') return @@ -75,12 +75,13 @@ def type_for_option(schema, option_keys): for key in option_keys: # Support "name[0]"-style list index syntax. match = LIST_INDEX_KEY_PATTERN.match(key) + properties = borgmatic.config.schema.get_properties(option_schema) try: if match: - option_schema = option_schema['properties'][match.group('list_name')]['items'] + option_schema = properties[match.group('list_name')]['items'] else: - option_schema = option_schema['properties'][key] + option_schema = properties[key] except KeyError: return None diff --git a/tests/unit/config/test_arguments.py b/tests/unit/config/test_arguments.py index 79f0236a..fdf5f0f5 100644 --- a/tests/unit/config/test_arguments.py +++ b/tests/unit/config/test_arguments.py @@ -73,6 +73,10 @@ def test_set_values_with_final_list_index_key_adds_it_to_config(): def test_type_for_option_with_option_finds_type(): + flexmock(module.borgmatic.config.schema).should_receive('get_properties').replace_with( + lambda sub_schema: sub_schema['properties'] + ) + assert ( module.type_for_option( schema={'type': 'object', 'properties': {'foo': {'type': 'integer'}}}, @@ -83,6 +87,10 @@ def test_type_for_option_with_option_finds_type(): def test_type_for_option_with_nested_option_finds_type(): + flexmock(module.borgmatic.config.schema).should_receive('get_properties').replace_with( + lambda sub_schema: sub_schema['properties'] + ) + assert ( module.type_for_option( schema={ @@ -98,6 +106,10 @@ def test_type_for_option_with_nested_option_finds_type(): def test_type_for_option_with_missing_nested_option_finds_nothing(): + flexmock(module.borgmatic.config.schema).should_receive('get_properties').replace_with( + lambda sub_schema: sub_schema['properties'] + ) + assert ( module.type_for_option( schema={ @@ -113,6 +125,10 @@ def test_type_for_option_with_missing_nested_option_finds_nothing(): def test_type_for_option_with_typeless_nested_option_finds_nothing(): + flexmock(module.borgmatic.config.schema).should_receive('get_properties').replace_with( + lambda sub_schema: sub_schema['properties'] + ) + assert ( module.type_for_option( schema={ @@ -125,7 +141,11 @@ def test_type_for_option_with_typeless_nested_option_finds_nothing(): ) -def test_type_for_list_index_option_finds_type(): +def test_type_for_option_with_list_index_option_finds_type(): + flexmock(module.borgmatic.config.schema).should_receive('get_properties').replace_with( + lambda sub_schema: sub_schema['properties'] + ) + assert ( module.type_for_option( schema={ @@ -138,7 +158,11 @@ def test_type_for_list_index_option_finds_type(): ) -def test_type_for_nested_list_index_option_finds_type(): +def test_type_for_option_with_nested_list_index_option_finds_type(): + flexmock(module.borgmatic.config.schema).should_receive('get_properties').replace_with( + lambda sub_schema: sub_schema['properties'] + ) + assert ( module.type_for_option( schema={