Skip to content

Commit b6e21f4

Browse files
authored
Merge pull request #769 from bashtage/remove-unused-vendor-code
TST: Add fixture to select agg
2 parents bfed234 + 13d7859 commit b6e21f4

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

arch/conftest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,42 @@ def pytest_runtest_setup(item):
4545
"--only-slow"
4646
): # pragma: no cover
4747
pytest.skip("skipping due to --only-slow") # pragma: no cover
48+
49+
50+
@pytest.fixture()
51+
def agg_backend():
52+
"""
53+
Fixture that switches the backend to agg for the duration of the test
54+
55+
Returns
56+
-------
57+
switch_backend : callable
58+
Function that will change the backend to agg when called
59+
60+
Notes
61+
-----
62+
Used by passing as an argument to the function that produces a plot,
63+
for example
64+
65+
def test_some_plot(agg_backend):
66+
<test code>
67+
"""
68+
backend = None
69+
try:
70+
import matplotlib
71+
72+
backend = matplotlib.get_backend()
73+
matplotlib.use("agg")
74+
75+
except ImportError:
76+
# Nothing to do if MPL is not available
77+
pass
78+
79+
def null():
80+
pass
81+
82+
yield null
83+
if backend:
84+
import matplotlib
85+
86+
matplotlib.use(backend)

arch/tests/unitroot/test_engle_granger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_bivariate_eg_alternative(data, trend, method):
142142
@pytest.mark.parametrize("trend", ["n", "c", "ct", "ctt"])
143143
@pytest.mark.parametrize("method", ["aic", "bic"])
144144
@pytest.mark.parametrize("lhs", ["x", "y", "z"])
145-
def test_trivariate(data, trend, method, lhs):
145+
def test_trivariate(data, trend, method, lhs, agg_backend):
146146
rhs = ["x", "y", "z"]
147147
if isinstance(data, pd.DataFrame):
148148
rhs.remove(lhs)
@@ -214,7 +214,7 @@ def test_name_ci_vector(data):
214214

215215

216216
@pytest.mark.skipif(not HAS_MATPLOTLIB, reason="matplotlib not available")
217-
def test_plot(data):
217+
def test_plot(data, agg_backend):
218218
rhs = ["x", "y", "z"]
219219
lhs = "y"
220220
if isinstance(data, pd.DataFrame):

arch/tests/univariate/test_mean.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def test_ar_no_lags(self):
553553
assert "lags: none" in ar.__str__()
554554

555555
@pytest.mark.skipif(not HAS_MATPLOTLIB, reason="matplotlib not installed")
556-
def test_ar_plot(self):
556+
def test_ar_plot(self, agg_backend):
557557
ar = ARX(self.y, lags=1, volatility=GARCH(), distribution=StudentsT())
558558
res = ar.fit(disp=DISPLAY, update_freq=UPDATE_FREQ, cov_type="mle")
559559
res.plot()
@@ -1351,7 +1351,7 @@ def test_param_cov():
13511351

13521352

13531353
@pytest.mark.skipif(not HAS_MATPLOTLIB, reason="matplotlib not installed")
1354-
def test_plot_bad_index():
1354+
def test_plot_bad_index(agg_backend):
13551355
import matplotlib.pyplot as plt
13561356

13571357
idx = sorted(f"{a}{b}{c}" for a, b, c in product(*([ascii_lowercase] * 3)))
@@ -1476,7 +1476,7 @@ def test_fixed_equivalence(fit_fixed_models):
14761476

14771477

14781478
@pytest.mark.skipif(not HAS_MATPLOTLIB, reason="matplotlib not installed")
1479-
def test_fixed_equivalence_plots(fit_fixed_models):
1479+
def test_fixed_equivalence_plots(fit_fixed_models, agg_backend):
14801480
import matplotlib
14811481

14821482
backend = matplotlib.get_backend()
@@ -1512,7 +1512,7 @@ def test_fixed_equivalence_forecastable(forecastable_model, simulations):
15121512

15131513
@pytest.mark.slow
15141514
@pytest.mark.skipif(not HAS_MATPLOTLIB, reason="matplotlib not installed")
1515-
def test_fixed_equivalence_forecastable_plots(forecastable_model):
1515+
def test_fixed_equivalence_forecastable_plots(forecastable_model, agg_backend):
15161516
res, res_fixed = forecastable_model
15171517
fig1 = res.hedgehog_plot(start=SP500.shape[0] - 25)
15181518
fig2 = res_fixed.hedgehog_plot(start=SP500.shape[0] - 25)

0 commit comments

Comments
 (0)