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

Skip to content

Remove ax fixture from category tests. #20000

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
Apr 17, 2021
Merged
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
40 changes: 23 additions & 17 deletions lib/matplotlib/tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ def test_default_units(self):
assert isinstance(self.cc.default_units(["a"], self.ax), cat.UnitData)


@pytest.fixture
def ax():
return plt.figure().subplots()


PLOT_LIST = [Axes.scatter, Axes.plot, Axes.bar]
PLOT_IDS = ["scatter", "plot", "bar"]

Expand All @@ -139,7 +134,8 @@ def test_StrCategoryLocator(self):
np.testing.assert_array_equal(ticks.tick_values(None, None), locs)

@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_StrCategoryLocatorPlot(self, ax, plotter):
def test_StrCategoryLocatorPlot(self, plotter):
ax = plt.figure().subplots()
plotter(ax, [1, 2, 3], ["a", "b", "c"])
np.testing.assert_array_equal(ax.yaxis.major.locator(), range(3))

Expand All @@ -151,7 +147,7 @@ class TestStrCategoryFormatter:
ids, cases = zip(*test_cases)

@pytest.mark.parametrize("ydata", cases, ids=ids)
def test_StrCategoryFormatter(self, ax, ydata):
def test_StrCategoryFormatter(self, ydata):
unit = cat.UnitData(ydata)
labels = cat.StrCategoryFormatter(unit._mapping)
for i, d in enumerate(ydata):
Expand All @@ -160,7 +156,8 @@ def test_StrCategoryFormatter(self, ax, ydata):

@pytest.mark.parametrize("ydata", cases, ids=ids)
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_StrCategoryFormatterPlot(self, ax, ydata, plotter):
def test_StrCategoryFormatterPlot(self, ydata, plotter):
ax = plt.figure().subplots()
plotter(ax, range(len(ydata)), ydata)
for i, d in enumerate(ydata):
assert ax.yaxis.major.formatter(i) == d
Expand All @@ -186,7 +183,8 @@ class TestPlotBytes:

@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
@pytest.mark.parametrize("bdata", bytes_data, ids=bytes_ids)
def test_plot_bytes(self, ax, plotter, bdata):
def test_plot_bytes(self, plotter, bdata):
ax = plt.figure().subplots()
counts = np.array([4, 6, 5])
plotter(ax, bdata, counts)
axis_test(ax.xaxis, bdata)
Expand All @@ -201,15 +199,17 @@ class TestPlotNumlike:

@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
@pytest.mark.parametrize("ndata", numlike_data, ids=numlike_ids)
def test_plot_numlike(self, ax, plotter, ndata):
def test_plot_numlike(self, plotter, ndata):
ax = plt.figure().subplots()
counts = np.array([4, 6, 5])
plotter(ax, ndata, counts)
axis_test(ax.xaxis, ndata)


class TestPlotTypes:
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_plot_unicode(self, ax, plotter):
def test_plot_unicode(self, plotter):
ax = plt.figure().subplots()
words = ['Здравствуйте', 'привет']
plotter(ax, words, [0, 1])
axis_test(ax.xaxis, words)
Expand All @@ -223,25 +223,29 @@ def test_data(self):

@pytest.mark.usefixtures("test_data")
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_plot_xaxis(self, ax, test_data, plotter):
def test_plot_xaxis(self, test_data, plotter):
ax = plt.figure().subplots()
plotter(ax, self.x, self.xy)
axis_test(ax.xaxis, self.x)

@pytest.mark.usefixtures("test_data")
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_plot_yaxis(self, ax, test_data, plotter):
def test_plot_yaxis(self, test_data, plotter):
ax = plt.figure().subplots()
plotter(ax, self.yx, self.y)
axis_test(ax.yaxis, self.y)

@pytest.mark.usefixtures("test_data")
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_plot_xyaxis(self, ax, test_data, plotter):
def test_plot_xyaxis(self, test_data, plotter):
ax = plt.figure().subplots()
plotter(ax, self.x, self.y)
axis_test(ax.xaxis, self.x)
axis_test(ax.yaxis, self.y)

@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_update_plot(self, ax, plotter):
def test_update_plot(self, plotter):
ax = plt.figure().subplots()
plotter(ax, ['a', 'b'], ['e', 'g'])
plotter(ax, ['a', 'b', 'd'], ['f', 'a', 'b'])
plotter(ax, ['b', 'c', 'd'], ['g', 'e', 'd'])
Expand All @@ -260,13 +264,15 @@ def test_update_plot(self, ax, plotter):

@pytest.mark.parametrize("plotter", plotters)
@pytest.mark.parametrize("xdata", fvalues, ids=fids)
def test_mixed_type_exception(self, ax, plotter, xdata):
def test_mixed_type_exception(self, plotter, xdata):
ax = plt.figure().subplots()
with pytest.raises(TypeError):
plotter(ax, xdata, [1, 2])

@pytest.mark.parametrize("plotter", plotters)
@pytest.mark.parametrize("xdata", fvalues, ids=fids)
def test_mixed_type_update_exception(self, ax, plotter, xdata):
def test_mixed_type_update_exception(self, plotter, xdata):
ax = plt.figure().subplots()
with pytest.raises(TypeError):
plotter(ax, [0, 3], [1, 3])
plotter(ax, xdata, [1, 2])
Expand Down