Browse Source

Fix setting of "--checks" on the command-line (#303).

Dan Helfman 2 months ago
parent
commit
9407f24674
3 changed files with 31 additions and 6 deletions
  1. 1 1
      borgmatic/actions/check.py
  2. 4 3
      borgmatic/config/arguments.py
  3. 26 2
      tests/unit/config/test_arguments.py

+ 1 - 1
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

+ 4 - 3
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
 

+ 26 - 2
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={