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

Skip to content

Commit c5a8246

Browse files
author
Vladimir
committed
feat, refactor: Combine rcparams and kwargs in one test suite
1 parent eae69a3 commit c5a8246

File tree

1 file changed

+46
-100
lines changed

1 file changed

+46
-100
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 46 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -193,122 +193,68 @@ def test_additional(self, lim, ref):
193193
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
194194

195195
@pytest.mark.parametrize(
196-
'lim, ref',
197-
[
198-
(
199-
(0, 1.39),
200-
[0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
201-
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
202-
0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35]
203-
),
204-
(
205-
(0, 0.139),
206-
[0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045,
207-
0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09,
208-
0.095, 0.105, 0.11, 0.115, 0.125, 0.13, 0.135]
209-
),
210-
],
211-
)
212-
def test_number_of_minor_ticks_rcparams_auto(self, lim, ref):
213-
with mpl.rc_context({'xtick.minor.ndivs': 'auto',
214-
'ytick.minor.ndivs': 'auto'}):
196+
'lim, ref, use_rcparam', [
197+
((0, 1.39),
198+
[0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7,
199+
0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35], True),
200+
((0, 1.39),
201+
[0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7,
202+
0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35], False),
203+
((0, 0.139),
204+
[0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055,
205+
0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115,
206+
0.125, 0.13, 0.135], True),
207+
((0, 0.139),
208+
[0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055,
209+
0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115,
210+
0.125, 0.13, 0.135], False),
211+
])
212+
def test_number_of_minor_ticks_auto(self, lim, ref, use_rcparam):
213+
if use_rcparam:
214+
context = {'xtick.minor.ndivs': 'auto',
215+
'ytick.minor.ndivs': 'auto'}
216+
kwargs = {}
217+
else:
218+
context = {}
219+
kwargs = {'n': 'auto'}
220+
221+
with mpl.rc_context(context):
215222
fig, ax = plt.subplots()
216223
ax.set_xlim(*lim)
217224
ax.set_ylim(*lim)
218-
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
219-
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator())
225+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs))
226+
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs))
220227
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref)
221228
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
222229

223230
@pytest.mark.parametrize(
224-
'lim, ref',
225-
[
226-
(
227-
(0, 1.39),
228-
[0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
229-
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
230-
0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35]
231-
),
232-
(
233-
(0, 0.139),
234-
[0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045,
235-
0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09,
236-
0.095, 0.105, 0.11, 0.115, 0.125, 0.13, 0.135]
237-
),
238-
],
239-
)
240-
def test_number_of_minor_ticks_ndivs_auto(self, lim, ref):
241-
fig, ax = plt.subplots()
242-
ax.set_xlim(*lim)
243-
ax.set_ylim(*lim)
244-
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(n='auto'))
245-
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(n='auto'))
246-
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref)
247-
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
231+
'n, lim, ref, use_rcparam', [
232+
(2, (0, 4), [0.5, 1.5, 2.5, 3.5], True),
233+
(2, (0, 4), [0.5, 1.5, 2.5, 3.5], False),
234+
(4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75], True),
235+
(4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75], False),
236+
(10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], True),
237+
(10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], False),
238+
])
239+
def test_number_of_minor_ticks_int(self, n, lim, ref, use_rcparam):
240+
if use_rcparam:
241+
context = {'xtick.minor.ndivs': n, 'ytick.minor.ndivs': n}
242+
kwargs = {}
243+
else:
244+
context = {}
245+
kwargs = {'n': n}
248246

249-
@pytest.mark.parametrize(
250-
'n, lim, ref',
251-
[
252-
(
253-
2,
254-
(0, 4),
255-
[0.5, 1.5, 2.5, 3.5]
256-
),
257-
(
258-
4,
259-
(0, 2),
260-
[0.25, 0.5, 0.75, 1.25, 1.5, 1.75]
261-
),
262-
(
263-
10,
264-
(0, 1),
265-
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
266-
),
267-
],
268-
)
269-
def test_number_of_minor_ticks_rcparams_int(self, n, lim, ref):
270-
with mpl.rc_context({'xtick.minor.ndivs': n, 'ytick.minor.ndivs': n}):
247+
with mpl.rc_context(context):
271248
fig, ax = plt.subplots()
272249
ax.set_xlim(*lim)
273250
ax.set_ylim(*lim)
274251
ax.xaxis.set_major_locator(mticker.MultipleLocator(1))
275-
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
252+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs))
276253
ax.yaxis.set_major_locator(mticker.MultipleLocator(1))
277-
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator())
254+
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs))
278255
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref)
279256
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
280257

281-
@pytest.mark.parametrize(
282-
'n, lim, ref',
283-
[
284-
(
285-
2,
286-
(0, 4),
287-
[0.5, 1.5, 2.5, 3.5]
288-
),
289-
(
290-
4,
291-
(0, 2),
292-
[0.25, 0.5, 0.75, 1.25, 1.5, 1.75]
293-
),
294-
(
295-
10,
296-
(0, 1),
297-
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
298-
),
299-
],
300-
)
301-
def test_number_of_minor_ticks_ndivs_int(self, n, lim, ref):
302-
fig, ax = plt.subplots()
303-
ax.set_xlim(*lim)
304-
ax.set_ylim(*lim)
305-
ax.xaxis.set_major_locator(mticker.MultipleLocator(1))
306-
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(n))
307-
ax.yaxis.set_major_locator(mticker.MultipleLocator(1))
308-
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(n))
309-
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref)
310-
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
311-
312258

313259
class TestLogLocator:
314260
def test_basic(self):

0 commit comments

Comments
 (0)