@@ -132,18 +132,17 @@ def test_nyquist_basic():
132
132
# Nyquist plot with poles on imaginary axis, omega specified
133
133
# (can miss encirclements due to the imaginary poles at +/- 1j)
134
134
sys = ct .tf ([1 ], [1 , 3 , 2 ]) * ct .tf ([1 ], [1 , 0 , 1 ])
135
- with pytest . warns ( UserWarning , match = "does not match" ) as records :
135
+ with warnings . catch_warnings ( record = True ) as records :
136
136
count = ct .nyquist_response (sys , np .linspace (1e-3 , 1e1 , 1000 ))
137
- if len (records ) == 0 :
138
- assert _Z (sys ) == count + _P (sys )
139
-
140
- # Nyquist plot with poles on imaginary axis, omega specified, with contour
141
- sys = ct .tf ([1 ], [1 , 3 , 2 ]) * ct .tf ([1 ], [1 , 0 , 1 ])
142
- with pytest .warns (UserWarning , match = "does not match" ) as records :
143
- count , contour = ct .nyquist_response (
144
- sys , np .linspace (1e-3 , 1e1 , 1000 ), return_contour = True )
145
- if len (records ) == 0 :
146
- assert _Z (sys ) == count + _P (sys )
137
+ if len (records ) == 0 :
138
+ # No warnings (it happens) => make sure count is correct
139
+ assert _Z (sys ) == count + _P (sys )
140
+ elif len (records ) == 1 :
141
+ # Expected case: make sure warning is the right one
142
+ assert issubclass (records [0 ].category , UserWarning )
143
+ assert "encirclements does not match" in str (records [0 ].message )
144
+ else :
145
+ pytest .fail ("multiple warnings in nyquist_response (?)" )
147
146
148
147
# Nyquist plot with poles on imaginary axis, return contour
149
148
sys = ct .tf ([1 ], [1 , 3 , 2 ]) * ct .tf ([1 ], [1 , 0 , 1 ])
0 commit comments