Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix loading of defaults during pytest fixture setup #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_get_param(self):
assert ct.config._get_param('config', 'test1', None) == 1
assert ct.config._get_param('config', 'test1', None, 1) == 1

ct.config.defaults['config.test3'] is None
ct.config.defaults['config.test3'] = None
assert ct.config._get_param('config', 'test3') is None
assert ct.config._get_param('config', 'test3', 1) == 1
assert ct.config._get_param('config', 'test3', None, 1) is None
Expand Down
21 changes: 18 additions & 3 deletions control/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@
"PendingDeprecationWarning")


@pytest.fixture(scope="session", autouse=TEST_MATRIX_AND_ARRAY,
@pytest.fixture(scope="session", autouse=True)
def control_defaults():
"""Make sure the testing session always starts with the defaults.

This should be the first fixture initialized,
so that all other fixtures see the general defaults (unless they set them
themselves) even before importing control/__init__. Enforce this by adding
it as an argument to all other session scoped fixtures.
"""
control.reset_defaults()
the_defaults = control.config.defaults.copy()
yield
# assert that nothing changed it without reverting
assert control.config.defaults == the_defaults

@pytest.fixture(scope="function", autouse=TEST_MATRIX_AND_ARRAY,
params=[pytest.param("arrayout", marks=matrixerrorfilter),
pytest.param("matrixout", marks=matrixfilter)])
def matarrayout(request):
Expand Down Expand Up @@ -70,7 +85,7 @@ def check_deprecated_matrix():
yield


@pytest.fixture(scope="session",
@pytest.fixture(scope="function",
params=[p for p, usebydefault in
[(pytest.param(np.array,
id="arrayin"),
Expand All @@ -90,7 +105,7 @@ def editsdefaults():
"""Make sure any changes to the defaults only last during a test"""
restore = control.config.defaults.copy()
yield
control.config.defaults.update(restore)
control.config.defaults = restore.copy()


@pytest.fixture(scope="function")
Expand Down
16 changes: 15 additions & 1 deletion control/tests/statesp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from control.dtime import sample_system
from control.lti import evalfr
from control.statesp import (StateSpace, _convertToStateSpace, drss, rss, ss,
tf2ss)
tf2ss, _statesp_defaults)
from control.tests.conftest import ismatarrayout, slycotonly
from control.xferfcn import TransferFunction, ss2tf

Expand Down Expand Up @@ -826,3 +826,17 @@ def test_returnScipySignalLTI_error(self, mimoss):
with pytest.raises(ValueError):
mimoss.returnScipySignalLTI(strict=True)


class TestStateSpaceConfig:
"""Test the configuration of the StateSpace module"""

@pytest.fixture
def matarrayout(self):
"""Override autoused global fixture within this class"""
pass

def test_statespace_defaults(self, matarrayout):
"""Make sure the tests are run with the configured defaults"""
for k, v in _statesp_defaults.items():
assert defaults[k] == v, \
"{} is {} but expected {}".format(k, defaults[k], v)