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

Skip to content

Commit 0ed8a8c

Browse files
committed
TST: extend tests of remove_overlapping_locs
1 parent 21c254b commit 0ed8a8c

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,11 @@ def minorticksubplot(xminor, yminor, i):
925925
minorticksubplot(True, True, 4)
926926

927927

928-
def test_remove_overlap():
928+
@pytest.mark.parametrize('remove_overlapping_locs, expected_num',
929+
((True, 6),
930+
(None, 6), # this tests the default
931+
(False, 9)))
932+
def test_remove_overlap(remove_overlapping_locs, expected_num):
929933
import numpy as np
930934
import matplotlib.dates as mdates
931935

@@ -940,7 +944,28 @@ def test_remove_overlap():
940944

941945
ax.xaxis.set_minor_locator(mdates.HourLocator((0, 6, 12, 18)))
942946
ax.xaxis.set_minor_formatter(mdates.DateFormatter('%H:%M'))
943-
944-
assert len(ax.xaxis.get_minorticklocs()) == 6
945-
ax.xaxis.remove_overlapping_locs = False
946-
assert len(ax.xaxis.get_minorticklocs()) == 9
947+
# force there to be extra ticks
948+
ax.xaxis.get_minor_ticks(15)
949+
if remove_overlapping_locs is not None:
950+
ax.xaxis.remove_overlapping_locs = remove_overlapping_locs
951+
952+
# check that getter/setter exists
953+
current = ax.xaxis.remove_overlapping_locs
954+
assert (current == ax.xaxis.get_remove_overlapping_locs())
955+
plt.setp(ax.xaxis, remove_overlapping_locs=current)
956+
new = ax.xaxis.remove_overlapping_locs
957+
assert (new == ax.xaxis.remove_overlapping_locs)
958+
959+
# check that the accessors filter correctly
960+
# this is the method that does the actual filtering
961+
assert len(ax.xaxis.get_minorticklocs()) == expected_num
962+
# these three are derivative
963+
assert len(ax.xaxis.get_minor_ticks()) == expected_num
964+
assert len(ax.xaxis.get_minorticklabels()) == expected_num
965+
assert len(ax.xaxis.get_minorticklines()) == expected_num*2
966+
967+
# force a draw to call _update_ticks under the hood
968+
fig.canvas.draw()
969+
# check that the correct number of ticks report them selves as
970+
# visible
971+
assert sum(t.get_visible() for t in ax.xaxis.minorTicks) == expected_num

0 commit comments

Comments
 (0)