Skip to content

Commit 50caf2b

Browse files
committed
make tests work with current source code state
revert this commit when merging into/with python-control#431 (remove statesp_test.py::test_copy_constructor_nodt if not applicable)
1 parent efcd483 commit 50caf2b

File tree

4 files changed

+27
-166
lines changed

4 files changed

+27
-166
lines changed

control/tests/discrete_test.py

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import numpy as np
77
import pytest
88

9-
from control import (StateSpace, TransferFunction, bode, common_timebase,
10-
evalfr, feedback, forced_response, impulse_response,
11-
isctime, isdtime, rss, sample_system, step_response,
12-
timebase)
9+
from control import StateSpace, TransferFunction, feedback, step_response, \
10+
isdtime, timebase, isctime, sample_system, bode, impulse_response, \
11+
evalfr, timebaseEqual, forced_response, rss
1312

1413

1514
class TestDiscrete:
@@ -52,21 +51,13 @@ class Tsys:
5251

5352
return T
5453

55-
def testCompatibleTimebases(self, tsys):
56-
"""test that compatible timebases don't throw errors and vice versa"""
57-
common_timebase(tsys.siso_ss1.dt, tsys.siso_tf1.dt)
58-
common_timebase(tsys.siso_ss1.dt, tsys.siso_ss1c.dt)
59-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss1.dt)
60-
common_timebase(tsys.siso_ss1.dt, tsys.siso_ss1d.dt)
61-
common_timebase(tsys.siso_ss1.dt, tsys.siso_ss1d.dt)
62-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss3d.dt)
63-
common_timebase(tsys.siso_ss3d.dt, tsys.siso_ss1d.dt)
64-
with pytest.raises(ValueError):
65-
# cont + discrete
66-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss1c.dt)
67-
with pytest.raises(ValueError):
68-
# incompatible discrete
69-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss2d.dt)
54+
def testTimebaseEqual(self, tsys):
55+
"""Test for equal timebases and not so equal ones"""
56+
assert timebaseEqual(tsys.siso_ss1, tsys.siso_tf1)
57+
assert timebaseEqual(tsys.siso_ss1, tsys.siso_ss1c)
58+
assert not timebaseEqual(tsys.siso_ss1d, tsys.siso_ss1c)
59+
assert not timebaseEqual(tsys.siso_ss1d, tsys.siso_ss2d)
60+
assert not timebaseEqual(tsys.siso_ss1d, tsys.siso_ss3d)
7061

7162
def testSystemInitialization(self, tsys):
7263
# Check to make sure systems are discrete time with proper variables
@@ -84,18 +75,6 @@ def testSystemInitialization(self, tsys):
8475
assert tsys.siso_tf2d.dt == 0.2
8576
assert tsys.siso_tf3d.dt is True
8677

87-
# keyword argument check
88-
# dynamic systems
89-
assert TransferFunction(1, [1, 1], dt=0.1).dt == 0.1
90-
assert TransferFunction(1, [1, 1], 0.1).dt == 0.1
91-
assert StateSpace(1,1,1,1, dt=0.1).dt == 0.1
92-
assert StateSpace(1,1,1,1, 0.1).dt == 0.1
93-
# static gain system, dt argument should still override default dt
94-
assert TransferFunction(1, [1,], dt=0.1).dt == 0.1
95-
assert TransferFunction(1, [1,], 0.1).dt == 0.1
96-
assert StateSpace(0,0,1,1, dt=0.1).dt == 0.1
97-
assert StateSpace(0,0,1,1, 0.1).dt == 0.1
98-
9978
def testCopyConstructor(self, tsys):
10079
for sys in (tsys.siso_ss1, tsys.siso_ss1c, tsys.siso_ss1d):
10180
newsys = StateSpace(sys)
@@ -135,7 +114,6 @@ def test_timebase_conversions(self, tsys):
135114
assert timebase(tf1*tf2) == timebase(tf2)
136115
assert timebase(tf1*tf3) == timebase(tf3)
137116
assert timebase(tf1*tf4) == timebase(tf4)
138-
assert timebase(tf3*tf4) == timebase(tf4)
139117
assert timebase(tf2*tf1) == timebase(tf2)
140118
assert timebase(tf3*tf1) == timebase(tf3)
141119
assert timebase(tf4*tf1) == timebase(tf4)
@@ -150,36 +128,33 @@ def test_timebase_conversions(self, tsys):
150128

151129
# Make sure discrete time without sampling is converted correctly
152130
assert timebase(tf3*tf3) == timebase(tf3)
153-
assert timebase(tf3*tf4) == timebase(tf4)
154131
assert timebase(tf3+tf3) == timebase(tf3)
155-
assert timebase(tf3+tf4) == timebase(tf4)
156132
assert timebase(feedback(tf3, tf3)) == timebase(tf3)
157-
assert timebase(feedback(tf3, tf4)) == timebase(tf4)
158133

159134
# Make sure all other combinations are errors
160-
with pytest.raises(ValueError, match="incompatible timebases"):
135+
with pytest.raises(ValueError, match="different sampling times"):
161136
tf2 * tf3
162-
with pytest.raises(ValueError, match="incompatible timebases"):
137+
with pytest.raises(ValueError, match="different sampling times"):
163138
tf3 * tf2
164-
with pytest.raises(ValueError, match="incompatible timebases"):
139+
with pytest.raises(ValueError, match="different sampling times"):
165140
tf2 * tf4
166-
with pytest.raises(ValueError, match="incompatible timebases"):
141+
with pytest.raises(ValueError, match="different sampling times"):
167142
tf4 * tf2
168-
with pytest.raises(ValueError, match="incompatible timebases"):
143+
with pytest.raises(ValueError, match="different sampling times"):
169144
tf2 + tf3
170-
with pytest.raises(ValueError, match="incompatible timebases"):
145+
with pytest.raises(ValueError, match="different sampling times"):
171146
tf3 + tf2
172-
with pytest.raises(ValueError, match="incompatible timebases"):
147+
with pytest.raises(ValueError, match="different sampling times"):
173148
tf2 + tf4
174-
with pytest.raises(ValueError, match="incompatible timebases"):
149+
with pytest.raises(ValueError, match="different sampling times"):
175150
tf4 + tf2
176-
with pytest.raises(ValueError, match="incompatible timebases"):
151+
with pytest.raises(ValueError, match="different sampling times"):
177152
feedback(tf2, tf3)
178-
with pytest.raises(ValueError, match="incompatible timebases"):
153+
with pytest.raises(ValueError, match="different sampling times"):
179154
feedback(tf3, tf2)
180-
with pytest.raises(ValueError, match="incompatible timebases"):
155+
with pytest.raises(ValueError, match="different sampling times"):
181156
feedback(tf2, tf4)
182-
with pytest.raises(ValueError, match="incompatible timebases"):
157+
with pytest.raises(ValueError, match="different sampling times"):
183158
feedback(tf4, tf2)
184159

185160
def testisdtime(self, tsys):
@@ -237,7 +212,6 @@ def testAddition(self, tsys):
237212
sys = tsys.siso_ss1c + tsys.siso_ss1c
238213
sys = tsys.siso_ss1d + tsys.siso_ss1d
239214
sys = tsys.siso_ss3d + tsys.siso_ss3d
240-
sys = tsys.siso_ss1d + tsys.siso_ss3d
241215

242216
with pytest.raises(ValueError):
243217
StateSpace.__add__(tsys.mimo_ss1c, tsys.mimo_ss1d)
@@ -252,7 +226,6 @@ def testAddition(self, tsys):
252226
sys = tsys.siso_tf1c + tsys.siso_tf1c
253227
sys = tsys.siso_tf1d + tsys.siso_tf1d
254228
sys = tsys.siso_tf2d + tsys.siso_tf2d
255-
sys = tsys.siso_tf1d + tsys.siso_tf3d
256229

257230
with pytest.raises(ValueError):
258231
TransferFunction.__add__(tsys.siso_tf1c, tsys.siso_tf1d)
@@ -275,7 +248,6 @@ def testMultiplication(self, tsys):
275248
sys = tsys.siso_ss1d * tsys.siso_ss1
276249
sys = tsys.siso_ss1c * tsys.siso_ss1c
277250
sys = tsys.siso_ss1d * tsys.siso_ss1d
278-
sys = tsys.siso_ss1d * tsys.siso_ss3d
279251

280252
with pytest.raises(ValueError):
281253
StateSpace.__mul__(tsys.mimo_ss1c, tsys.mimo_ss1d)
@@ -289,7 +261,6 @@ def testMultiplication(self, tsys):
289261
sys = tsys.siso_tf1d * tsys.siso_tf1
290262
sys = tsys.siso_tf1c * tsys.siso_tf1c
291263
sys = tsys.siso_tf1d * tsys.siso_tf1d
292-
sys = tsys.siso_tf1d * tsys.siso_tf3d
293264

294265
with pytest.raises(ValueError):
295266
TransferFunction.__mul__(tsys.siso_tf1c, tsys.siso_tf1d)
@@ -314,7 +285,6 @@ def testFeedback(self, tsys):
314285
sys = feedback(tsys.siso_ss1d, tsys.siso_ss1)
315286
sys = feedback(tsys.siso_ss1c, tsys.siso_ss1c)
316287
sys = feedback(tsys.siso_ss1d, tsys.siso_ss1d)
317-
sys = feedback(tsys.siso_ss1d, tsys.siso_ss3d)
318288

319289
with pytest.raises(ValueError):
320290
feedback(tsys.mimo_ss1c, tsys.mimo_ss1d)
@@ -328,7 +298,6 @@ def testFeedback(self, tsys):
328298
sys = feedback(tsys.siso_tf1d, tsys.siso_tf1)
329299
sys = feedback(tsys.siso_tf1c, tsys.siso_tf1c)
330300
sys = feedback(tsys.siso_tf1d, tsys.siso_tf1d)
331-
sys = feedback(tsys.siso_tf1d, tsys.siso_tf3d)
332301

333302
with pytest.raises(ValueError):
334303
feedback(tsys.siso_tf1c, tsys.siso_tf1d)

control/tests/lti_test.py

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from control import c2d, tf, tf2ss, NonlinearIOSystem
7-
from control.lti import (LTI, common_timebase, damp, dcgain, isctime, isdtime,
7+
from control.lti import (LTI, damp, dcgain, isctime, isdtime,
88
issiso, pole, timebaseEqual, zero)
99
from control.tests.conftest import slycotonly
1010

@@ -72,84 +72,3 @@ def test_dcgain(self):
7272
sys = tf(84, [1, 2])
7373
np.testing.assert_equal(sys.dcgain(), 42)
7474
np.testing.assert_equal(dcgain(sys), 42)
75-
76-
@pytest.mark.parametrize("dt1, dt2, expected",
77-
[(None, None, True),
78-
(None, 0, True),
79-
(None, 1, True),
80-
pytest.param(None, True, True,
81-
marks=pytest.mark.xfail(
82-
reason="returns false")),
83-
(0, 0, True),
84-
(0, 1, False),
85-
(0, True, False),
86-
(1, 1, True),
87-
(1, 2, False),
88-
(1, True, False),
89-
(True, True, True)])
90-
def test_timebaseEqual_deprecated(self, dt1, dt2, expected):
91-
"""Test that timbaseEqual throws a warning and returns as documented"""
92-
sys1 = tf([1], [1, 2, 3], dt1)
93-
sys2 = tf([1], [1, 4, 5], dt2)
94-
95-
print(sys1.dt)
96-
print(sys2.dt)
97-
98-
with pytest.deprecated_call():
99-
assert timebaseEqual(sys1, sys2) is expected
100-
# Make sure behaviour is symmetric
101-
with pytest.deprecated_call():
102-
assert timebaseEqual(sys2, sys1) is expected
103-
104-
@pytest.mark.parametrize("dt1, dt2, expected",
105-
[(None, None, None),
106-
(None, 0, 0),
107-
(None, 1, 1),
108-
(None, True, True),
109-
(True, True, True),
110-
(True, 1, 1),
111-
(1, 1, 1),
112-
(0, 0, 0),
113-
])
114-
@pytest.mark.parametrize("sys1", [True, False])
115-
@pytest.mark.parametrize("sys2", [True, False])
116-
def test_common_timebase(self, dt1, dt2, expected, sys1, sys2):
117-
"""Test that common_timbase adheres to :ref:`conventions-ref`"""
118-
i1 = tf([1], [1, 2, 3], dt1) if sys1 else dt1
119-
i2 = tf([1], [1, 4, 5], dt2) if sys2 else dt2
120-
assert common_timebase(i1, i2) == expected
121-
# Make sure behaviour is symmetric
122-
assert common_timebase(i2, i1) == expected
123-
124-
@pytest.mark.parametrize("i1, i2",
125-
[(True, 0),
126-
(0, 1),
127-
(1, 2)])
128-
def test_common_timebase_errors(self, i1, i2):
129-
"""Test that common_timbase throws errors on invalid combinations"""
130-
with pytest.raises(ValueError):
131-
common_timebase(i1, i2)
132-
# Make sure behaviour is symmetric
133-
with pytest.raises(ValueError):
134-
common_timebase(i2, i1)
135-
136-
@pytest.mark.parametrize("dt, ref, strictref",
137-
[(None, True, False),
138-
(0, False, False),
139-
(1, True, True),
140-
(True, True, True)])
141-
@pytest.mark.parametrize("objfun, arg",
142-
[(LTI, ()),
143-
(NonlinearIOSystem, (lambda x: x, ))])
144-
def test_isdtime(self, objfun, arg, dt, ref, strictref):
145-
"""Test isdtime and isctime functions to follow convention"""
146-
obj = objfun(*arg, dt=dt)
147-
148-
assert isdtime(obj) == ref
149-
assert isdtime(obj, strict=True) == strictref
150-
151-
if dt is not None:
152-
ref = not ref
153-
strictref = not strictref
154-
assert isctime(obj) == ref
155-
assert isctime(obj, strict=True) == strictref

control/tests/statesp_test.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,13 @@ def sys623(self):
8080

8181
@pytest.mark.parametrize(
8282
"dt",
83-
[(), (None, ), (0, ), (1, ), (0.1, ), (True, )],
83+
[(None, ), (0, ), (1, ), (0.1, ), (True, )],
8484
ids=lambda i: "dt " + ("unspec" if len(i) == 0 else str(i[0])))
8585
@pytest.mark.parametrize(
8686
"argfun",
8787
[pytest.param(
8888
lambda ABCDdt: (ABCDdt, {}),
8989
id="A, B, C, D[, dt]"),
90-
pytest.param(
91-
lambda ABCDdt: (ABCDdt[:4], {'dt': dt_ for dt_ in ABCDdt[4:]}),
92-
id="A, B, C, D[, dt=dt]"),
9390
pytest.param(
9491
lambda ABCDdt: ((StateSpace(*ABCDdt), ), {}),
9592
id="sys")
@@ -109,7 +106,7 @@ def test_constructor(self, sys322ABCD, dt, argfun):
109106
@pytest.mark.parametrize("args, exc, errmsg",
110107
[((True, ), TypeError,
111108
"(can only take in|sys must be) a StateSpace"),
112-
((1, 2), ValueError, "1, 4, or 5 arguments"),
109+
((1, 2), ValueError, "1 or 4 arguments"),
113110
((np.ones((3, 2)), np.ones((3, 2)),
114111
np.ones((2, 2)), np.ones((2, 2))),
115112
ValueError, "A must be square"),
@@ -133,16 +130,6 @@ def test_constructor_invalid(self, args, exc, errmsg):
133130
with pytest.raises(exc, match=errmsg):
134131
ss(*args)
135132

136-
def test_constructor_warns(self, sys322ABCD):
137-
"""Test ambiguos input to StateSpace() constructor"""
138-
with pytest.warns(UserWarning, match="received multiple dt"):
139-
sys = StateSpace(*(sys322ABCD + (0.1, )), dt=0.2)
140-
np.testing.assert_almost_equal(sys.A, sys322ABCD[0])
141-
np.testing.assert_almost_equal(sys.B, sys322ABCD[1])
142-
np.testing.assert_almost_equal(sys.C, sys322ABCD[2])
143-
np.testing.assert_almost_equal(sys.D, sys322ABCD[3])
144-
assert sys.dt == 0.1
145-
146133
def test_copy_constructor(self):
147134
"""Test the copy constructor"""
148135
# Create a set of matrices for a simple linear system
@@ -164,22 +151,6 @@ def test_copy_constructor(self):
164151
linsys.A[0, 0] = -3
165152
np.testing.assert_array_equal(cpysys.A, [[-1]]) # original value
166153

167-
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-
"""
172-
sysin = sample_system(sys322, 1.)
173-
del sysin.dt
174-
sys = StateSpace(sysin)
175-
assert sys.dt == defaults['control.default_dt']
176-
177-
# test for static gain
178-
sysin = StateSpace([], [], [], [[1, 2], [3, 4]], 1.)
179-
del sysin.dt
180-
sys = StateSpace(sysin)
181-
assert sys.dt is None
182-
183154
def test_matlab_style_constructor(self):
184155
"""Use (deprecated) matrix-style construction string"""
185156
with pytest.deprecated_call():
@@ -382,6 +353,7 @@ def test_freq_resp(self):
382353
np.testing.assert_almost_equal(phase, true_phase)
383354
np.testing.assert_equal(omega, true_omega)
384355

356+
@pytest.mark.skip("is_static_gain is introduced in gh-431")
385357
def test_is_static_gain(self):
386358
A0 = np.zeros((2,2))
387359
A1 = A0.copy()

control/tests/xferfcn_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def test_evalfr_siso(self, dt, omega, resp):
409409
resp,
410410
atol=1e-3)
411411

412+
@pytest.mark.skip("is_static_gain is introduced in gh-431")
412413
def test_is_static_gain(self):
413414
numstatic = 1.1
414415
denstatic = 1.2

0 commit comments

Comments
 (0)