Fix traceback when upgrading old INI-style configuration with upgrade-borgmatic-config (#367).

This commit is contained in:
Dan Helfman 2020-11-18 15:01:10 -08:00
parent b619bde037
commit 9b819f32f8
4 changed files with 10 additions and 7 deletions

1
NEWS
View file

@ -4,6 +4,7 @@
* #355: Fix traceback when a database hook value is null in a configuration file. * #355: Fix traceback when a database hook value is null in a configuration file.
* #361: Merge override values when specifying the "--override" flag multiple times. The previous * #361: Merge override values when specifying the "--override" flag multiple times. The previous
behavior was to take the value of the last "--override" flag only. behavior was to take the value of the last "--override" flag only.
* #367: Fix traceback when upgrading old INI-style configuration with upgrade-borgmatic-config.
* #368: Fix signal forwarding from borgmatic to Borg resulting in recursion traceback. * #368: Fix signal forwarding from borgmatic to Borg resulting in recursion traceback.
* #369: Document support for Borg placeholders in repository names. * #369: Document support for Borg placeholders in repository names.

View file

@ -99,7 +99,9 @@ def main(): # pragma: no cover
) )
generate.write_configuration( generate.write_configuration(
args.destination_config_filename, destination_config, mode=source_config_file_mode args.destination_config_filename,
generate.render_configuration(destination_config),
mode=source_config_file_mode,
) )
display_result(args) display_result(args)

View file

@ -99,7 +99,7 @@ def _comment_out_optional_configuration(rendered_config):
return '\n'.join(lines) return '\n'.join(lines)
def _render_configuration(config): def render_configuration(config):
''' '''
Given a config data structure of nested OrderedDicts, render the config as YAML and return it. Given a config data structure of nested OrderedDicts, render the config as YAML and return it.
''' '''
@ -284,5 +284,5 @@ def generate_sample_configuration(source_filename, destination_filename, schema_
write_configuration( write_configuration(
destination_filename, destination_filename,
_comment_out_optional_configuration(_render_configuration(destination_config)), _comment_out_optional_configuration(render_configuration(destination_config)),
) )

View file

@ -87,8 +87,8 @@ location:
assert module._comment_out_optional_configuration(config.strip()) == expected_config.strip() assert module._comment_out_optional_configuration(config.strip()) == expected_config.strip()
def test_render_configuration_converts_configuration_to_yaml_string(): def testrender_configuration_converts_configuration_to_yaml_string():
yaml_string = module._render_configuration({'foo': 'bar'}) yaml_string = module.render_configuration({'foo': 'bar'})
assert yaml_string == 'foo: bar\n' assert yaml_string == 'foo: bar\n'
@ -194,7 +194,7 @@ def test_generate_sample_configuration_does_not_raise():
flexmock(module.yaml).should_receive('round_trip_load') flexmock(module.yaml).should_receive('round_trip_load')
flexmock(module).should_receive('_schema_to_sample_configuration') flexmock(module).should_receive('_schema_to_sample_configuration')
flexmock(module).should_receive('merge_source_configuration_into_destination') flexmock(module).should_receive('merge_source_configuration_into_destination')
flexmock(module).should_receive('_render_configuration') flexmock(module).should_receive('render_configuration')
flexmock(module).should_receive('_comment_out_optional_configuration') flexmock(module).should_receive('_comment_out_optional_configuration')
flexmock(module).should_receive('write_configuration') flexmock(module).should_receive('write_configuration')
@ -208,7 +208,7 @@ def test_generate_sample_configuration_with_source_filename_does_not_raise():
flexmock(module.load).should_receive('load_configuration') flexmock(module.load).should_receive('load_configuration')
flexmock(module).should_receive('_schema_to_sample_configuration') flexmock(module).should_receive('_schema_to_sample_configuration')
flexmock(module).should_receive('merge_source_configuration_into_destination') flexmock(module).should_receive('merge_source_configuration_into_destination')
flexmock(module).should_receive('_render_configuration') flexmock(module).should_receive('render_configuration')
flexmock(module).should_receive('_comment_out_optional_configuration') flexmock(module).should_receive('_comment_out_optional_configuration')
flexmock(module).should_receive('write_configuration') flexmock(module).should_receive('write_configuration')