test_generate.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from collections import OrderedDict
  2. from flexmock import flexmock
  3. from borgmatic.config import generate as module
  4. def test_schema_to_sample_configuration_generates_config_with_examples():
  5. flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
  6. flexmock(module).should_receive('add_comments_to_configuration')
  7. schema = {
  8. 'map': OrderedDict(
  9. [
  10. ('section1', {'map': {'field1': OrderedDict([('example', 'Example 1')])}}),
  11. (
  12. 'section2',
  13. {
  14. 'map': OrderedDict(
  15. [
  16. ('field2', {'example': 'Example 2'}),
  17. ('field3', {'example': 'Example 3'}),
  18. ]
  19. )
  20. },
  21. ),
  22. ]
  23. )
  24. }
  25. config = module._schema_to_sample_configuration(schema)
  26. assert config == OrderedDict(
  27. [
  28. ('section1', OrderedDict([('field1', 'Example 1')])),
  29. ('section2', OrderedDict([('field2', 'Example 2'), ('field3', 'Example 3')])),
  30. ]
  31. )