Skip to content

Commit a259980

Browse files
committed
Better test coverage.
1 parent fdc5e1d commit a259980

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

testing/tests/api/test_commanding.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
def test_docstring():
1111
@cmd.new_command
1212
def func():
13-
"""docstring"""
14-
assert func.__doc__ == "docstring"
13+
"""
14+
docstring
15+
a
16+
"""
17+
assert func.__doc__ == "docstring\na"
1518

1619

1720
def test_bool(capsys):
1821
@cmd.new_command
1922
def func(a: bool, b: bool):
20-
assert a
23+
assert a is True
2124
assert not b
2225
cmd.do("func yes, 0")
2326
out, err = capsys.readouterr()
24-
assert out == '' and err == ''
27+
assert out + err == ''
2528

2629

2730
def test_generic(capsys):
@@ -152,4 +155,32 @@ def func(quiet: bool=True):
152155

153156
def test_argument_error():
154157
err = ArgumentParsingError('my_var', "Short error message.")
155-
assert str(err) == "Failed at parsing 'my_var'. Short error message."
158+
assert str(err) == "Failed at parsing 'my_var'. Short error message."
159+
160+
def test_call_error(capsys):
161+
@cmd.new_command
162+
def func(
163+
my_var: Union[int, float] = 10,
164+
my_foo: int | float = 10.0,
165+
null_ptr: Optional[bool] = None,
166+
extended_calculation: bool = True,
167+
old_style: Any = "Old behavior"
168+
):
169+
assert extended_calculation
170+
assert isinstance(my_var, int)
171+
assert isinstance(my_foo, float)
172+
assert null_ptr is None
173+
assert old_style == "Old behavior"
174+
175+
cmd.do("func my_foo=a")
176+
out, err = capsys.readouterr()
177+
assert "Failed at parsing 'my_foo'." in (out + err)
178+
179+
cmd.do("func extended_calculation=a")
180+
out, err = capsys.readouterr()
181+
assert (
182+
"Failed at parsing 'extended_calculation'."
183+
" Can't parse 'a' as bool."
184+
" Supported true values are yes, 1, true, on, y."
185+
" Supported false values are no, 0, false, off, n."
186+
) in (out + err)

0 commit comments

Comments
 (0)