8
8
from math import pi ,log10
9
9
10
10
import matplotlib .pyplot as plt
11
- from matplotlib .testing .decorators import cleanup as mplcleanup
12
11
import numpy as np
13
12
import pytest
14
13
18
17
@pytest .mark .usefixtures ("editsdefaults" )# makes sure to reset the defaults
19
18
# to the test configuration
20
19
class TestConfig :
21
-
22
20
# Create a simple second order system to use for testing
23
21
sys = ct .tf ([10 ], [1 ,2 ,1 ])
24
22
@@ -28,8 +26,7 @@ def test_set_defaults(self):
28
26
assert ct .config .defaults ['freqplot.deg' ]== 2
29
27
assert ct .config .defaults ['freqplot.Hz' ]is None
30
28
31
- @mplcleanup
32
- def test_get_param (self ):
29
+ def test_get_param (self ,mplcleanup ):
33
30
assert ct .config ._get_param ('freqplot' ,'dB' )\
34
31
== ct .config .defaults ['freqplot.dB' ]
35
32
assert ct .config ._get_param ('freqplot' ,'dB' ,1 )== 1
@@ -92,8 +89,7 @@ def test_default_deprecation(self):
92
89
assert ct .config .defaults ['bode.Hz' ] \
93
90
== ct .config .defaults ['freqplot.Hz' ]
94
91
95
- @mplcleanup
96
- def test_fbs_bode (self ):
92
+ def test_fbs_bode (self ,mplcleanup ):
97
93
ct .use_fbs_defaults ()
98
94
99
95
# Generate a Bode plot
@@ -137,8 +133,7 @@ def test_fbs_bode(self):
137
133
phase_x ,phase_y = (((plt .gcf ().axes [1 ]).get_lines ())[0 ]).get_data ()
138
134
np .testing .assert_almost_equal (phase_y [- 1 ],- pi ,decimal = 2 )
139
135
140
- @mplcleanup
141
- def test_matlab_bode (self ):
136
+ def test_matlab_bode (self ,mplcleanup ):
142
137
ct .use_matlab_defaults ()
143
138
144
139
# Generate a Bode plot
@@ -182,8 +177,7 @@ def test_matlab_bode(self):
182
177
phase_x ,phase_y = (((plt .gcf ().axes [1 ]).get_lines ())[0 ]).get_data ()
183
178
np .testing .assert_almost_equal (phase_y [- 1 ],- pi ,decimal = 2 )
184
179
185
- @mplcleanup
186
- def test_custom_bode_default (self ):
180
+ def test_custom_bode_default (self ,mplcleanup ):
187
181
ct .config .defaults ['freqplot.dB' ]= True
188
182
ct .config .defaults ['freqplot.deg' ]= True
189
183
ct .config .defaults ['freqplot.Hz' ]= True
@@ -204,8 +198,7 @@ def test_custom_bode_default(self):
204
198
np .testing .assert_almost_equal (mag_y [0 ],20 * log10 (10 ),decimal = 3 )
205
199
np .testing .assert_almost_equal (phase_y [- 1 ],- pi ,decimal = 2 )
206
200
207
- @mplcleanup
208
- def test_bode_number_of_samples (self ):
201
+ def test_bode_number_of_samples (self ,mplcleanup ):
209
202
# Set the number of samples (default is 50, from np.logspace)
210
203
mag_ret ,phase_ret ,omega_ret = ct .bode_plot (self .sys ,omega_num = 87 )
211
204
assert len (mag_ret )== 87
@@ -219,8 +212,7 @@ def test_bode_number_of_samples(self):
219
212
mag_ret ,phase_ret ,omega_ret = ct .bode_plot (self .sys ,omega_num = 87 )
220
213
assert len (mag_ret )== 87
221
214
222
- @mplcleanup
223
- def test_bode_feature_periphery_decade (self ):
215
+ def test_bode_feature_periphery_decade (self ,mplcleanup ):
224
216
# Generate a sample Bode plot to figure out the range it uses
225
217
ct .reset_defaults ()# Make sure starting state is correct
226
218
mag_ret ,phase_ret ,omega_ret = ct .bode_plot (self .sys ,Hz = False )