Prechádzať zdrojové kódy

Add a few more missing tests (#1019).

Dan Helfman 3 mesiacov pred
rodič
commit
5ab766b51c

+ 2 - 2
borgmatic/commands/borgmatic.py

@@ -830,7 +830,7 @@ def collect_configuration_run_summary_logs(configs, config_paths, arguments):
                 configuration_filename=config_filename,
             )
     except (CalledProcessError, ValueError, OSError) as error:
-        yield from log_error_records('Error running pre-everything hook', error)
+        yield from log_error_records('Error running before everything hook', error)
         return
 
     # Execute the actions corresponding to each configuration file.
@@ -882,7 +882,7 @@ def collect_configuration_run_summary_logs(configs, config_paths, arguments):
                 configuration_filename=config_filename,
             )
     except (CalledProcessError, ValueError, OSError) as error:
-        yield from log_error_records('Error running post-everything hook', error)
+        yield from log_error_records('Error running after everything hook', error)
 
 
 def exit_with_help_link():  # pragma: no cover

+ 35 - 4
tests/integration/config/test_generate.py

@@ -262,7 +262,7 @@ def test_add_comments_to_configuration_sequence_of_maps_without_description_does
     module.add_comments_to_configuration_sequence(config, schema)
 
 
-def test_add_comments_to_configuration_object_does_not_raise():
+def test_add_comments_to_configuration_comments_out_non_default_options():
     # Ensure that it can deal with fields both in the schema and missing from the schema.
     config = module.ruamel.yaml.comments.CommentedMap([('foo', 33), ('bar', 44), ('baz', 55)])
     schema = {
@@ -272,13 +272,44 @@ def test_add_comments_to_configuration_object_does_not_raise():
 
     module.add_comments_to_configuration_object(config, schema)
 
+    assert 'COMMENT_OUT' in config.ca.items['foo'][1][-1]._value
+    assert 'COMMENT_OUT' in config.ca.items['bar'][1][-1]._value
+    assert 'baz' not in config.ca.items
 
-def test_add_comments_to_configuration_object_with_skip_first_does_not_raise():
-    config = module.ruamel.yaml.comments.CommentedMap([('foo', 33)])
-    schema = {'type': 'object', 'properties': {'foo': {'description': 'Foo'}}}
+
+def test_add_comments_to_configuration_comments_out_non_source_config_options():
+    # Ensure that it can deal with fields both in the schema and missing from the schema.
+    config = module.ruamel.yaml.comments.CommentedMap(
+        [('repositories', 33), ('bar', 44), ('baz', 55)]
+    )
+    schema = {
+        'type': 'object',
+        'properties': {
+            'repositories': {'description': 'repositories'},
+            'bar': {'description': 'Bar'},
+        },
+    }
+
+    module.add_comments_to_configuration_object(config, schema)
+
+    assert 'repositories' in config.ca.items
+    assert 'COMMENT_OUT' in config.ca.items['bar'][1][-1]._value
+    assert 'baz' not in config.ca.items
+
+
+def test_add_comments_to_configuration_object_with_skip_first_does_not_comment_out_first_option():
+    config = module.ruamel.yaml.comments.CommentedMap([('foo', 33), ('bar', 44), ('baz', 55)])
+    schema = {
+        'type': 'object',
+        'properties': {'foo': {'description': 'Foo'}, 'bar': {'description': 'Bar'}},
+    }
 
     module.add_comments_to_configuration_object(config, schema, skip_first=True)
 
+    assert 'foo' not in config.ca.items
+    assert 'COMMENT_OUT' in config.ca.items['bar'][1][-1]._value
+    assert 'baz' not in config.ca.items
+
 
 def test_generate_sample_configuration_does_not_raise():
     builtins = flexmock(sys.modules['builtins'])

+ 36 - 1
tests/unit/config/test_generate.py

@@ -17,7 +17,7 @@ def test_get_properties_with_simple_object():
     assert module.get_properties(schema) == schema['properties']
 
 
-def test_get_properties_merges_one_of_list_properties():
+def test_get_properties_merges_oneof_list_properties():
     schema = {
         'type': 'object',
         'oneOf': [
@@ -45,6 +45,41 @@ def test_get_properties_merges_one_of_list_properties():
     )
 
 
+def test_get_properties_interleaves_oneof_list_properties():
+    schema = {
+        'type': 'object',
+        'oneOf': [
+            {
+                'properties': dict(
+                    [
+                        ('field1', {'example': 'Example 1'}),
+                        ('field2', {'example': 'Example 2'}),
+                        ('field3', {'example': 'Example 3'}),
+                    ]
+                ),
+            },
+            {
+                'properties': dict(
+                    [
+                        ('field4', {'example': 'Example 4'}),
+                        ('field5', {'example': 'Example 5'}),
+                    ]
+                ),
+            },
+        ],
+    }
+
+    assert module.get_properties(schema) == dict(
+        [
+            ('field1', {'example': 'Example 1'}),
+            ('field4', {'example': 'Example 4'}),
+            ('field2', {'example': 'Example 2'}),
+            ('field5', {'example': 'Example 5'}),
+            ('field3', {'example': 'Example 3'}),
+        ]
+    )
+
+
 def test_schema_to_sample_configuration_generates_config_map_with_examples():
     schema = {
         'type': 'object',