9
9
"""
10
10
11
11
import re
12
+ import warnings
12
13
13
14
import numpy as np
14
15
import pytest
15
16
16
17
import control as ct
17
18
from control import iosys as ios
18
- from control .tests .conftest import noscipy0 , matrixfilter
19
+ from control .tests .conftest import matrixfilter
20
+
19
21
20
22
class TestIOSys :
21
23
@@ -46,7 +48,6 @@ class TSys:
46
48
47
49
return T
48
50
49
- @noscipy0
50
51
def test_linear_iosys (self , tsys ):
51
52
# Create an input/output system from the linear system
52
53
linsys = tsys .siso_linsys
@@ -65,7 +66,6 @@ def test_linear_iosys(self, tsys):
65
66
np .testing .assert_array_almost_equal (lti_t , ios_t )
66
67
np .testing .assert_allclose (lti_y , ios_y , atol = 0.002 , rtol = 0. )
67
68
68
- @noscipy0
69
69
def test_tf2io (self , tsys ):
70
70
# Create a transfer function from the state space system
71
71
linsys = tsys .siso_linsys
@@ -129,7 +129,6 @@ def test_iosys_print(self, tsys, capsys):
129
129
ios_linearized = ios .linearize (ios_unspecified , [0 , 0 ], [0 ])
130
130
print (ios_linearized )
131
131
132
- @noscipy0
133
132
@pytest .mark .parametrize ("ss" , [ios .NonlinearIOSystem , ct .ss ])
134
133
def test_nonlinear_iosys (self , tsys , ss ):
135
134
# Create a simple nonlinear I/O system
@@ -236,7 +235,6 @@ def test_linearize_named_signals(self, kincar):
236
235
assert lin_nocopy .find_output ('x' ) is None
237
236
assert lin_nocopy .find_state ('x' ) is None
238
237
239
- @noscipy0
240
238
def test_connect (self , tsys ):
241
239
# Define a couple of (linear) systems to interconnection
242
240
linsys1 = tsys .siso_linsys
@@ -294,7 +292,6 @@ def test_connect(self, tsys):
294
292
np .testing .assert_array_almost_equal (lti_t , ios_t )
295
293
np .testing .assert_allclose (lti_y , ios_y ,atol = 0.002 ,rtol = 0. )
296
294
297
- @noscipy0
298
295
@pytest .mark .parametrize (
299
296
"connections, inplist, outlist" ,
300
297
[pytest .param ([[(1 , 0 ), (0 , 0 , 1 )]], [[(0 , 0 , 1 )]], [[(1 , 0 , 1 )]],
@@ -338,7 +335,6 @@ def test_connect_spec_variants(self, tsys, connections, inplist, outlist):
338
335
np .testing .assert_array_almost_equal (lti_t , ios_t )
339
336
np .testing .assert_allclose (lti_y , ios_y , atol = 0.002 , rtol = 0. )
340
337
341
- @noscipy0
342
338
@pytest .mark .parametrize (
343
339
"connections, inplist, outlist" ,
344
340
[pytest .param ([['sys2.u[0]' , 'sys1.y[0]' ]],
@@ -375,7 +371,6 @@ def test_connect_spec_warnings(self, tsys, connections, inplist, outlist):
375
371
np .testing .assert_array_almost_equal (lti_t , ios_t )
376
372
np .testing .assert_allclose (lti_y , ios_y , atol = 0.002 , rtol = 0. )
377
373
378
- @noscipy0
379
374
def test_static_nonlinearity (self , tsys ):
380
375
# Linear dynamical system
381
376
linsys = tsys .siso_linsys
@@ -400,7 +395,6 @@ def test_static_nonlinearity(self, tsys):
400
395
np .testing .assert_array_almost_equal (lti_y , ios_y , decimal = 2 )
401
396
402
397
403
- @noscipy0
404
398
@pytest .mark .filterwarnings ("ignore:Duplicate name::control.iosys" )
405
399
def test_algebraic_loop (self , tsys ):
406
400
# Create some linear and nonlinear systems to play with
@@ -470,7 +464,6 @@ def test_algebraic_loop(self, tsys):
470
464
with pytest .raises (RuntimeError ):
471
465
ios .input_output_response (* args )
472
466
473
- @noscipy0
474
467
def test_summer (self , tsys ):
475
468
# Construct a MIMO system for testing
476
469
linsys = tsys .mimo_linsys1
@@ -489,7 +482,6 @@ def test_summer(self, tsys):
489
482
ios_t , ios_y = ios .input_output_response (iosys_parallel , T , U , X0 )
490
483
np .testing .assert_allclose (ios_y , lin_y ,atol = 0.002 ,rtol = 0. )
491
484
492
- @noscipy0
493
485
def test_rmul (self , tsys ):
494
486
# Test right multiplication
495
487
# TODO: replace with better tests when conversions are implemented
@@ -510,7 +502,6 @@ def test_rmul(self, tsys):
510
502
lti_t , lti_y = ct .forced_response (ioslin , T , U * U , X0 )
511
503
np .testing .assert_array_almost_equal (ios_y , lti_y * lti_y , decimal = 3 )
512
504
513
- @noscipy0
514
505
def test_neg (self , tsys ):
515
506
"""Test negation of a system"""
516
507
@@ -533,7 +524,6 @@ def test_neg(self, tsys):
533
524
lti_t , lti_y = ct .forced_response (ioslin , T , U * U , X0 )
534
525
np .testing .assert_array_almost_equal (ios_y , - lti_y , decimal = 3 )
535
526
536
- @noscipy0
537
527
def test_feedback (self , tsys ):
538
528
# Set up parameters for simulation
539
529
T , U , X0 = tsys .T , tsys .U , tsys .X0
@@ -549,7 +539,6 @@ def test_feedback(self, tsys):
549
539
lti_t , lti_y = ct .forced_response (linsys , T , U , X0 )
550
540
np .testing .assert_allclose (ios_y , lti_y ,atol = 0.002 ,rtol = 0. )
551
541
552
- @noscipy0
553
542
def test_bdalg_functions (self , tsys ):
554
543
"""Test block diagram functions algebra on I/O systems"""
555
544
# Set up parameters for simulation
@@ -596,7 +585,6 @@ def test_bdalg_functions(self, tsys):
596
585
ios_t , ios_y = ios .input_output_response (iosys_feedback , T , U , X0 )
597
586
np .testing .assert_allclose (ios_y , lin_y ,atol = 0.002 ,rtol = 0. )
598
587
599
- @noscipy0
600
588
def test_algebraic_functions (self , tsys ):
601
589
"""Test algebraic operations on I/O systems"""
602
590
# Set up parameters for simulation
@@ -648,7 +636,6 @@ def test_algebraic_functions(self, tsys):
648
636
ios_t , ios_y = ios .input_output_response (iosys_negate , T , U , X0 )
649
637
np .testing .assert_allclose (ios_y , lin_y ,atol = 0.002 ,rtol = 0. )
650
638
651
- @noscipy0
652
639
def test_nonsquare_bdalg (self , tsys ):
653
640
# Set up parameters for simulation
654
641
T = tsys .T
@@ -699,7 +686,6 @@ def test_nonsquare_bdalg(self, tsys):
699
686
with pytest .raises (ValueError ):
700
687
ct .series (* args )
701
688
702
- @noscipy0
703
689
def test_discrete (self , tsys ):
704
690
"""Test discrete time functionality"""
705
691
# Create some linear and nonlinear systems to play with
@@ -868,7 +854,6 @@ def test_find_eqpts(self, tsys):
868
854
assert xeq is None
869
855
assert ueq is None
870
856
871
- @noscipy0
872
857
def test_params (self , tsys ):
873
858
# Start with the default set of parameters
874
859
ios_secord_default = ios .NonlinearIOSystem (
@@ -1433,11 +1418,10 @@ def test_duplicates(self, tsys):
1433
1418
nlios2 = ios .NonlinearIOSystem (None ,
1434
1419
lambda t , x , u , params : u * u ,
1435
1420
inputs = 1 , outputs = 1 , name = "nlios2" )
1436
- with pytest .warns (None ) as record :
1421
+ with warnings .catch_warnings ():
1422
+ warnings .simplefilter ("error" )
1437
1423
ct .InterconnectedSystem ([nlios1 , iosys_siso , nlios2 ],
1438
1424
inputs = 0 , outputs = 0 , states = 0 )
1439
- if record :
1440
- pytest .fail ("Warning not expected: " + record [0 ].message )
1441
1425
1442
1426
1443
1427
def test_linear_interconnection ():
@@ -1527,7 +1511,7 @@ def predprey(t, x, u, params={}):
1527
1511
1528
1512
def pvtol (t , x , u , params = {}):
1529
1513
"""Reduced planar vertical takeoff and landing dynamics"""
1530
- from math import sin , cos
1514
+ from math import cos , sin
1531
1515
m = params .get ('m' , 4. ) # kg, system mass
1532
1516
J = params .get ('J' , 0.0475 ) # kg m^2, system inertia
1533
1517
r = params .get ('r' , 0.25 ) # m, thrust offset
@@ -1543,7 +1527,7 @@ def pvtol(t, x, u, params={}):
1543
1527
1544
1528
1545
1529
def pvtol_full (t , x , u , params = {}):
1546
- from math import sin , cos
1530
+ from math import cos , sin
1547
1531
m = params .get ('m' , 4. ) # kg, system mass
1548
1532
J = params .get ('J' , 0.0475 ) # kg m^2, system inertia
1549
1533
r = params .get ('r' , 0.25 ) # m, thrust offset
@@ -1596,8 +1580,12 @@ def test_interconnect_unused_input():
1596
1580
inputs = ['r' ],
1597
1581
outputs = ['y' ])
1598
1582
1599
- with pytest . warns ( None ) as record :
1583
+ with warnings . catch_warnings () :
1600
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 )
1601
1589
h = ct .interconnect ([g ,s ,k ],
1602
1590
inputs = ['r' ],
1603
1591
outputs = ['y' ],
@@ -1612,14 +1600,6 @@ def test_interconnect_unused_input():
1612
1600
h = ct .interconnect ([g ,s ,k ],
1613
1601
connections = False )
1614
1602
1615
- #https://docs.pytest.org/en/6.2.x/warnings.html#recwarn
1616
- for r in record :
1617
- # strip out matrix warnings
1618
- if re .match (r'.*matrix subclass' , str (r .message )):
1619
- continue
1620
- print (r .message )
1621
- pytest .fail (f'Unexpected warning: { r .message } ' )
1622
-
1623
1603
1624
1604
# warn if explicity ignored input in fact used
1625
1605
with pytest .warns (
@@ -1674,7 +1654,11 @@ def test_interconnect_unused_output():
1674
1654
1675
1655
1676
1656
# no warning if output explicitly ignored
1677
- 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 )
1678
1662
h = ct .interconnect ([g ,s ,k ],
1679
1663
inputs = ['r' ],
1680
1664
outputs = ['y' ],
@@ -1689,14 +1673,6 @@ def test_interconnect_unused_output():
1689
1673
h = ct .interconnect ([g ,s ,k ],
1690
1674
connections = False )
1691
1675
1692
- #https://docs.pytest.org/en/6.2.x/warnings.html#recwarn
1693
- for r in record :
1694
- # strip out matrix warnings
1695
- if re .match (r'.*matrix subclass' , str (r .message )):
1696
- continue
1697
- print (r .message )
1698
- pytest .fail (f'Unexpected warning: { r .message } ' )
1699
-
1700
1676
# warn if explicity ignored output in fact used
1701
1677
with pytest .warns (
1702
1678
UserWarning ,
0 commit comments