Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f13a07

Browse files
committed
Replace mplcleanup decorator use by fixture
1 parent89ce0cb commit7f13a07

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

‎control/tests/config_test.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
frommathimportpi,log10
99

1010
importmatplotlib.pyplotasplt
11-
frommatplotlib.testing.decoratorsimportcleanupasmplcleanup
1211
importnumpyasnp
1312
importpytest
1413

@@ -18,7 +17,6 @@
1817
@pytest.mark.usefixtures("editsdefaults")# makes sure to reset the defaults
1918
# to the test configuration
2019
classTestConfig:
21-
2220
# Create a simple second order system to use for testing
2321
sys=ct.tf([10], [1,2,1])
2422

@@ -28,8 +26,7 @@ def test_set_defaults(self):
2826
assertct.config.defaults['freqplot.deg']==2
2927
assertct.config.defaults['freqplot.Hz']isNone
3028

31-
@mplcleanup
32-
deftest_get_param(self):
29+
deftest_get_param(self,mplcleanup):
3330
assertct.config._get_param('freqplot','dB')\
3431
==ct.config.defaults['freqplot.dB']
3532
assertct.config._get_param('freqplot','dB',1)==1
@@ -92,8 +89,7 @@ def test_default_deprecation(self):
9289
assertct.config.defaults['bode.Hz'] \
9390
==ct.config.defaults['freqplot.Hz']
9491

95-
@mplcleanup
96-
deftest_fbs_bode(self):
92+
deftest_fbs_bode(self,mplcleanup):
9793
ct.use_fbs_defaults()
9894

9995
# Generate a Bode plot
@@ -137,8 +133,7 @@ def test_fbs_bode(self):
137133
phase_x,phase_y= (((plt.gcf().axes[1]).get_lines())[0]).get_data()
138134
np.testing.assert_almost_equal(phase_y[-1],-pi,decimal=2)
139135

140-
@mplcleanup
141-
deftest_matlab_bode(self):
136+
deftest_matlab_bode(self,mplcleanup):
142137
ct.use_matlab_defaults()
143138

144139
# Generate a Bode plot
@@ -182,8 +177,7 @@ def test_matlab_bode(self):
182177
phase_x,phase_y= (((plt.gcf().axes[1]).get_lines())[0]).get_data()
183178
np.testing.assert_almost_equal(phase_y[-1],-pi,decimal=2)
184179

185-
@mplcleanup
186-
deftest_custom_bode_default(self):
180+
deftest_custom_bode_default(self,mplcleanup):
187181
ct.config.defaults['freqplot.dB']=True
188182
ct.config.defaults['freqplot.deg']=True
189183
ct.config.defaults['freqplot.Hz']=True
@@ -204,8 +198,7 @@ def test_custom_bode_default(self):
204198
np.testing.assert_almost_equal(mag_y[0],20*log10(10),decimal=3)
205199
np.testing.assert_almost_equal(phase_y[-1],-pi,decimal=2)
206200

207-
@mplcleanup
208-
deftest_bode_number_of_samples(self):
201+
deftest_bode_number_of_samples(self,mplcleanup):
209202
# Set the number of samples (default is 50, from np.logspace)
210203
mag_ret,phase_ret,omega_ret=ct.bode_plot(self.sys,omega_num=87)
211204
assertlen(mag_ret)==87
@@ -219,8 +212,7 @@ def test_bode_number_of_samples(self):
219212
mag_ret,phase_ret,omega_ret=ct.bode_plot(self.sys,omega_num=87)
220213
assertlen(mag_ret)==87
221214

222-
@mplcleanup
223-
deftest_bode_feature_periphery_decade(self):
215+
deftest_bode_feature_periphery_decade(self,mplcleanup):
224216
# Generate a sample Bode plot to figure out the range it uses
225217
ct.reset_defaults()# Make sure starting state is correct
226218
mag_ret,phase_ret,omega_ret=ct.bode_plot(self.sys,Hz=False)

‎control/tests/conftest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""conftest.py - pytest local plugins and fixtures"""
22

33
importos
4-
importsys
54
fromcontextlibimportcontextmanager
65

76
importmatplotlibasmpl
87
importnumpyasnp
98
importpytest
10-
importscipyassp
119

1210
importcontrol
1311

@@ -45,15 +43,15 @@ def control_defaults():
4543
params=[pytest.param("arrayout",marks=matrixerrorfilter),
4644
pytest.param("matrixout",marks=matrixfilter)])
4745
defmatarrayout(request):
48-
"""Switch the config to use np.ndarray and np.matrix as returns"""
46+
"""Switch the config to use np.ndarray and np.matrix as returns."""
4947
restore=control.config.defaults['statesp.use_numpy_matrix']
5048
control.use_numpy_matrix(request.param=="matrixout",warn=False)
5149
yield
5250
control.use_numpy_matrix(restore,warn=False)
5351

5452

5553
defismatarrayout(obj):
56-
"""Test if the returned object has the correct type as configured
54+
"""Test if the returned object has the correct type as configured.
5755
5856
note that isinstance(np.matrix(obj), np.ndarray) is True
5957
"""
@@ -63,15 +61,15 @@ def ismatarrayout(obj):
6361

6462

6563
defasmatarrayout(obj):
66-
"""Return a object according to the configured default"""
64+
"""Return a object according to the configured default."""
6765
use_matrix=control.config.defaults['statesp.use_numpy_matrix']
6866
matarray=np.asmatrixifuse_matrixelsenp.asarray
6967
returnmatarray(obj)
7068

7169

7270
@contextmanager
7371
defcheck_deprecated_matrix():
74-
"""Check that a call produces a deprecation warning because of np.matrix"""
72+
"""Check that a call produces a deprecation warning because of np.matrix."""
7573
use_matrix=control.config.defaults['statesp.use_numpy_matrix']
7674
ifuse_matrix:
7775
withpytest.deprecated_call():
@@ -94,13 +92,13 @@ def check_deprecated_matrix():
9492
False)]
9593
ifusebydefaultorTEST_MATRIX_AND_ARRAY])
9694
defmatarrayin(request):
97-
"""Use array and matrix to construct input data in tests"""
95+
"""Use array and matrix to construct input data in tests."""
9896
returnrequest.param
9997

10098

10199
@pytest.fixture(scope="function")
102100
defeditsdefaults():
103-
"""Make sure any changes to the defaults only last during a test"""
101+
"""Make sure any changes to the defaults only last during a test."""
104102
restore=control.config.defaults.copy()
105103
yield
106104
control.config.defaults=restore.copy()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp