Fix error parsing arguments with multiple verbosity flags (#716).
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-06-24 14:10:47 -07:00
parent e4e455ee45
commit 35a11559ac
7 changed files with 389 additions and 108 deletions

View File

@@ -3,18 +3,26 @@ from borgmatic.commands.completion import actions as module
def test_available_actions_uses_only_subactions_for_action_with_subactions():
unused_top_level_parser, subparsers = borgmatic.commands.arguments.make_parsers()
(
unused_global_parser,
action_parsers,
unused_combined_parser,
) = borgmatic.commands.arguments.make_parsers()
actions = module.available_actions(subparsers, 'config')
actions = module.available_actions(action_parsers, 'config')
assert 'bootstrap' in actions
assert 'list' not in actions
def test_available_actions_omits_subactions_for_action_without_subactions():
unused_top_level_parser, subparsers = borgmatic.commands.arguments.make_parsers()
(
unused_global_parser,
action_parsers,
unused_combined_parser,
) = borgmatic.commands.arguments.make_parsers()
actions = module.available_actions(subparsers, 'list')
actions = module.available_actions(action_parsers, 'list')
assert 'bootstrap' not in actions
assert 'config' in actions

View File

@@ -30,6 +30,17 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list():
assert global_arguments.log_file_verbosity == 0
def test_parse_arguments_with_action_after_config_path_omits_action():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
arguments = module.parse_arguments('--config', 'myconfig', 'list', '--json')
global_arguments = arguments['global']
assert global_arguments.config_paths == ['myconfig']
assert 'list' in arguments
assert arguments['list'].json
def test_parse_arguments_with_verbosity_overrides_default():
config_paths = ['default']
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
@@ -194,10 +205,10 @@ def test_parse_arguments_with_multiple_actions_leaves_other_action_disabled():
assert 'check' in arguments
def test_parse_arguments_with_invalid_arguments_exits():
def test_parse_arguments_disallows_invalid_argument():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--posix-me-harder')
@@ -211,7 +222,7 @@ def test_parse_arguments_disallows_deprecated_excludes_option():
def test_parse_arguments_disallows_encryption_mode_without_init():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--config', 'myconfig', '--encryption', 'repokey')
@@ -231,14 +242,14 @@ def test_parse_arguments_requires_encryption_mode_with_init():
def test_parse_arguments_disallows_append_only_without_init():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--config', 'myconfig', '--append-only')
def test_parse_arguments_disallows_storage_quota_without_init():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--config', 'myconfig', '--storage-quota', '5G')
@@ -287,14 +298,14 @@ def test_parse_arguments_allows_repository_with_list():
def test_parse_arguments_disallows_archive_unless_action_consumes_it():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--config', 'myconfig', '--archive', 'test')
def test_parse_arguments_disallows_paths_unless_action_consumes_it():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--config', 'myconfig', '--path', 'test')
@@ -380,7 +391,7 @@ def test_parse_arguments_allows_progress_and_extract():
def test_parse_arguments_disallows_progress_without_create():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--progress', 'list')
@@ -399,7 +410,7 @@ def test_parse_arguments_with_stats_and_prune_flags_does_not_raise():
def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_value_error():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit):
with pytest.raises(ValueError):
module.parse_arguments('--stats', 'list')
@@ -535,11 +546,9 @@ def test_parse_arguments_extract_with_check_only_extract_does_not_raise():
def test_parse_arguments_bootstrap_without_config_errors():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit) as exit:
with pytest.raises(ValueError):
module.parse_arguments('bootstrap')
assert exit.value.code == 2
def test_parse_arguments_config_with_no_subaction_errors():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])