Factor out schema type comparion in config generation and get several tests passing (#303).

This commit is contained in:
Dan Helfman
2025-03-23 11:24:36 -07:00
parent f222bf2c1a
commit 57721937a3
4 changed files with 47 additions and 16 deletions
+20 -8
View File
@@ -2,6 +2,7 @@ import pytest
from flexmock import flexmock
from borgmatic.config import generate as module
import borgmatic.config.schema
def test_schema_to_sample_configuration_generates_config_map_with_examples():
@@ -9,13 +10,16 @@ def test_schema_to_sample_configuration_generates_config_map_with_examples():
'type': 'object',
'properties': dict(
[
('field1', {'example': 'Example 1'}),
('field2', {'example': 'Example 2'}),
('field3', {'example': 'Example 3'}),
('field1', {'type': 'string', 'example': 'Example 1'}),
('field2', {'type': 'string', 'example': 'Example 2'}),
('field3', {'type': 'string', 'example': 'Example 3'}),
]
),
}
flexmock(module).should_receive('get_properties').and_return(schema['properties'])
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(schema['properties'])
flexmock(module.ruamel.yaml.comments).should_receive('CommentedMap').replace_with(dict)
flexmock(module).should_receive('add_comments_to_configuration_object')
@@ -46,11 +50,15 @@ def test_schema_to_sample_configuration_generates_config_sequence_of_maps_with_e
'items': {
'type': 'object',
'properties': dict(
[('field1', {'example': 'Example 1'}), ('field2', {'example': 'Example 2'})]
[('field1', {'type': 'string', 'example': 'Example 1'}), ('field2', {'type': 'string', 'example': 'Example 2'})]
),
},
}
flexmock(module).should_receive('get_properties').and_return(schema['items']['properties'])
flexmock(module.borgmatic.config.schema).should_receive('compare_types').and_return(False)
flexmock(module.borgmatic.config.schema).should_receive('compare_types').with_args('array', {'array'}).and_return(True)
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(schema['items']['properties'])
flexmock(module.ruamel.yaml.comments).should_receive('CommentedSeq').replace_with(list)
flexmock(module).should_receive('add_comments_to_configuration_sequence')
flexmock(module).should_receive('add_comments_to_configuration_object')
@@ -66,11 +74,15 @@ def test_schema_to_sample_configuration_generates_config_sequence_of_maps_with_m
'items': {
'type': ['object', 'null'],
'properties': dict(
[('field1', {'example': 'Example 1'}), ('field2', {'example': 'Example 2'})]
[('field1', {'type': 'string', 'example': 'Example 1'}), ('field2', {'type': 'string', 'example': 'Example 2'})]
),
},
}
flexmock(module).should_receive('get_properties').and_return(schema['items']['properties'])
flexmock(module.borgmatic.config.schema).should_receive('compare_types').and_return(False)
flexmock(module.borgmatic.config.schema).should_receive('compare_types').with_args('array', {'array'}).and_return(True)
flexmock(module.borgmatic.config.schema).should_receive('compare_types').with_args(['object', 'null'], {'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(schema['items']['properties'])
flexmock(module.ruamel.yaml.comments).should_receive('CommentedSeq').replace_with(list)
flexmock(module).should_receive('add_comments_to_configuration_sequence')
flexmock(module).should_receive('add_comments_to_configuration_object')