Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Nov 3, 2023
1 parent e55a278 commit 8038c03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion cyclopts/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ def remaining_parameters():
if parameter.kind == parameter.VAR_POSITIONAL: # ``*args``
f_args.extend(_coerce_pos(parameter, x) for x in tokens)
break
elif parameter.kind in (parameter.POSITIONAL_ONLY, parameter.POSITIONAL_OR_KEYWORD):
elif parameter.kind == parameter.POSITIONAL_ONLY:
f_args.append(_coerce_pos(parameter, tokens.popleft()))
elif parameter.kind == parameter.POSITIONAL_OR_KEYWORD:
f_kwargs[parameter.name] = _coerce_pos(parameter, tokens.popleft())
else:
raise UnreachableError("Not expected to get here.")

Expand Down
28 changes: 16 additions & 12 deletions tests/bind/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@ def foo(a, b, c):
pass


def test_basic_1(app):
@pytest.mark.parametrize(
"cmd_str",
[
"foo 1 2 3",
"foo --a 1 --b 2 --c 3",
"foo --c 3 1 2",
"foo --c 3 --b=2 1",
"foo --c 3 --b=2 --a 1",
"foo 1 --b=2 3",
],
)
def test_basic_1(app, cmd_str):
@app.command
def foo(a: int, b: int, c: int):
pass

signature = inspect.signature(foo)
expected_bind = signature.bind(1, 2, 3)

def run(s):
actual_command, actual_bind, unused_args = app.parse_known_args(s)
assert actual_command == foo
assert actual_bind == expected_bind
assert unused_args == []

run("foo 1 2 3")
run("foo --a 1 --b 2 --c 3")
run("foo --c 3 1 2")
run("foo --c 3 --b=2 1")
run("foo --c 3 --b=2 --a 1")
actual_command, actual_bind, unused_args = app.parse_known_args(cmd_str)
assert actual_command == foo
assert actual_bind == expected_bind
assert unused_args == []

0 comments on commit 8038c03

Please sign in to comment.