Skip to content

Commit f758725

Browse files
authored
Merge pull request #777 from bnavigator/fix-776
Allow new matplotlib 3.6 error message in kwargs tests
2 parents 0e2e89b + 1cf3ec7 commit f758725

File tree

2 files changed

+72
-80
lines changed

2 files changed

+72
-80
lines changed

control/tests/kwargs_test.py

+65-70
Original file line numberDiff line numberDiff line change
@@ -75,79 +75,74 @@ def test_kwarg_search(module, prefix):
7575
test_kwarg_search(obj, prefix + obj.__name__ + '.')
7676

7777

78-
@pytest.mark.usefixtures('editsdefaults')
79-
def test_unrecognized_kwargs():
78+
@pytest.mark.parametrize(
79+
"function, nsssys, ntfsys, moreargs, kwargs",
80+
[(control.dlqe, 1, 0, ([[1]], [[1]]), {}),
81+
(control.dlqr, 1, 0, ([[1, 0], [0, 1]], [[1]]), {}),
82+
(control.drss, 0, 0, (2, 1, 1), {}),
83+
(control.input_output_response, 1, 0, ([0, 1, 2], [1, 1, 1]), {}),
84+
(control.lqe, 1, 0, ([[1]], [[1]]), {}),
85+
(control.lqr, 1, 0, ([[1, 0], [0, 1]], [[1]]), {}),
86+
(control.linearize, 1, 0, (0, 0), {}),
87+
(control.pzmap, 1, 0, (), {}),
88+
(control.rlocus, 0, 1, ( ), {}),
89+
(control.root_locus, 0, 1, ( ), {}),
90+
(control.rss, 0, 0, (2, 1, 1), {}),
91+
(control.set_defaults, 0, 0, ('control',), {'default_dt': True}),
92+
(control.ss, 0, 0, (0, 0, 0, 0), {'dt': 1}),
93+
(control.ss2io, 1, 0, (), {}),
94+
(control.ss2tf, 1, 0, (), {}),
95+
(control.summing_junction, 0, 0, (2,), {}),
96+
(control.tf, 0, 0, ([1], [1, 1]), {}),
97+
(control.tf2io, 0, 1, (), {}),
98+
(control.tf2ss, 0, 1, (), {}),
99+
(control.InputOutputSystem, 0, 0, (),
100+
{'inputs': 1, 'outputs': 1, 'states': 1}),
101+
(control.InputOutputSystem.linearize, 1, 0, (0, 0), {}),
102+
(control.StateSpace, 0, 0, ([[-1, 0], [0, -1]], [[1], [1]], [[1, 1]], 0), {}),
103+
(control.TransferFunction, 0, 0, ([1], [1, 1]), {})]
104+
)
105+
def test_unrecognized_kwargs(function, nsssys, ntfsys, moreargs, kwargs,
106+
mplcleanup, editsdefaults):
107+
# Create SISO systems for use in parameterized tests
108+
sssys = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
109+
tfsys = control.tf([1], [1, 1])
110+
111+
args = (sssys, )*nsssys + (tfsys, )*ntfsys + moreargs
112+
113+
# Call the function normally and make sure it works
114+
function(*args, **kwargs)
115+
116+
# Now add an unrecognized keyword and make sure there is an error
117+
with pytest.raises(TypeError, match="unrecognized keyword"):
118+
function(*args, **kwargs, unknown=None)
119+
120+
121+
@pytest.mark.parametrize(
122+
"function, nsysargs, moreargs, kwargs",
123+
[(control.bode, 1, (), {}),
124+
(control.bode_plot, 1, (), {}),
125+
(control.describing_function_plot, 1,
126+
(control.descfcn.saturation_nonlinearity(1), [1, 2, 3, 4]), {}),
127+
(control.gangof4, 2, (), {}),
128+
(control.gangof4_plot, 2, (), {}),
129+
(control.nyquist, 1, (), {}),
130+
(control.nyquist_plot, 1, (), {}),
131+
(control.singular_values_plot, 1, (), {})]
132+
)
133+
def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
80134
# Create a SISO system for use in parameterized tests
81135
sys = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
82136

83-
table = [
84-
[control.dlqe, (sys, [[1]], [[1]]), {}],
85-
[control.dlqr, (sys, [[1, 0], [0, 1]], [[1]]), {}],
86-
[control.drss, (2, 1, 1), {}],
87-
[control.input_output_response, (sys, [0, 1, 2], [1, 1, 1]), {}],
88-
[control.lqe, (sys, [[1]], [[1]]), {}],
89-
[control.lqr, (sys, [[1, 0], [0, 1]], [[1]]), {}],
90-
[control.linearize, (sys, 0, 0), {}],
91-
[control.pzmap, (sys,), {}],
92-
[control.rlocus, (control.tf([1], [1, 1]), ), {}],
93-
[control.root_locus, (control.tf([1], [1, 1]), ), {}],
94-
[control.rss, (2, 1, 1), {}],
95-
[control.set_defaults, ('control',), {'default_dt': True}],
96-
[control.ss, (0, 0, 0, 0), {'dt': 1}],
97-
[control.ss2io, (sys,), {}],
98-
[control.ss2tf, (sys,), {}],
99-
[control.summing_junction, (2,), {}],
100-
[control.tf, ([1], [1, 1]), {}],
101-
[control.tf2io, (control.tf([1], [1, 1]),), {}],
102-
[control.tf2ss, (control.tf([1], [1, 1]),), {}],
103-
[control.InputOutputSystem, (),
104-
{'inputs': 1, 'outputs': 1, 'states': 1}],
105-
[control.InputOutputSystem.linearize, (sys, 0, 0), {}],
106-
[control.StateSpace, ([[-1, 0], [0, -1]], [[1], [1]], [[1, 1]], 0), {}],
107-
[control.TransferFunction, ([1], [1, 1]), {}],
108-
]
109-
110-
for function, args, kwargs in table:
111-
# Call the function normally and make sure it works
112-
function(*args, **kwargs)
113-
114-
# Now add an unrecognized keyword and make sure there is an error
115-
with pytest.raises(TypeError, match="unrecognized keyword"):
116-
function(*args, **kwargs, unknown=None)
117-
118-
# If we opened any figures, close them to avoid matplotlib warnings
119-
if plt.gca():
120-
plt.close('all')
121-
122-
123-
def test_matplotlib_kwargs():
124-
# Create a SISO system for use in parameterized tests
125-
sys = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
126-
ctl = control.ss([[-1, 1], [0, -1]], [[0], [1]], [[1, 0]], 0, dt=None)
127-
128-
table = [
129-
[control.bode, (sys, ), {}],
130-
[control.bode_plot, (sys, ), {}],
131-
[control.describing_function_plot,
132-
(sys, control.descfcn.saturation_nonlinearity(1), [1, 2, 3, 4]), {}],
133-
[control.gangof4, (sys, ctl), {}],
134-
[control.gangof4_plot, (sys, ctl), {}],
135-
[control.nyquist, (sys, ), {}],
136-
[control.nyquist_plot, (sys, ), {}],
137-
[control.singular_values_plot, (sys, ), {}],
138-
]
139-
140-
for function, args, kwargs in table:
141-
# Call the function normally and make sure it works
142-
function(*args, **kwargs)
143-
144-
# Now add an unrecognized keyword and make sure there is an error
145-
with pytest.raises(AttributeError, match="has no property"):
146-
function(*args, **kwargs, unknown=None)
147-
148-
# If we opened any figures, close them to avoid matplotlib warnings
149-
if plt.gca():
150-
plt.close('all')
137+
# Call the function normally and make sure it works
138+
args = (sys, )*nsysargs + moreargs
139+
function(*args, **kwargs)
140+
141+
# Now add an unrecognized keyword and make sure there is an error
142+
with pytest.raises(AttributeError,
143+
match="(has no property|unexpected keyword)"):
144+
function(*args, **kwargs, unknown=None)
145+
151146

152147

153148
#

control/tests/passivity_test.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Author: Mark Yeatman
2+
Author: Mark Yeatman
33
Date: May 30, 2022
44
'''
55
import pytest
@@ -99,20 +99,17 @@ def test_system_dimension():
9999

100100

101101
@pytest.mark.parametrize(
102-
"test_input,expected",
102+
"systemmatrices, expected",
103103
[((A, B, C, D*0.0), True),
104104
((A_d, B, C, D), True),
105-
((A*1e12, B, C, D*0), True),
105+
pytest.param((A*1e12, B, C, D*0), True,
106+
marks=pytest.mark.xfail(reason="gh-761")),
106107
((A, B*0, C*0, D), True),
107108
((A*0, B, C, D), True),
108109
((A*0, B*0, C*0, D*0), True)])
109-
def test_ispassive_edge_cases(test_input, expected):
110-
A = test_input[0]
111-
B = test_input[1]
112-
C = test_input[2]
113-
D = test_input[3]
114-
sys = ss(A, B, C, D)
115-
assert(passivity.ispassive(sys) == expected)
110+
def test_ispassive_edge_cases(systemmatrices, expected):
111+
sys = ss(*systemmatrices)
112+
assert passivity.ispassive(sys) == expected
116113

117114

118115
def test_rho_and_nu_are_none():

0 commit comments

Comments
 (0)