1
1
"""conftest.py - pytest local plugins and fixtures"""
2
2
3
3
import os
4
- import sys
5
4
from contextlib import contextmanager
6
5
7
6
import matplotlib as mpl
8
7
import numpy as np
9
8
import pytest
10
- import scipy as sp
11
9
12
10
import control
13
11
@@ -45,15 +43,15 @@ def control_defaults():
45
43
params = [pytest .param ("arrayout" , marks = matrixerrorfilter ),
46
44
pytest .param ("matrixout" , marks = matrixfilter )])
47
45
def matarrayout (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. """
49
47
restore = control .config .defaults ['statesp.use_numpy_matrix' ]
50
48
control .use_numpy_matrix (request .param == "matrixout" , warn = False )
51
49
yield
52
50
control .use_numpy_matrix (restore , warn = False )
53
51
54
52
55
53
def ismatarrayout (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.
57
55
58
56
note that isinstance(np.matrix(obj), np.ndarray) is True
59
57
"""
@@ -63,15 +61,15 @@ def ismatarrayout(obj):
63
61
64
62
65
63
def asmatarrayout (obj ):
66
- """Return a object according to the configured default"""
64
+ """Return a object according to the configured default. """
67
65
use_matrix = control .config .defaults ['statesp.use_numpy_matrix' ]
68
66
matarray = np .asmatrix if use_matrix else np .asarray
69
67
return matarray (obj )
70
68
71
69
72
70
@contextmanager
73
71
def check_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. """
75
73
use_matrix = control .config .defaults ['statesp.use_numpy_matrix' ]
76
74
if use_matrix :
77
75
with pytest .deprecated_call ():
@@ -94,19 +92,20 @@ def check_deprecated_matrix():
94
92
False )]
95
93
if usebydefault or TEST_MATRIX_AND_ARRAY ])
96
94
def matarrayin (request ):
97
- """Use array and matrix to construct input data in tests"""
95
+ """Use array and matrix to construct input data in tests. """
98
96
return request .param
99
97
100
98
101
99
@pytest .fixture (scope = "function" )
102
100
def editsdefaults ():
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. """
104
102
restore = control .config .defaults .copy ()
105
103
yield
106
104
control .config .defaults = restore .copy ()
107
105
108
106
109
107
@pytest .fixture (scope = "function" )
108
+ @pytest .mark .flaky (reruns = 2 , reruns_delay = 1 )
110
109
def mplcleanup ():
111
110
"""Clean up any plots and changes a test may have made to matplotlib.
112
111
0 commit comments