Skip to content

Commit

Permalink
More robusts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pslacerda committed May 18, 2024
1 parent 598bd54 commit 401f9f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions modules/pymol/commanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,13 @@ def inner(*args, **kwargs):
elif funcs[arg] == List[float]:
funcs[arg] = _parse_list_float
else:
raise NotImplemented(f"{funcs[arg]} argument is not supported.")
# Assumi it's a literal supported type
pass
# Convert the argument to the correct type
kwargs[arg] = funcs[arg](kwargs[arg])
return function(**kwargs)

# It was called by Python, so pass the arguments as is
# It was called from Python, so pass the arguments as is
else:
return function(*args, **kwargs)

Expand Down
8 changes: 6 additions & 2 deletions testing/tests/api/commanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ def func(a: int, b: Path):
cmd.do('func 1, /tmp')


def test_declare_command_default():
def test_declare_command_default(capsys):
from pymol.commanding import Selection
@cmd.declare_command
def func(a: Selection = "sele"):
assert a == "a"
func("a")
cmd.do("func a")
out, err = capsys.readouterr()
assert out == ''

def test_declare_command_docstring():
@cmd.declare_command
Expand All @@ -214,12 +216,14 @@ def func():
assert func.__doc__ == "docstring\nTest:\n --foo"


def test_declare_command_type_return():
def test_declare_command_type_return(capsys):
@cmd.declare_command
def func() -> int:
return 1

assert func() == 1
out, err = capsys.readouterr()
assert out == ''

@cmd.declare_command
def func():
Expand Down

0 comments on commit 401f9f4

Please sign in to comment.