test_load.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. flexmock(module).should_receive('load_configuration').with_args('/etc/include.yaml').and_return(
  7. config
  8. ).once()
  9. assert module.probe_and_include_file('/etc/include.yaml', ['/etc', '/var']) == config
  10. def test_probe_and_include_file_with_relative_path_probes_include_directories():
  11. config = flexmock()
  12. flexmock(module.os.path).should_receive('exists').with_args('/etc/include.yaml').and_return(
  13. False
  14. )
  15. flexmock(module.os.path).should_receive('exists').with_args('/var/include.yaml').and_return(
  16. True
  17. )
  18. flexmock(module).should_receive('load_configuration').with_args('/etc/include.yaml').never()
  19. flexmock(module).should_receive('load_configuration').with_args('/var/include.yaml').and_return(
  20. config
  21. ).once()
  22. assert module.probe_and_include_file('include.yaml', ['/etc', '/var']) == config
  23. def test_probe_and_include_file_with_relative_path_and_missing_files_raises():
  24. flexmock(module.os.path).should_receive('exists').and_return(False)
  25. flexmock(module).should_receive('load_configuration').never()
  26. with pytest.raises(FileNotFoundError):
  27. module.probe_and_include_file('include.yaml', ['/etc', '/var'])