-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dict_option() and dict_positional() helpers
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pytest | ||
|
||
from arcparse import arcparser, dict_option, dict_positional | ||
from arcparse.errors import InvalidArgument | ||
|
||
|
||
dict_ = { | ||
"foo": 1, | ||
"bar": 0, | ||
} | ||
|
||
|
||
def test_dict_positional_default_in_dict() -> None: | ||
with pytest.raises(InvalidArgument): | ||
dict_positional(dict_, default=2) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"arg_string,value", | ||
[ | ||
("foo", 1), | ||
("bar", 0), | ||
] | ||
) | ||
def test_dict_positional(arg_string: str, value: int) -> None: | ||
@arcparser | ||
class Args: | ||
foo_bar: int = dict_positional(dict_) | ||
|
||
parsed = Args.parse(arg_string.split()) | ||
assert parsed.foo_bar == value | ||
|
||
|
||
def test_dict_option_default_in_dict() -> None: | ||
with pytest.raises(InvalidArgument): | ||
dict_option(dict_, default=2) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"arg_string,value", | ||
[ | ||
("--foo-bar foo", 1), | ||
("--foo-bar bar", 0), | ||
] | ||
) | ||
def test_dict_option(arg_string: str, value: int) -> None: | ||
@arcparser | ||
class Args: | ||
foo_bar: int = dict_option(dict_) | ||
|
||
parsed = Args.parse(arg_string.split()) | ||
assert parsed.foo_bar == value |