test_version.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import version as module
  5. from ..test_verbosity import insert_logging_mock
  6. VERSION = '1.2.3'
  7. def insert_execute_command_and_capture_output_mock(
  8. command, borg_local_path='borg', version_output=f'borg {VERSION}'
  9. ):
  10. flexmock(module.environment).should_receive('make_environment')
  11. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  12. command,
  13. extra_environment=None,
  14. ).once().and_return(version_output)
  15. def test_local_borg_version_calls_borg_with_required_parameters():
  16. insert_execute_command_and_capture_output_mock(('borg', '--version'))
  17. flexmock(module.environment).should_receive('make_environment')
  18. assert module.local_borg_version({}) == VERSION
  19. def test_local_borg_version_with_log_info_calls_borg_with_info_parameter():
  20. insert_execute_command_and_capture_output_mock(('borg', '--version', '--info'))
  21. insert_logging_mock(logging.INFO)
  22. flexmock(module.environment).should_receive('make_environment')
  23. assert module.local_borg_version({}) == VERSION
  24. def test_local_borg_version_with_log_debug_calls_borg_with_debug_parameters():
  25. insert_execute_command_and_capture_output_mock(('borg', '--version', '--debug', '--show-rc'))
  26. insert_logging_mock(logging.DEBUG)
  27. flexmock(module.environment).should_receive('make_environment')
  28. assert module.local_borg_version({}) == VERSION
  29. def test_local_borg_version_with_local_borg_path_calls_borg_with_it():
  30. insert_execute_command_and_capture_output_mock(('borg1', '--version'), borg_local_path='borg1')
  31. flexmock(module.environment).should_receive('make_environment')
  32. assert module.local_borg_version({}, 'borg1') == VERSION
  33. def test_local_borg_version_with_invalid_version_raises():
  34. insert_execute_command_and_capture_output_mock(('borg', '--version'), version_output='wtf')
  35. flexmock(module.environment).should_receive('make_environment')
  36. with pytest.raises(ValueError):
  37. module.local_borg_version({})