Skip to content

Commit a0ee90c

Browse files
committed
cover docstring parser standard info = -i cases
1 parent 11a80eb commit a0ee90c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

slycot/tests/test_exceptions.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,55 @@ def test_unhandled_info_iwarn():
9393
assert wm[1].message.info == 0
9494

9595

96+
def test_info_standard_i():
97+
"""Test the handling of standard "`info = -i`
98+
99+
Raises
100+
------
101+
SlycotError
102+
:info = -i: Non-standard msg, info is {info}, -i is -{i}
103+
"""
104+
# No i in check_vars: keep silent
105+
raise_if_slycot_error(-1, docstring=test_info_standard_i.__doc__,
106+
checkvars={'a': 1})
107+
# -i does not match
108+
raise_if_slycot_error(-1, docstring=test_info_standard_i.__doc__,
109+
checkvars={'i': 2})
110+
# -i matches, raise the error
111+
with pytest.raises(SlycotError) as ex_info:
112+
raise_if_slycot_error(-1, docstring=test_info_standard_i.__doc__,
113+
checkvars={'i': 1})
114+
assert str(ex_info.value) == "\nNon-standard msg, info is -1, -i is -1"
115+
116+
117+
def test_infospec_nameerror():
118+
"""Test infospec with unknown variable.
119+
120+
Raises
121+
------
122+
SlycotError
123+
:info = v: We do not know {v}
124+
"""
125+
with pytest.raises(RuntimeError) as ex_info:
126+
raise_if_slycot_error(-1, docstring=test_infospec_nameerror.__doc__,
127+
checkvars={'a': 1})
128+
assert str(ex_info.value) == "Unknown variable in infospec: info = v"
129+
130+
131+
def test_infospec_syntaxerror():
132+
"""Test invalid infospec.
133+
134+
Raises
135+
------
136+
SlycotError
137+
:info i: Invalid expression
138+
"""
139+
with pytest.raises(RuntimeError) as ex_info:
140+
raise_if_slycot_error(-1, docstring=test_infospec_syntaxerror.__doc__,
141+
checkvars={'i': 1})
142+
assert str(ex_info.value) == "Invalid infospec: info i"
143+
144+
96145
# Test code for test_xerbla_override
97146
CODE = """
98147
import sys

0 commit comments

Comments
 (0)