12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import logging
- import pytest
- from flexmock import flexmock
- from borgmatic.borg import version as module
- from ..test_verbosity import insert_logging_mock
- VERSION = '1.2.3'
- def insert_execute_command_and_capture_output_mock(
- command, borg_local_path='borg', borg_exit_codes=None, version_output=f'borg {VERSION}'
- ):
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command_and_capture_output').with_args(
- command,
- extra_environment=None,
- borg_local_path=borg_local_path,
- borg_exit_codes=borg_exit_codes,
- ).once().and_return(version_output)
- def test_local_borg_version_calls_borg_with_required_parameters():
- insert_execute_command_and_capture_output_mock(('borg', '--version'))
- flexmock(module.environment).should_receive('make_environment')
- assert module.local_borg_version({}) == VERSION
- def test_local_borg_version_with_log_info_calls_borg_with_info_parameter():
- insert_execute_command_and_capture_output_mock(('borg', '--version', '--info'))
- insert_logging_mock(logging.INFO)
- flexmock(module.environment).should_receive('make_environment')
- assert module.local_borg_version({}) == VERSION
- def test_local_borg_version_with_log_debug_calls_borg_with_debug_parameters():
- insert_execute_command_and_capture_output_mock(('borg', '--version', '--debug', '--show-rc'))
- insert_logging_mock(logging.DEBUG)
- flexmock(module.environment).should_receive('make_environment')
- assert module.local_borg_version({}) == VERSION
- def test_local_borg_version_with_local_borg_path_calls_borg_with_it():
- insert_execute_command_and_capture_output_mock(('borg1', '--version'), borg_local_path='borg1')
- flexmock(module.environment).should_receive('make_environment')
- assert module.local_borg_version({}, 'borg1') == VERSION
- def test_local_borg_version_with_borg_exit_codes_calls_using_with_them():
- borg_exit_codes = flexmock()
- insert_execute_command_and_capture_output_mock(
- ('borg', '--version'), borg_exit_codes=borg_exit_codes
- )
- flexmock(module.environment).should_receive('make_environment')
- assert module.local_borg_version({'borg_exit_codes': borg_exit_codes}) == VERSION
- def test_local_borg_version_with_invalid_version_raises():
- insert_execute_command_and_capture_output_mock(('borg', '--version'), version_output='wtf')
- flexmock(module.environment).should_receive('make_environment')
- with pytest.raises(ValueError):
- module.local_borg_version({})
|