test_load.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import pytest
  2. from flexmock import flexmock
  3. from borgmatic.config import load as module
  4. def test_probe_and_include_file_with_absolute_path_skips_probing():
  5. config = flexmock()
  6. config_paths = set()
  7. flexmock(module).should_receive('load_configuration').with_args(
  8. '/etc/include.yaml', config_paths
  9. ).and_return(config).once()
  10. assert (
  11. module.probe_and_include_file('/etc/include.yaml', ['/etc', '/var'], config_paths) == config
  12. )
  13. def test_probe_and_include_file_with_relative_path_probes_include_directories():
  14. config = {'foo': 'bar'}
  15. config_paths = set()
  16. flexmock(module.os.path).should_receive('exists').with_args('/etc/include.yaml').and_return(
  17. False
  18. )
  19. flexmock(module.os.path).should_receive('exists').with_args('/var/include.yaml').and_return(
  20. True
  21. )
  22. flexmock(module).should_receive('load_configuration').with_args(
  23. '/etc/include.yaml', config_paths
  24. ).never()
  25. flexmock(module).should_receive('load_configuration').with_args(
  26. '/var/include.yaml', config_paths
  27. ).and_return(config).once()
  28. assert module.probe_and_include_file('include.yaml', ['/etc', '/var'], config_paths) == {
  29. 'foo': 'bar',
  30. }
  31. def test_probe_and_include_file_with_relative_path_and_missing_files_raises():
  32. flexmock(module.os.path).should_receive('exists').and_return(False)
  33. flexmock(module).should_receive('load_configuration').never()
  34. with pytest.raises(FileNotFoundError):
  35. module.probe_and_include_file('include.yaml', ['/etc', '/var'], config_paths=set())
  36. def test_reserialize_tag_node_turns_it_into_string():
  37. assert (
  38. module.reserialize_tag_node(loader=flexmock(), tag_node=flexmock(tag='!tag', value='value'))
  39. == '!tag value'
  40. )
  41. def test_reserialize_tag_node_with_invalid_value_raises():
  42. with pytest.raises(ValueError):
  43. assert module.reserialize_tag_node(
  44. loader=flexmock(), tag_node=flexmock(tag='!tag', value=['value'])
  45. )