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

Commitbbb2e36

Browse files
authored
Merge pull request#489 from bnavigator/fix-defaults
Fix loading of defaults during pytest fixture setup
2 parentsd66f4e4 +abf1565 commitbbb2e36

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

‎control/tests/config_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_get_param(self):
3737
assertct.config._get_param('config','test1',None)==1
3838
assertct.config._get_param('config','test1',None,1)==1
3939

40-
ct.config.defaults['config.test3']isNone
40+
ct.config.defaults['config.test3']=None
4141
assertct.config._get_param('config','test3')isNone
4242
assertct.config._get_param('config','test3',1)==1
4343
assertct.config._get_param('config','test3',None,1)isNone

‎control/tests/conftest.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@
2828
"PendingDeprecationWarning")
2929

3030

31-
@pytest.fixture(scope="session",autouse=TEST_MATRIX_AND_ARRAY,
31+
@pytest.fixture(scope="session",autouse=True)
32+
defcontrol_defaults():
33+
"""Make sure the testing session always starts with the defaults.
34+
35+
This should be the first fixture initialized,
36+
so that all other fixtures see the general defaults (unless they set them
37+
themselves) even before importing control/__init__. Enforce this by adding
38+
it as an argument to all other session scoped fixtures.
39+
"""
40+
control.reset_defaults()
41+
the_defaults=control.config.defaults.copy()
42+
yield
43+
# assert that nothing changed it without reverting
44+
assertcontrol.config.defaults==the_defaults
45+
46+
@pytest.fixture(scope="function",autouse=TEST_MATRIX_AND_ARRAY,
3247
params=[pytest.param("arrayout",marks=matrixerrorfilter),
3348
pytest.param("matrixout",marks=matrixfilter)])
3449
defmatarrayout(request):
@@ -70,7 +85,7 @@ def check_deprecated_matrix():
7085
yield
7186

7287

73-
@pytest.fixture(scope="session",
88+
@pytest.fixture(scope="function",
7489
params=[pforp,usebydefaultin
7590
[(pytest.param(np.array,
7691
id="arrayin"),
@@ -90,7 +105,7 @@ def editsdefaults():
90105
"""Make sure any changes to the defaults only last during a test"""
91106
restore=control.config.defaults.copy()
92107
yield
93-
control.config.defaults.update(restore)
108+
control.config.defaults=restore.copy()
94109

95110

96111
@pytest.fixture(scope="function")

‎control/tests/statesp_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
fromcontrol.dtimeimportsample_system
1717
fromcontrol.ltiimportevalfr
1818
fromcontrol.statespimport (StateSpace,_convertToStateSpace,drss,rss,ss,
19-
tf2ss)
19+
tf2ss,_statesp_defaults)
2020
fromcontrol.tests.conftestimportismatarrayout,slycotonly
2121
fromcontrol.xferfcnimportTransferFunction,ss2tf
2222

@@ -826,3 +826,17 @@ def test_returnScipySignalLTI_error(self, mimoss):
826826
withpytest.raises(ValueError):
827827
mimoss.returnScipySignalLTI(strict=True)
828828

829+
830+
classTestStateSpaceConfig:
831+
"""Test the configuration of the StateSpace module"""
832+
833+
@pytest.fixture
834+
defmatarrayout(self):
835+
"""Override autoused global fixture within this class"""
836+
pass
837+
838+
deftest_statespace_defaults(self,matarrayout):
839+
"""Make sure the tests are run with the configured defaults"""
840+
fork,vin_statesp_defaults.items():
841+
assertdefaults[k]==v, \
842+
"{} is {} but expected {}".format(k,defaults[k],v)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp