Skip to content

Commit 26303ff

Browse files
committed
move kwarg lists inside function to fix initialization issue
1 parent a86d33f commit 26303ff

1 file changed

Lines changed: 52 additions & 48 deletions

File tree

control/tests/kwargs_test.py

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -58,54 +58,58 @@ def test_kwarg_search(module, prefix):
5858
test_kwarg_search(obj, prefix + obj.__name__ + '.')
5959

6060

61-
# Create a SISO system for use in parameterized tests
62-
sys = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
63-
64-
65-
# Parameterized tests for looking for unrecognized keyword errors
66-
@pytest.mark.parametrize("function, args, kwargs", [
67-
[control.dlqr, (sys, [[1, 0], [0, 1]], [[1]]), {}],
68-
[control.drss, (2, 1, 1), {}],
69-
[control.input_output_response, (sys, [0, 1, 2], [1, 1, 1]), {}],
70-
[control.lqr, (sys, [[1, 0], [0, 1]], [[1]]), {}],
71-
[control.pzmap, (sys,), {}],
72-
[control.rlocus, (control.tf([1], [1, 1]), ), {}],
73-
[control.root_locus, (control.tf([1], [1, 1]), ), {}],
74-
[control.rss, (2, 1, 1), {}],
75-
[control.ss, (0, 0, 0, 0), {'dt': 1}],
76-
[control.ss2io, (sys,), {}],
77-
[control.summing_junction, (2,), {}],
78-
[control.tf, ([1], [1, 1]), {}],
79-
[control.tf2io, (control.tf([1], [1, 1]),), {}],
80-
[control.InputOutputSystem, (1, 1, 1), {}],
81-
[control.StateSpace, ([[-1, 0], [0, -1]], [[1], [1]], [[1, 1]], 0), {}],
82-
[control.TransferFunction, ([1], [1, 1]), {}],
83-
])
84-
def test_unrecognized_kwargs(function, args, kwargs):
85-
# Call the function normally and make sure it works
86-
function(*args, **kwargs)
87-
88-
# Now add an unrecognized keyword and make sure there is an error
89-
with pytest.raises(TypeError, match="unrecognized keyword"):
90-
function(*args, **kwargs, unknown=None)
91-
92-
93-
# Parameterized tests for looking for keyword errors handled by matplotlib
94-
@pytest.mark.parametrize("function, args, kwargs", [
95-
[control.bode, (sys, ), {}],
96-
[control.bode_plot, (sys, ), {}],
97-
[control.gangof4, (sys, sys), {}],
98-
[control.gangof4_plot, (sys, sys), {}],
99-
[control.nyquist, (sys, ), {}],
100-
[control.nyquist_plot, (sys, ), {}],
101-
])
102-
def test_matplotlib_kwargs(function, args, kwargs):
103-
# Call the function normally and make sure it works
104-
function(*args, **kwargs)
105-
106-
# Now add an unrecognized keyword and make sure there is an error
107-
with pytest.raises(AttributeError, match="has no property"):
108-
function(*args, **kwargs, unknown=None)
61+
def test_unrecognized_kwargs():
62+
# Create a SISO system for use in parameterized tests
63+
sys = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
64+
65+
table = [
66+
[control.dlqr, (sys, [[1, 0], [0, 1]], [[1]]), {}],
67+
[control.drss, (2, 1, 1), {}],
68+
[control.input_output_response, (sys, [0, 1, 2], [1, 1, 1]), {}],
69+
[control.lqr, (sys, [[1, 0], [0, 1]], [[1]]), {}],
70+
[control.pzmap, (sys,), {}],
71+
[control.rlocus, (control.tf([1], [1, 1]), ), {}],
72+
[control.root_locus, (control.tf([1], [1, 1]), ), {}],
73+
[control.rss, (2, 1, 1), {}],
74+
[control.ss, (0, 0, 0, 0), {'dt': 1}],
75+
[control.ss2io, (sys,), {}],
76+
[control.summing_junction, (2,), {}],
77+
[control.tf, ([1], [1, 1]), {}],
78+
[control.tf2io, (control.tf([1], [1, 1]),), {}],
79+
[control.InputOutputSystem, (1, 1, 1), {}],
80+
[control.StateSpace, ([[-1, 0], [0, -1]], [[1], [1]], [[1, 1]], 0), {}],
81+
[control.TransferFunction, ([1], [1, 1]), {}],
82+
]
83+
84+
for function, args, kwargs in table:
85+
# Call the function normally and make sure it works
86+
function(*args, **kwargs)
87+
88+
# Now add an unrecognized keyword and make sure there is an error
89+
with pytest.raises(TypeError, match="unrecognized keyword"):
90+
function(*args, **kwargs, unknown=None)
91+
92+
93+
def test_matplotlib_kwargs():
94+
# Create a SISO system for use in parameterized tests
95+
sys = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
96+
97+
table = [
98+
[control.bode, (sys, ), {}],
99+
[control.bode_plot, (sys, ), {}],
100+
[control.gangof4, (sys, sys), {}],
101+
[control.gangof4_plot, (sys, sys), {}],
102+
[control.nyquist, (sys, ), {}],
103+
[control.nyquist_plot, (sys, ), {}],
104+
]
105+
106+
for function, args, kwargs in table:
107+
# Call the function normally and make sure it works
108+
function(*args, **kwargs)
109+
110+
# Now add an unrecognized keyword and make sure there is an error
111+
with pytest.raises(AttributeError, match="has no property"):
112+
function(*args, **kwargs, unknown=None)
109113

110114

111115
#

0 commit comments

Comments
 (0)