generated from BrianPugh/python-template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parameter2cli to also populate values for POSITIONAL_ONLY, VAR_KE…
…YWORD, and VAR_POSITIONAL.
- Loading branch information
Showing
2 changed files
with
66 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import inspect | ||
|
||
from typing_extensions import Annotated | ||
|
||
from cyclopts.bind import parameter2cli | ||
from cyclopts.parameter import Parameter | ||
|
||
|
||
def test_parameter2cli_positional_or_keyword(): | ||
def foo(a: Annotated[int, Parameter(negative=())]): | ||
pass | ||
|
||
a_iparam = list(inspect.signature(foo).parameters.values())[0] | ||
actual = parameter2cli(foo) | ||
assert actual == {a_iparam: ["--a"]} | ||
|
||
|
||
def test_parameter2cli_positional_only(): | ||
def foo(a: Annotated[int, Parameter(negative=())], /): | ||
pass | ||
|
||
a_iparam = list(inspect.signature(foo).parameters.values())[0] | ||
actual = parameter2cli(foo) | ||
assert actual == {a_iparam: ["A"]} | ||
|
||
|
||
def test_parameter2cli_keyword_only(): | ||
def foo(*, a: Annotated[int, Parameter(negative=())]): | ||
pass | ||
|
||
a_iparam = list(inspect.signature(foo).parameters.values())[0] | ||
actual = parameter2cli(foo) | ||
assert actual == {a_iparam: ["--a"]} | ||
|
||
|
||
def test_parameter2cli_var_keyword(): | ||
def foo(**a: Annotated[int, Parameter(negative=())]): | ||
pass | ||
|
||
a_iparam = list(inspect.signature(foo).parameters.values())[0] | ||
actual = parameter2cli(foo) | ||
assert actual == {a_iparam: ["--a"]} | ||
|
||
|
||
def test_parameter2cli_var_positional(): | ||
def foo(*a: Annotated[int, Parameter(negative=())]): | ||
pass | ||
|
||
a_iparam = list(inspect.signature(foo).parameters.values())[0] | ||
actual = parameter2cli(foo) | ||
assert actual == {a_iparam: ["A"]} |