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

Skip to content

Commit d31ec5f

Browse files
committed
TST: move from decorator to fixture
1 parent e5f7982 commit d31ec5f

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

lib/matplotlib/testing/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,26 @@ def mpl_image_comparison_parameters(request, extension):
7676
yield
7777
finally:
7878
delattr(func.__wrapped__, 'parameters')
79+
80+
81+
@pytest.fixture
82+
def pd(request):
83+
'''fixture to import and configure pandas'''
84+
85+
pd = pytest.importorskip('pandas')
86+
if pd:
87+
try:
88+
from pandas.plotting import (
89+
register_matplotlib_converters as register)
90+
except ImportError:
91+
from pandas.tseries.converter import register
92+
register()
93+
94+
try:
95+
from pandas.plotting import (
96+
deregister_matplotlib_converters as deregister)
97+
request.addfinalizer(deregister)
98+
except ImportError:
99+
pass
100+
101+
return pd

lib/matplotlib/tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
from matplotlib.testing.conftest import (mpl_test_settings,
44
mpl_image_comparison_parameters,
5-
pytest_configure, pytest_unconfigure)
5+
pytest_configure, pytest_unconfigure,
6+
pd)

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,27 +5091,7 @@ def test_broken_barh_empty():
50915091
ax.broken_barh([], (.1, .5))
50925092

50935093

5094-
def _pandas_wrapper(func):
5095-
'''Decorator to centralize pandas setup / conditional import'''
5096-
import functools
5097-
5098-
@functools.wraps(func)
5099-
def wrapped_for_pandas(*args, **kwargs):
5100-
pytest.importorskip('pandas')
5101-
try:
5102-
from pandas.plotting import (
5103-
register_matplotlib_converters as register)
5104-
except ImportError:
5105-
from pandas.tseries.converter import register
5106-
register()
5107-
return func(*args, **kwargs)
5108-
5109-
return wrapped_for_pandas
5110-
5111-
5112-
@_pandas_wrapper
5113-
def test_pandas_pcolormesh():
5114-
import pandas as pd
5094+
def test_pandas_pcolormesh(pd):
51155095
time = pd.date_range('2000-01-01', periods=10)
51165096
depth = np.arange(20)
51175097
data = np.random.rand(20, 10)
@@ -5120,10 +5100,7 @@ def test_pandas_pcolormesh():
51205100
ax.pcolormesh(time, depth, data)
51215101

51225102

5123-
@_pandas_wrapper
5124-
def test_pandas_indexing_dates():
5125-
import pandas as pd
5126-
5103+
def test_pandas_indexing_dates(pd):
51275104
dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')
51285105
values = np.sin(np.array(range(len(dates))))
51295106
df = pd.DataFrame({'dates': dates, 'values': values})
@@ -5134,32 +5111,23 @@ def test_pandas_indexing_dates():
51345111
ax.plot('dates', 'values', data=without_zero_index)
51355112

51365113

5137-
@_pandas_wrapper
5138-
def test_pandas_errorbar_indexing():
5139-
import pandas as pd
5140-
5114+
def test_pandas_errorbar_indexing(pd):
51415115
df = pd.DataFrame(np.random.uniform(size=(5, 4)),
51425116
columns=['x', 'y', 'xe', 'ye'],
51435117
index=[1, 2, 3, 4, 5])
51445118
fig, ax = plt.subplots()
51455119
ax.errorbar('x', 'y', xerr='xe', yerr='ye', data=df)
51465120

51475121

5148-
@_pandas_wrapper
5149-
def test_pandas_indexing_hist():
5150-
import pandas as pd
5151-
5122+
def test_pandas_indexing_hist(pd):
51525123
ser_1 = pd.Series(data=[1, 2, 2, 3, 3, 4, 4, 4, 4, 5])
51535124
ser_2 = ser_1.iloc[1:]
51545125
fig, axes = plt.subplots()
51555126
axes.hist(ser_2)
51565127

51575128

5158-
@_pandas_wrapper
5159-
def test_pandas_bar_align_center():
5129+
def test_pandas_bar_align_center(pd):
51605130
# Tests fix for issue 8767
5161-
import pandas as pd
5162-
51635131
df = pd.DataFrame({'a': range(2), 'b': range(2)})
51645132

51655133
fig, ax = plt.subplots(1)

0 commit comments

Comments
 (0)