Changeset - 5231a1784f87
[Not reviewed]
0 2 0
Brett Smith - 3 years ago 2021-02-24 18:15:33
brettcsmith@brettcsmith.org
cliutil: EnumArgument matches user arguments against aliases.
2 files changed with 13 insertions and 7 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/cliutil.py
Show inline comments
...
 
@@ -96,3 +96,7 @@ class EnumArgument(Generic[ET]):
 
        regexp = re.compile(re.escape(arg), re.IGNORECASE)
 
        matches = frozenset(choice for choice in self.base if regexp.match(choice.name))
 
        matches = frozenset(
 
            choice
 
            for name, choice in self.base.__members__.items()
 
            if regexp.match(name)
 
        )
 
        count = len(matches)
tests/test_cliutil.py
Show inline comments
...
 
@@ -34,2 +34,4 @@ class ArgChoices(enum.Enum):
 
    BB = 'bb'
 
    START = AA
 
    END = BB
 

	
...
 
@@ -272,5 +274,5 @@ def test_can_run(cmd, expected):
 

	
 
@pytest.mark.parametrize('choice', ArgChoices)
 
def test_enum_arg_enum_type(arg_enum, choice):
 
    assert arg_enum.enum_type(choice.name) is choice
 
@pytest.mark.parametrize('name,choice', ArgChoices.__members__.items())
 
def test_enum_arg_enum_type(arg_enum, name, choice):
 
    assert arg_enum.enum_type(name.lower()) is choice
 
    assert arg_enum.enum_type(choice.value) is choice
...
 
@@ -282,5 +284,5 @@ def test_enum_arg_no_enum_match(arg_enum, arg):
 

	
 
@pytest.mark.parametrize('choice', ArgChoices)
 
def test_enum_arg_value_type(arg_enum, choice):
 
    assert arg_enum.value_type(choice.name) == choice.value
 
@pytest.mark.parametrize('name,choice', ArgChoices.__members__.items())
 
def test_enum_arg_value_type(arg_enum, name, choice):
 
    assert arg_enum.value_type(name.lower()) == choice.value
 
    assert arg_enum.value_type(choice.value) == choice.value
0 comments (0 inline, 0 general)