Skip to content

Commit 7f883f6

Browse files
committed
1 parent 0cd3ac8 commit 7f883f6

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

control/tests/iosys_test.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import re
12+
import warnings
1213

1314
import numpy as np
1415
import pytest
@@ -17,6 +18,7 @@
1718
from control import iosys as ios
1819
from control.tests.conftest import matrixfilter
1920

21+
2022
class 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

14261427
def test_linear_interconnection():
@@ -1510,7 +1511,7 @@ def predprey(t, x, u, params={}):
15101511

15111512
def 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

15281529
def 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,

control/tests/namedio_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import re
1212
from copy import copy
13+
import warnings
1314

1415
import numpy as np
1516
import control as ct
@@ -243,9 +244,12 @@ def test_duplicate_sysname():
243244
sys = ct.rss(4, 1, 1)
244245

245246
# No warnings should be generated if we reuse an an unnamed system
246-
with pytest.warns(None) as record:
247+
with warnings.catch_warnings():
248+
warnings.simplefilter("error")
249+
# strip out matrix warnings
250+
warnings.filterwarnings("ignore", "the matrix subclass",
251+
category=PendingDeprecationWarning)
247252
res = sys * sys
248-
assert not any([type(msg) == UserWarning for msg in record])
249253

250254
# Generate a warning if the system is named
251255
sys = ct.rss(4, 1, 1, name='sys')

control/tests/nyquist_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
99
"""
1010

11+
import warnings
12+
1113
import pytest
1214
import numpy as np
1315
import matplotlib.pyplot as plt
@@ -225,10 +227,11 @@ def test_nyquist_encirclements():
225227
sys = 1 / (s**2 + s + 1)
226228
with pytest.warns(UserWarning, match="encirclements was a non-integer"):
227229
count = ct.nyquist_plot(sys, omega_limits=[0.5, 1e3])
228-
with pytest.warns(None) as records:
230+
with warnings.catch_warnings():
231+
warnings.simplefilter("error")
232+
# strip out matrix warnings
229233
count = ct.nyquist_plot(
230234
sys, omega_limits=[0.5, 1e3], encirclement_threshold=0.2)
231-
assert len(records) == 0
232235
plt.title("Non-integer number of encirclements [%g]" % count)
233236

234237

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy