test_override.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import pytest
  2. from borgmatic.config import override as module
  3. @pytest.mark.parametrize(
  4. 'value,expected_result,option_type',
  5. (
  6. ('thing', 'thing', 'string'),
  7. ('33', 33, 'integer'),
  8. ('33', '33', 'string'),
  9. ('33b', '33b', 'integer'),
  10. ('33b', '33b', 'string'),
  11. ('true', True, 'boolean'),
  12. ('false', False, 'boolean'),
  13. ('true', 'true', 'string'),
  14. ('[foo]', ['foo'], 'array'),
  15. ('[foo]', '[foo]', 'string'),
  16. ('[foo, bar]', ['foo', 'bar'], 'array'),
  17. ('[foo, bar]', '[foo, bar]', 'string'),
  18. ),
  19. )
  20. def test_convert_value_type_coerces_values(value, expected_result, option_type):
  21. assert module.convert_value_type(value, option_type) == expected_result
  22. def test_apply_overrides_updates_config():
  23. raw_overrides = [
  24. 'section.key=value1',
  25. 'other_section.thing=value2',
  26. 'section.nested.key=value3',
  27. 'location.no_longer_in_location=value4',
  28. 'new.foo=bar',
  29. 'new.mylist=[baz]',
  30. 'new.nonlist=[quux]',
  31. ]
  32. config = {
  33. 'section': {'key': 'value', 'other': 'other_value'},
  34. 'other_section': {'thing': 'thing_value'},
  35. 'no_longer_in_location': 'because_location_is_deprecated',
  36. }
  37. schema = {
  38. 'properties': {
  39. 'new': {'properties': {'mylist': {'type': 'array'}, 'nonlist': {'type': 'string'}}}
  40. }
  41. }
  42. module.apply_overrides(config, schema, raw_overrides)
  43. assert config == {
  44. 'section': {'key': 'value1', 'other': 'other_value', 'nested': {'key': 'value3'}},
  45. 'other_section': {'thing': 'value2'},
  46. 'new': {'foo': 'bar', 'mylist': ['baz'], 'nonlist': '[quux]'},
  47. 'location': {'no_longer_in_location': 'value4'},
  48. 'no_longer_in_location': 'value4',
  49. }