Skip to content

Commit bbb2e36

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

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
assert ct.config._get_param('config', 'test1', None) == 1
3838
assert ct.config._get_param('config', 'test1', None, 1) == 1
3939

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

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+
def control_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+
assert control.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
def matarrayout(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=[p for p, usebydefault in
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
from control.dtime import sample_system
1717
from control.lti import evalfr
1818
from control.statesp import (StateSpace, _convertToStateSpace, drss, rss, ss,
19-
tf2ss)
19+
tf2ss, _statesp_defaults)
2020
from control.tests.conftest import ismatarrayout, slycotonly
2121
from control.xferfcn import TransferFunction, ss2tf
2222

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy