test_load.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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())