test_generate.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from io import StringIO
  2. import sys
  3. from flexmock import flexmock
  4. from borgmatic.config import generate as module
  5. def test_insert_newline_before_comment_does_not_raise():
  6. field_name = 'foo'
  7. config = module.yaml.comments.CommentedMap([(field_name, 33)])
  8. config.yaml_set_comment_before_after_key(key=field_name, before='Comment',)
  9. module._insert_newline_before_comment(config, field_name)
  10. def test_write_configuration_does_not_raise():
  11. builtins = flexmock(sys.modules['builtins'])
  12. builtins.should_receive('open').and_return(StringIO())
  13. module.write_configuration('config.yaml', {})
  14. def test_add_comments_to_configuration_does_not_raise():
  15. # Ensure that it can deal with fields both in the schema and missing from the schema.
  16. config = module.yaml.comments.CommentedMap([('foo', 33), ('bar', 44), ('baz', 55)])
  17. schema = {
  18. 'map': {
  19. 'foo': {'desc': 'Foo'},
  20. 'bar': {'desc': 'Bar'},
  21. }
  22. }
  23. module.add_comments_to_configuration(config, schema)
  24. def test_generate_sample_configuration_does_not_raise():
  25. builtins = flexmock(sys.modules['builtins'])
  26. builtins.should_receive('open').with_args('schema.yaml').and_return('')
  27. flexmock(module).should_receive('write_configuration')
  28. flexmock(module).should_receive('_schema_to_sample_configuration')
  29. module.generate_sample_configuration('config.yaml', 'schema.yaml')