8000 use editdefaults fixture and matrixfilter mark for unit testing · python-control/python-control@488edf5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 488edf5

Browse files
committed
use editdefaults fixture and matrixfilter mark for unit testing
1 parent e767986 commit 488edf5

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

control/tests/iosys_test.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import control as ct
1818
from control import iosys as ios
19-
from control.tests.conftest import noscipy0
19+
from control.tests.conftest import noscipy0, matrixfilter
2020

2121
class TestIOSys:
2222

@@ -204,6 +204,8 @@ def test_linearize(self, tsys, kincar):
204204
linearized.C, [[1, 0, 0], [0, 1, 0]])
205205
np.testing.assert_array_almost_equal(linearized.D, np.zeros((2,2)))
206206

207+
@pytest.mark.usefixtures("editsdefaults")
208+
@matrixfilter # avoid np.matrix warnings in v0.8.4
207209
def test_linearize_named_signals(self, kincar):
208210
# Full form of the call
209211
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True,
@@ -217,17 +219,14 @@ def test_linearize_named_signals(self, kincar):
217219
assert linearized.find_state('y') == 1
218220
assert linearized.find_state('theta') == 2
219221

220-
# If we copy signal names w/out a system name, append '_linearized'
221-
ct.use_legacy_defaults('0.8.4')
222-
ct.config.use_numpy_matrix(False) # get rid of warning messages
222+
# If we copy signal names w/out a system name, append '$linearized'
223223
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True)
224-
assert linearized.name == kincar.name + '_linearized'
224+
assert linearized.name == kincar.name + '$linearized'
225225

226-
ct.reset_defaults()
227-
ct.use_legacy_defaults('0.9.0')
226+
# Test legacy version as well
227+
ct.use_legacy_defaults('0.8.4')
228228
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True)
229-
assert linearized.name == kincar.name + '$linearized'
230-
ct.reset_defaults()
229+
assert linearized.name == kincar.name + '_linearized'
231230

232231
# If copy is False, signal names should not be copied
233232
lin_nocopy = kincar.linearize(0, 0, copy=False)
@@ -954,12 +953,13 @@ def test_named_signals(self, tsys):
954953
np.testing.assert_array_almost_equal(ss_feedback.C, lin_feedback.C)
955954
np.testing.assert_array_almost_equal(ss_feedback.D, lin_feedback.D)
956955

956+
@pytest.mark.usefixtures("editsdefaults")
957+
@matrixfilter # avoid np.matrix warnings in v0.8.4
957958
def test_sys_naming_convention(self, tsys):
958959
"""Enforce generic system names 'sys[i]' to be present when systems are
959960
created without explicit names."""
960961

961962
ct.config.use_legacy_defaults('0.8.4') # changed delims in 0.9.0
962-
ct.config.use_numpy_matrix(False) # get rid of warning messages
963963
ct.InputOutputSystem.idCounter = 0
964964
sys = ct.LinearIOSystem(tsys.mimo_linsys1)
965965

@@ -1013,8 +1013,8 @@ def test_sys_naming_convention(self, tsys):
10131013
with pytest.warns(UserWarning):
10141014
unnamedsys1 * unnamedsys1
10151015

1016-
ct.config.reset_defaults() # reset defaults
1017-
1016+
@pytest.mark.usefixtures("editsdefaults")
1017+
@matrixfilter # avoid np.matrix warnings in v0.8.4
10181018
def test_signals_naming_convention_0_8_4(self, tsys):
10191019
"""Enforce generic names to be present when systems are created
10201020
without explicit signal names:
@@ -1024,7 +1024,6 @@ def test_signals_naming_convention_0_8_4(self, tsys):
10241024
"""
10251025

10261026
ct.config.use_legacy_defaults('0.8.4') # changed delims in 0.9.0
1027-
ct.config.use_numpy_matrix(False) # get rid of warning messages
10281027
ct.InputOutputSystem.idCounter = 0
10291028
sys = ct.LinearIOSystem(tsys.mimo_linsys1)
10301029
for statename in ["x[0]", "x[1]"]:
@@ -1077,8 +1076,6 @@ def test_signals_naming_convention_0_8_4(self, tsys):
10771076
assert "sys[1].x[0]" in same_name_series.state_index
10781077
assert "copy of sys[1].x[0]" in same_name_series.state_index
10791078

1080-
ct.config.reset_defaults() # reset defaults
1081-
10821079
def test_named_signals_linearize_inconsistent(self, tsys):
10831080
"""Mare sure that providing inputs or outputs not consistent with
10841081
updfcn or outfcn fail
@@ -1218,6 +1215,8 @@ def test_docstring_example(self):
12181215
np.testing.assert_array_almost_equal(io_S.C, ss_S.C)
12191216
np.testing.assert_array_almost_equal(io_S.D, ss_S.D)
12201217

1218+
@pytest.mark.usefixtures("editsdefaults")
1219+
@matrixfilter # avoid np.matrix warnings in v0.8.4
12211220
def test_duplicates(self, tsys):
12221221
nlios = ios.NonlinearIOSystem(lambda t, x, u, params: x,
12231222
lambda t, x, u, params: u * u,
@@ -1236,7 +1235,6 @@ def test_duplicates(self, tsys):
12361235
ios_series = nlios1 * nlios2
12371236
assert "copy of sys_1.x[0]" in ios_series.state_index.keys()
12381237
assert "copy of sys.x[0]" in ios_series.state_index.keys()
1239-
ct.config.reset_defaults() # reset defaults
12401238

12411239
# Duplicate names
12421240
iosys_siso = ct.LinearIOSystem(tsys.siso_linsys)

0 commit comments

Comments
 (0)
0