2015-07-27 04:06:03 +00:00
|
|
|
import os
|
2014-12-20 19:37:25 +00:00
|
|
|
|
2015-07-27 04:06:03 +00:00
|
|
|
from flexmock import flexmock
|
2016-04-10 22:59:36 +00:00
|
|
|
import pytest
|
2014-12-20 19:37:25 +00:00
|
|
|
|
2017-07-09 05:33:51 +00:00
|
|
|
from borgmatic.commands import borgmatic as module
|
2015-07-19 01:35:29 +00:00
|
|
|
|
|
|
|
|
2014-12-20 19:37:25 +00:00
|
|
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
2018-07-25 01:34:05 +00:00
|
|
|
config_paths = ['default']
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
|
|
|
|
2016-06-10 18:21:53 +00:00
|
|
|
parser = module.parse_arguments()
|
2014-12-20 19:37:25 +00:00
|
|
|
|
2018-07-25 01:34:05 +00:00
|
|
|
assert parser.config_paths == config_paths
|
2017-07-10 23:25:13 +00:00
|
|
|
assert parser.excludes_filename == None
|
2017-07-10 16:43:25 +00:00
|
|
|
assert parser.verbosity is None
|
2018-07-28 21:21:38 +00:00
|
|
|
assert parser.json is False
|
2014-12-20 19:37:25 +00:00
|
|
|
|
|
|
|
|
2017-07-26 04:18:51 +00:00
|
|
|
def test_parse_arguments_with_path_arguments_overrides_defaults():
|
2018-07-25 01:34:05 +00:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2016-06-10 18:21:53 +00:00
|
|
|
parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
|
2014-12-20 19:37:25 +00:00
|
|
|
|
2017-07-26 04:18:51 +00:00
|
|
|
assert parser.config_paths == ['myconfig']
|
2014-12-20 19:37:25 +00:00
|
|
|
assert parser.excludes_filename == 'myexcludes'
|
2017-07-10 16:43:25 +00:00
|
|
|
assert parser.verbosity is None
|
2014-12-20 19:37:25 +00:00
|
|
|
|
|
|
|
|
2017-07-26 04:18:51 +00:00
|
|
|
def test_parse_arguments_with_multiple_config_paths_parses_as_list():
|
2018-07-25 01:34:05 +00:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2017-07-26 04:18:51 +00:00
|
|
|
parser = module.parse_arguments('--config', 'myconfig', 'otherconfig')
|
|
|
|
|
|
|
|
assert parser.config_paths == ['myconfig', 'otherconfig']
|
|
|
|
assert parser.verbosity is None
|
|
|
|
|
|
|
|
|
2015-07-18 04:58:50 +00:00
|
|
|
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
2018-07-25 01:34:05 +00:00
|
|
|
config_paths = ['default']
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
|
|
|
|
2016-06-10 18:21:53 +00:00
|
|
|
parser = module.parse_arguments('--verbosity', '1')
|
2014-12-20 19:37:25 +00:00
|
|
|
|
2018-07-25 01:34:05 +00:00
|
|
|
assert parser.config_paths == config_paths
|
2017-07-10 23:25:13 +00:00
|
|
|
assert parser.excludes_filename == None
|
2015-07-18 04:58:50 +00:00
|
|
|
assert parser.verbosity == 1
|
2014-12-20 19:37:25 +00:00
|
|
|
|
|
|
|
|
2018-07-28 21:21:38 +00:00
|
|
|
def test_parse_arguments_with_json_flag_overrides_default():
|
|
|
|
parser = module.parse_arguments('--list', '--json')
|
|
|
|
assert parser.json is True
|
|
|
|
|
|
|
|
|
2017-07-29 05:02:18 +00:00
|
|
|
def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled():
|
2018-07-25 01:34:05 +00:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2017-07-29 05:02:18 +00:00
|
|
|
parser = module.parse_arguments()
|
|
|
|
|
|
|
|
assert parser.prune is True
|
|
|
|
assert parser.create is True
|
|
|
|
assert parser.check is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_prune_action_leaves_other_actions_disabled():
|
2018-07-25 01:34:05 +00:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2017-07-29 05:02:18 +00:00
|
|
|
parser = module.parse_arguments('--prune')
|
|
|
|
|
|
|
|
assert parser.prune is True
|
|
|
|
assert parser.create is False
|
|
|
|
assert parser.check is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_multiple_actions_leaves_other_action_disabled():
|
2018-07-25 01:34:05 +00:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2017-07-29 05:02:18 +00:00
|
|
|
parser = module.parse_arguments('--create', '--check')
|
|
|
|
|
|
|
|
assert parser.prune is False
|
|
|
|
assert parser.create is True
|
|
|
|
assert parser.check is True
|
|
|
|
|
|
|
|
|
2014-12-20 19:37:25 +00:00
|
|
|
def test_parse_arguments_with_invalid_arguments_exits():
|
2018-07-25 01:34:05 +00:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2017-07-10 16:43:25 +00:00
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
module.parse_arguments('--posix-me-harder')
|
2018-07-28 21:21:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_json_flag_but_no_list_flag_raises_value_error():
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('--json')
|