9
9
"""
10
10
11
11
import re
12
+ import warnings
12
13
13
14
import numpy as np
14
15
import pytest
17
18
from control import iosys as ios
18
19
from control .tests .conftest import matrixfilter
19
20
21
+
20
22
class TestIOSys :
21
23
22
24
@pytest .fixture
@@ -1416,11 +1418,10 @@ def test_duplicates(self, tsys):
1416
1418
nlios2 = ios .NonlinearIOSystem (None ,
1417
1419
lambda t , x , u , params : u * u ,
1418
1420
inputs = 1 , outputs = 1 , name = "nlios2" )
1419
- with pytest .warns (None ) as record :
1421
+ with warnings .catch_warnings ():
1422
+ warnings .simplefilter ("error" )
1420
1423
ct .InterconnectedSystem ([nlios1 , iosys_siso , nlios2 ],
1421
1424
inputs = 0 , outputs = 0 , states = 0 )
1422
- if record :
1423
- pytest .fail ("Warning not expected: " + record [0 ].message )
1424
1425
1425
1426
1426
1427
def test_linear_interconnection ():
@@ -1510,7 +1511,7 @@ def predprey(t, x, u, params={}):
1510
1511
1511
1512
def pvtol (t , x , u , params = {}):
1512
1513
"""Reduced planar vertical takeoff and landing dynamics"""
1513
- from math import sin , cos
1514
+ from math import cos , sin
1514
1515
m = params .get ('m' , 4. ) # kg, system mass
1515
1516
J = params .get ('J' , 0.0475 ) # kg m^2, system inertia
1516
1517
r = params .get ('r' , 0.25 ) # m, thrust offset
@@ -1526,7 +1527,7 @@ def pvtol(t, x, u, params={}):
1526
1527
1527
1528
1528
1529
def pvtol_full (t , x , u , params = {}):
1529
- from math import sin , cos
1530
+ from math import cos , sin
1530
1531
m = params .get ('m' , 4. ) # kg, system mass
1531
1532
J = params .get ('J' , 0.0475 ) # kg m^2, system inertia
1532
1533
r = params .get ('r' , 0.25 ) # m, thrust offset
@@ -1579,8 +1580,12 @@ def test_interconnect_unused_input():
1579
1580
inputs = ['r' ],
1580
1581
outputs = ['y' ])
1581
1582
1582
- with pytest . warns ( None ) as record :
1583
+ with warnings . catch_warnings () :
1583
1584
# 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 )
1584
1589
h = ct .interconnect ([g ,s ,k ],
1585
1590
inputs = ['r' ],
1586
1591
outputs = ['y' ],
@@ -1595,14 +1600,6 @@ def test_interconnect_unused_input():
1595
1600
h = ct .interconnect ([g ,s ,k ],
1596
1601
connections = False )
1597
1602
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
-
1606
1603
1607
1604
# warn if explicity ignored input in fact used
1608
1605
with pytest .warns (
@@ -1657,7 +1654,11 @@ def test_interconnect_unused_output():
1657
1654
1658
1655
1659
1656
# 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 )
1661
1662
h = ct .interconnect ([g ,s ,k ],
1662
1663
inputs = ['r' ],
1663
1664
outputs = ['y' ],
@@ -1672,14 +1673,6 @@ def test_interconnect_unused_output():
1672
1673
h = ct .interconnect ([g ,s ,k ],
1673
1674
connections = False )
1674
1675
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
-
1683
1676
# warn if explicity ignored output in fact used
1684
1677
with pytest .warns (
1685
1678
UserWarning ,
0 commit comments