test_version.py 2.0 KB

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