99"""
1010
1111import re
12+ import warnings
1213
1314import numpy as np
1415import pytest
1718from control import iosys as ios
1819from control .tests .conftest import matrixfilter
1920
21+
2022class TestIOSys :
2123
2224 @pytest .fixture
@@ -1416,11 +1418,10 @@ def test_duplicates(self, tsys):
14161418 nlios2 = ios .NonlinearIOSystem (None ,
14171419 lambda t , x , u , params : u * u ,
14181420 inputs = 1 , outputs = 1 , name = "nlios2" )
1419- with pytest .warns (None ) as record :
1421+ with warnings .catch_warnings ():
1422+ warnings .simplefilter ("error" )
14201423 ct .InterconnectedSystem ([nlios1 , iosys_siso , nlios2 ],
14211424 inputs = 0 , outputs = 0 , states = 0 )
1422- if record :
1423- pytest .fail ("Warning not expected: " + record [0 ].message )
14241425
14251426
14261427def test_linear_interconnection ():
@@ -1510,7 +1511,7 @@ def predprey(t, x, u, params={}):
15101511
15111512def pvtol (t , x , u , params = {}):
15121513 """Reduced planar vertical takeoff and landing dynamics"""
1513- from math import sin , cos
1514+ from math import cos , sin
15141515 m = params .get ('m' , 4. ) # kg, system mass
15151516 J = params .get ('J' , 0.0475 ) # kg m^2, system inertia
15161517 r = params .get ('r' , 0.25 ) # m, thrust offset
@@ -1526,7 +1527,7 @@ def pvtol(t, x, u, params={}):
15261527
15271528
15281529def pvtol_full (t , x , u , params = {}):
1529- from math import sin , cos
1530+ from math import cos , sin
15301531 m = params .get ('m' , 4. ) # kg, system mass
15311532 J = params .get ('J' , 0.0475 ) # kg m^2, system inertia
15321533 r = params .get ('r' , 0.25 ) # m, thrust offset
@@ -1579,8 +1580,12 @@ def test_interconnect_unused_input():
15791580 inputs = ['r' ],
15801581 outputs = ['y' ])
15811582
1582- with pytest . warns ( None ) as record :
1583+ with warnings . catch_warnings () :
15831584 # no warning if output explicitly ignored, various argument forms
1585+ warnings .simplefilter ("error" )
1586+ # strip out matrix warnings
1587+ warnings .filterwarnings ("ignore" , "the matrix subclass" ,
1588+ category = PendingDeprecationWarning )
15841589 h = ct .interconnect ([g ,s ,k ],
15851590 inputs = ['r' ],
15861591 outputs = ['y' ],
@@ -1595,14 +1600,6 @@ def test_interconnect_unused_input():
15951600 h = ct .interconnect ([g ,s ,k ],
15961601 connections = False )
15971602
1598- #https://docs.pytest.org/en/6.2.x/warnings.html#recwarn
1599- for r in record :
1600- # strip out matrix warnings
1601- if re .match (r'.*matrix subclass' , str (r .message )):
1602- continue
1603- print (r .message )
1604- pytest .fail (f'Unexpected warning: { r .message } ' )
1605-
16061603
16071604 # warn if explicity ignored input in fact used
16081605 with pytest .warns (
@@ -1657,7 +1654,11 @@ def test_interconnect_unused_output():
16571654
16581655
16591656 # no warning if output explicitly ignored
1660- with pytest .warns (None ) as record :
1657+ with warnings .catch_warnings ():
1658+ warnings .simplefilter ("error" )
1659+ # strip out matrix warnings
1660+ warnings .filterwarnings ("ignore" , "the matrix subclass" ,
1661+ category = PendingDeprecationWarning )
16611662 h = ct .interconnect ([g ,s ,k ],
16621663 inputs = ['r' ],
16631664 outputs = ['y' ],
@@ -1672,14 +1673,6 @@ def test_interconnect_unused_output():
16721673 h = ct .interconnect ([g ,s ,k ],
16731674 connections = False )
16741675
1675- #https://docs.pytest.org/en/6.2.x/warnings.html#recwarn
1676- for r in record :
1677- # strip out matrix warnings
1678- if re .match (r'.*matrix subclass' , str (r .message )):
1679- continue
1680- print (r .message )
1681- pytest .fail (f'Unexpected warning: { r .message } ' )
1682-
16831676 # warn if explicity ignored output in fact used
16841677 with pytest .warns (
16851678 UserWarning ,
0 commit comments