test_version.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_mock(command, borg_local_path='borg', version_output=f'borg {VERSION}'):
  8. flexmock(module.environment).should_receive('make_environment')
  9. flexmock(module).should_receive('execute_command').with_args(
  10. command, output_log_level=None, borg_local_path=borg_local_path, extra_environment=None,
  11. ).once().and_return(version_output)
  12. def test_local_borg_version_calls_borg_with_required_parameters():
  13. insert_execute_command_mock(('borg', '--version'))
  14. flexmock(module.environment).should_receive('make_environment')
  15. assert module.local_borg_version({}) == VERSION
  16. def test_local_borg_version_with_log_info_calls_borg_with_info_parameter():
  17. insert_execute_command_mock(('borg', '--version', '--info'))
  18. insert_logging_mock(logging.INFO)
  19. flexmock(module.environment).should_receive('make_environment')
  20. assert module.local_borg_version({}) == VERSION
  21. def test_local_borg_version_with_log_debug_calls_borg_with_debug_parameters():
  22. insert_execute_command_mock(('borg', '--version', '--debug', '--show-rc'))
  23. insert_logging_mock(logging.DEBUG)
  24. flexmock(module.environment).should_receive('make_environment')
  25. assert module.local_borg_version({}) == VERSION
  26. def test_local_borg_version_with_local_borg_path_calls_borg_with_it():
  27. insert_execute_command_mock(('borg1', '--version'), borg_local_path='borg1')
  28. flexmock(module.environment).should_receive('make_environment')
  29. assert module.local_borg_version({}, 'borg1') == VERSION
  30. def test_local_borg_version_with_invalid_version_raises():
  31. insert_execute_command_mock(('borg', '--version'), version_output='wtf')
  32. flexmock(module.environment).should_receive('make_environment')
  33. with pytest.raises(ValueError):
  34. module.local_borg_version({})