Skip to content

Commit 1bf445b

Browse files
murrayrmbnavigator
authored andcommitted
add unit tests for freqresp/evalfr warnings/errors
1 parent 3b10af0 commit 1bf445b

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

control/frdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def __call__(self, s, squeeze=True):
421421
frequency values.
422422
"""
423423
if any(abs(np.array(s, ndmin=1).real) > 0):
424-
raise ValueError("__call__: FRD systems can only accept"
424+
raise ValueError("__call__: FRD systems can only accept "
425425
"purely imaginary frequencies")
426426
# need to preserve array or scalar status
427427
if hasattr(s, '__len__'):

control/tests/frd_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,15 @@ def test_eval(self):
405405
np.testing.assert_almost_equal(sys_tf(1j), frd_tf(1j))
406406

407407
# Should get an error if we evaluate at an unknown frequency
408-
with pytest.raises(ValueError):
408+
with pytest.raises(ValueError, match="not .* in frequency list"):
409409
frd_tf.eval(2)
410410

411+
# Should get an error if we evaluate at an complex number
412+
with pytest.raises(ValueError, match="can only accept real-valued"):
413+
frd_tf.eval(2 + 1j)
414+
411415
# Should get an error if we use __call__ at real-valued frequency
412-
with pytest.raises(ValueError):
416+
with pytest.raises(ValueError, match="only accept purely imaginary"):
413417
frd_tf(2)
414418

415419
def test_repr_str(self):

control/tests/statesp_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ def test_freq_resp(self):
376376
np.testing.assert_almost_equal(phase, true_phase)
377377
np.testing.assert_equal(omega, true_omega)
378378

379+
# Deprecated version of the call (should return warning)
380+
with pytest.warns(DeprecationWarning, match="will be removed"):
381+
from control import freqresp
382+
mag, phase, omega = sys.freqresp(true_omega)
383+
np.testing.assert_almost_equal(mag, true_mag)
384+
379385
def test_is_static_gain(self):
380386
A0 = np.zeros((2,2))
381387
A1 = A0.copy()

0 commit comments

Comments
 (0)