8000 update tests for dt=0, fix the constructor checks for missing dt · python-control/python-control@404b23c · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 404b23c

Browse files
committed
update tests for dt=0, fix the constructor checks for missing dt
1 parent e3a0070 commit 404b23c

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

control/statesp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def __init__(self, *args, **kwargs):
244244
elif len(args) == 1:
245245
try:
246246
dt = args[0].dt
247-
except NameError:
247+
except AttributeError:
248248
if self.is_static_gain():
249249
dt = None
250250
else:

control/tests/discrete_test.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ def testAddition(self, tsys):
243243
StateSpace.__add__(tsys.mimo_ss1c, tsys.mimo_ss1d)
244244
with pytest.raises(ValueError):
245245
StateSpace.__add__(tsys.mimo_ss1d, tsys.mimo_ss2d)
246-
with pytest.raises(ValueError):
247-
StateSpace.__add__(tsys.siso_ss1d, tsys.siso_ss3d)
248246

249247
# Transfer function addition
250248
sys = tsys.siso_tf1 + tsys.siso_tf1d
@@ -260,8 +258,6 @@ def testAddition(self, tsys):
260258
TransferFunction.__add__(tsys.siso_tf1c, tsys.siso_tf1d)
261259
with pytest.raises(ValueError):
262260
TransferFunction.__add__(tsys.siso_tf1d, tsys.siso_tf2d)
263-
with pytest.raises(ValueError):
264-
TransferFunction.__add__(tsys.siso_tf1d, tsys.siso_tf3d)
265261

266262
# State space + transfer function
267263
sys = tsys.siso_ss1c + tsys.siso_tf1c
@@ -285,8 +281,6 @@ def testMultiplication(self, tsys):
285281
StateSpace.__mul__(tsys.mimo_ss1c, tsys.mimo_ss1d)
286282
with pytest.raises(ValueError):
287283
StateSpace.__mul__(tsys.mimo_ss1d, tsys.mimo_ss2d)
288-
with pytest.raises(ValueError):
289-
StateSpace.__mul__(tsys.siso_ss1d, tsys.siso_ss3d)
290284

291285
# Transfer function multiplication
292286
sys = tsys.siso_tf1 * tsys.siso_tf1d
@@ -301,8 +295,6 @@ def testMultiplication(self, tsys):
301295
TransferFunction.__mul__(tsys.siso_tf1c, tsys.siso_tf1d)
302296
with pytest.raises(ValueError):
303297
TransferFunction.__mul__(tsys.siso_tf1d, tsys.siso_tf2d)
304-
with pytest.raises(ValueError):
305-
TransferFunction.__mul__(tsys.siso_tf1d, tsys.siso_tf3d)
306298

307299
# State space * transfer function
308300
sys = tsys.siso_ss1c * tsys.siso_tf1c
@@ -328,8 +320,6 @@ def testFeedback(self, tsys):
328320
feedback(tsys.mimo_ss1c, tsys.mimo_ss1d)
329321
with pytest.raises(ValueError):
330322
feedback(tsys.mimo_ss1d, tsys.mimo_ss2d)
331-
with pytest.raises(ValueError):
332-
feedback(tsys.siso_ss1d, tsys.siso_ss3d)
333323

334324
# Transfer function feedback
335325
sys = feedback(tsys.siso_tf1, tsys.siso_tf1d)
@@ -344,8 +334,6 @@ def testFeedback(self, tsys):
344334
feedback(tsys.siso_tf1c, tsys.siso_tf1d)
345335
with pytest.raises(ValueError):
346336
feedback(tsys.siso_tf1d, tsys.siso_tf2d)
347-
with pytest.raises(ValueError):
348-
feedback(tsys.siso_tf1d, tsys.siso_tf3d)
349337

350338
# State space, transfer function
351339
sys = feedback(tsys.siso_ss1c, tsys.siso_tf1c)

control/tests/iosys_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def test_duplicates(self, tsys):
10241024
# Nonduplicate objects
10251025
nlios1 = nlios.copy()
10261026
nlios2 = nlios.copy()
1027-
with pytest.warns(UserWarning, match="copy of sys") as record:
1027+
with pytest.warns(UserWarning, match="Duplicate name"):
10281028
ios_series = nlios1 * nlios2
10291029
assert "copy of sys_1.x[0]" in ios_series.state_index.keys()
10301030
assert "copy of sys.x[0]" in ios_series.state_index.keys()

control/tests/statesp_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ def test_copy_constructor(self):
165165
np.testing.assert_array_equal(cpysys.A, [[-1]]) # original value
166166

167167
def test_copy_constructor_nodt(self, sys322):
168-
"""Test the copy constructor when an object without dt is passed
169-
170-
FIXME: may be obsolete in case gh-431 is updated
171-
"""
168+
"""Test the copy constructor when an object without dt is passed"""
172169
sysin = sample_system(sys322, 1.)
173170
del sysin.dt
174171
sys = StateSpace(sysin)

control/tests/xferfcn_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from control.tests.conftest import slycotonly, nopython2, matrixfilter
1414
from control.lti import isctime, isdtime
1515
from control.dtime import sample_system
16+
from control.config import defaults
1617

1718

1819
class TestXferFcn:
@@ -85,6 +86,21 @@ def test_constructor_zero_denominator(self):
8586
TransferFunction([[[1.], [2., 3.]], [[-1., 4.], [3., 2.]]],
8687
[[[1., 0.], [0.]], [[0., 0.], [2.]]])
8788

89+
def test_constructor_nodt(self):
90+
"""Test the constructor when an object without dt is passed"""
91+
sysin = TransferFunction([[[0., 1.], [2., 3.]]],
92+
[[[5., 2.], [3., 0.]]])
93+
del sysin.dt
94+
sys = TransferFunction(sysin)
95+
assert sys.dt == defaults['control.default_dt']
96+
97+
# test for static gain
98+
sysin = TransferFunction([[[2.], [3.]]],
99+
[[[1.], [.1]]])
100+
del sysin.dt
101+
sys = TransferFunction(sysin)
102+
assert sys.dt is None
103+
88104
def test_add_inconsistent_dimension(self):
89105
"""Add two transfer function matrices of different sizes."""
90106
sys1 = TransferFunction([[[1., 2.]]], [[[4., 5.]]])

control/xferfcn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def __init__(self, *args, **kwargs):
223223
# TODO: not sure this can ever happen since dt is always present
224224
try:
225225
dt = args[0].dt
226-
except NameError: # pragma: no coverage
226+
except AttributeError:
227227
if self.is_static_gain():
228228
dt = None
229229
else:

0 commit comments

Comments
 (0)
0