fix the error thrown, unit test for it, and add string explanations
This commit is contained in:
parent
77dbb5c499
commit
aa564ac5fe
2 changed files with 23 additions and 14 deletions
|
@ -136,7 +136,7 @@ def exact_options_completion(action: Action):
|
||||||
if has_unknown_required_param_options(action):
|
if has_unknown_required_param_options(action):
|
||||||
return f'''\ncomplete -c borgmatic -x -n "__borgmatic_last_arg {args}"'''
|
return f'''\ncomplete -c borgmatic -x -n "__borgmatic_last_arg {args}"'''
|
||||||
|
|
||||||
raise RuntimeError(
|
raise ValueError(
|
||||||
f'Unexpected action: {action} passes has_exact_options but has no choices produced'
|
f'Unexpected action: {action} passes has_exact_options but has no choices produced'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from typing import Tuple
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from borgmatic.commands.completion import (
|
from borgmatic.commands.completion import (
|
||||||
|
exact_options_completion,
|
||||||
has_choice_options,
|
has_choice_options,
|
||||||
has_exact_options,
|
has_exact_options,
|
||||||
has_file_options,
|
has_file_options,
|
||||||
|
@ -89,32 +90,40 @@ test_data: list[TestCase] = [
|
||||||
|
|
||||||
@pytest.mark.parametrize('action, option_type', test_data)
|
@pytest.mark.parametrize('action, option_type', test_data)
|
||||||
def test_has_file_options_detects_file_options(action: Action, option_type: OptionType):
|
def test_has_file_options_detects_file_options(action: Action, option_type: OptionType):
|
||||||
assert has_file_options(action) == option_type.file
|
assert (
|
||||||
# if has_file_options(action) was true, has_exact_options(action) should also be true
|
has_file_options(action) == option_type.file
|
||||||
if option_type.file:
|
), f'Action: {action} should be file={option_type.file}'
|
||||||
assert has_exact_options(action)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('action, option_type', test_data)
|
@pytest.mark.parametrize('action, option_type', test_data)
|
||||||
def test_has_choice_options_detects_choice_options(action: Action, option_type: OptionType):
|
def test_has_choice_options_detects_choice_options(action: Action, option_type: OptionType):
|
||||||
assert has_choice_options(action) == option_type.choice
|
assert (
|
||||||
# if has_choice_options(action) was true, has_exact_options(action) should also be true
|
has_choice_options(action) == option_type.choice
|
||||||
if option_type.choice:
|
), f'Action: {action} should be choice={option_type.choice}'
|
||||||
assert has_exact_options(action)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('action, option_type', test_data)
|
@pytest.mark.parametrize('action, option_type', test_data)
|
||||||
def test_has_unknown_required_param_options_detects_unknown_required_param_options(
|
def test_has_unknown_required_param_options_detects_unknown_required_param_options(
|
||||||
action: Action, option_type: OptionType
|
action: Action, option_type: OptionType
|
||||||
):
|
):
|
||||||
assert has_unknown_required_param_options(action) == option_type.unknown_required
|
assert (
|
||||||
# if has_unknown_required_param_options(action) was true, has_exact_options(action) should also be true
|
has_unknown_required_param_options(action) == option_type.unknown_required
|
||||||
if option_type.unknown_required:
|
), f'Action: {action} should be unknown_required={option_type.unknown_required}'
|
||||||
assert has_exact_options(action)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('action, option_type', test_data)
|
@pytest.mark.parametrize('action, option_type', test_data)
|
||||||
def test_has_exact_options_detects_exact_options(action: Action, option_type: OptionType):
|
def test_has_exact_options_detects_exact_options(action: Action, option_type: OptionType):
|
||||||
assert has_exact_options(action) == (
|
assert has_exact_options(action) == (
|
||||||
option_type.file or option_type.choice or option_type.unknown_required
|
option_type.file or option_type.choice or option_type.unknown_required
|
||||||
)
|
), f'Action: {action} should have exact options given {option_type}'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('action, option_type', test_data)
|
||||||
|
def test_produce_exact_options_completion(action: Action, option_type: OptionType):
|
||||||
|
try:
|
||||||
|
completion = exact_options_completion(action)
|
||||||
|
assert (
|
||||||
|
type(completion) == str
|
||||||
|
), f'Completion should be a string, got {completion} of type {type(completion)}'
|
||||||
|
except ValueError as value_error:
|
||||||
|
assert False, f'exact_options_completion raised ValueError: {value_error}'
|
||||||
|
|
Loading…
Reference in a new issue