test_load.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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',
  9. config_paths,
  10. ).and_return(config).once()
  11. assert (
  12. module.probe_and_include_file('/etc/include.yaml', ['/etc', '/var'], config_paths) == config
  13. )
  14. def test_probe_and_include_file_with_relative_path_probes_include_directories():
  15. config = {'foo': 'bar'}
  16. config_paths = set()
  17. flexmock(module.os.path).should_receive('exists').with_args('/etc/include.yaml').and_return(
  18. False,
  19. )
  20. flexmock(module.os.path).should_receive('exists').with_args('/var/include.yaml').and_return(
  21. True,
  22. )
  23. flexmock(module).should_receive('load_configuration').with_args(
  24. '/etc/include.yaml',
  25. config_paths,
  26. ).never()
  27. flexmock(module).should_receive('load_configuration').with_args(
  28. '/var/include.yaml',
  29. config_paths,
  30. ).and_return(config).once()
  31. assert module.probe_and_include_file('include.yaml', ['/etc', '/var'], config_paths) == {
  32. 'foo': 'bar',
  33. }
  34. def test_probe_and_include_file_with_relative_path_and_missing_files_raises():
  35. flexmock(module.os.path).should_receive('exists').and_return(False)
  36. flexmock(module).should_receive('load_configuration').never()
  37. with pytest.raises(FileNotFoundError):
  38. module.probe_and_include_file('include.yaml', ['/etc', '/var'], config_paths=set())