mirror of
https://projects.torsion.org/witten/borgmatic.git
synced 2025-04-15 00:28:30 +00:00
Fix for the example not showing up in generated config for empty YAML objects (#303).
This commit is contained in:
parent
e96db2e100
commit
017cbae4f9
2 changed files with 44 additions and 10 deletions
|
@ -53,16 +53,21 @@ def schema_to_sample_configuration(schema, source_config=None, level=0, parent_i
|
|||
if source_config and isinstance(source_config, list) and isinstance(source_config[0], dict):
|
||||
source_config = dict(collections.ChainMap(*source_config))
|
||||
|
||||
config = ruamel.yaml.comments.CommentedMap(
|
||||
[
|
||||
(
|
||||
field_name,
|
||||
schema_to_sample_configuration(
|
||||
sub_schema, (source_config or {}).get(field_name, {}), level + 1
|
||||
),
|
||||
)
|
||||
for field_name, sub_schema in borgmatic.config.schema.get_properties(schema).items()
|
||||
]
|
||||
config = (
|
||||
ruamel.yaml.comments.CommentedMap(
|
||||
[
|
||||
(
|
||||
field_name,
|
||||
schema_to_sample_configuration(
|
||||
sub_schema, (source_config or {}).get(field_name, {}), level + 1
|
||||
),
|
||||
)
|
||||
for field_name, sub_schema in borgmatic.config.schema.get_properties(
|
||||
schema
|
||||
).items()
|
||||
]
|
||||
)
|
||||
or example
|
||||
)
|
||||
indent = (level * INDENT) + (SEQUENCE_INDENT if parent_is_sequence else 0)
|
||||
add_comments_to_configuration_object(
|
||||
|
|
|
@ -39,6 +39,35 @@ def test_schema_to_sample_configuration_generates_config_map_with_examples():
|
|||
)
|
||||
|
||||
|
||||
def test_schema_to_sample_configuration_with_empty_object_generates_config_map_with_example():
|
||||
schema = {
|
||||
'type': 'object',
|
||||
'example': {
|
||||
'foo': 'Example 1',
|
||||
'baz': 'Example 2',
|
||||
},
|
||||
}
|
||||
flexmock(module.borgmatic.config.schema).should_receive('compare_types').and_return(False)
|
||||
flexmock(module.borgmatic.config.schema).should_receive('compare_types').with_args(
|
||||
'object', {'object'}
|
||||
).and_return(True)
|
||||
flexmock(module.borgmatic.config.schema).should_receive('compare_types').with_args(
|
||||
'string', module.SCALAR_SCHEMA_TYPES, match=all
|
||||
).and_return(True)
|
||||
flexmock(module.borgmatic.config.schema).should_receive('get_properties').and_return({})
|
||||
flexmock(module.ruamel.yaml.comments).should_receive('CommentedMap').replace_with(dict)
|
||||
flexmock(module).should_receive('add_comments_to_configuration_object')
|
||||
|
||||
config = module.schema_to_sample_configuration(schema)
|
||||
|
||||
assert config == dict(
|
||||
[
|
||||
('foo', 'Example 1'),
|
||||
('baz', 'Example 2'),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_schema_to_sample_configuration_generates_config_sequence_of_strings_with_example():
|
||||
flexmock(module.ruamel.yaml.comments).should_receive('CommentedSeq').replace_with(list)
|
||||
flexmock(module).should_receive('add_comments_to_configuration_sequence')
|
||||
|
|
Loading…
Add table
Reference in a new issue