Skip to content

Commit 45d677f

Browse files
committed
extend fixture usage to matarrayin and matarrayout, pytestify statefbk_test.py
this replaces the funcitionality of previously dropped statefbk_matrix_test.py to test that the functions work with (dperecated) matrix input
1 parent 89118fe commit 45d677f

File tree

4 files changed

+165
-144
lines changed

4 files changed

+165
-144
lines changed

control/tests/conftest.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,28 @@
2020

2121

2222
@pytest.fixture(scope="session", autouse=test_ndarray,
23-
params=["array", "matrix"])
24-
def use_numpy_ndarray_and_matrix(request):
25-
"""Switch the config to use np.ndarray or np.matrix"""
23+
params=["arrayout", "matrixout"])
24+
def matarrayout(request):
25+
"""Switch the config to use np.ndarray and np.matrix as returns"""
2626
restore = control.config.defaults['statesp.use_numpy_matrix']
27-
control.use_numpy_matrix(request.param == "matrix", warn=False)
27+
control.use_numpy_matrix(request.param == "matrixout", warn=False)
2828
yield
2929
control.use_numpy_matrix(restore, warn=False)
3030

3131

32-
def is_matrix_or_array(obj):
32+
def ismatarrayout(obj):
3333
"""Test if the returned object has the correct type as configured"""
3434
use_matrix = control.config.defaults['statesp.use_numpy_matrix']
3535
return isinstance(obj, np.matrix if use_matrix else np.ndarray)
3636

3737

38+
def asmatarrayout(obj):
39+
"""Return a object according to the configured default"""
40+
use_matrix = control.config.defaults['statesp.use_numpy_matrix']
41+
matarray = np.asmatrix if use_matrix else np.asarray
42+
return matarray(obj)
43+
44+
3845
@contextmanager
3946
def check_deprecated_matrix():
4047
"""Check that a call produces a deprecation warning because of np.matrix"""
@@ -49,6 +56,14 @@ def check_deprecated_matrix():
4956
yield
5057

5158

59+
@pytest.fixture(scope="session",
60+
params=[np.array, np.matrix] if test_ndarray else [np.array],
61+
ids=["arrayin", "matrixin"] if test_ndarray else ["arrayin"])
62+
def matarrayin(request):
63+
"""Use array and matrix to construct input data in tests"""
64+
return request.param
65+
66+
5267
@pytest.fixture(scope="function")
5368
def editsdefaults():
5469
"""Make sure any changes to the defaults only last during a test"""

control/tests/modelsimp_array_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestModelsimp:
1616
"""Test model reduction functions"""
1717

1818
@slycotonly
19-
def testHSVD(self, use_numpy_ndarray_and_matrix):
19+
def testHSVD(self, matarrayout):
2020
A = np.array([[1., -2.], [3., -4.]])
2121
B = np.array([[5.], [7.]])
2222
C = np.array([[6., 8.]])

0 commit comments

Comments
 (0)