test_override.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. 'new.foo=bar',
  28. 'new.mylist=[baz]',
  29. 'new.nonlist=[quux]',
  30. ]
  31. config = {
  32. 'section': {'key': 'value', 'other': 'other_value'},
  33. 'other_section': {'thing': 'thing_value'},
  34. }
  35. schema = {
  36. 'properties': {
  37. 'new': {'properties': {'mylist': {'type': 'array'}, 'nonlist': {'type': 'string'}}}
  38. }
  39. }
  40. module.apply_overrides(config, schema, raw_overrides)
  41. assert config == {
  42. 'section': {'key': 'value1', 'other': 'other_value', 'nested': {'key': 'value3'}},
  43. 'other_section': {'thing': 'value2'},
  44. 'new': {'foo': 'bar', 'mylist': ['baz'], 'nonlist': '[quux]'},
  45. }