Skip to content

Commit 8c665bf

Browse files
committed
Add test for year locator
1 parent 7b59cb2 commit 8c665bf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/matplotlib/tests/test_dates.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,41 @@ def test_yearlocator_pytz():
964964
assert st == expected
965965

966966

967+
def test_YearLocator():
968+
def _create_year_locator(date1, date2, **kwargs):
969+
locator = mdates.YearLocator(**kwargs)
970+
locator.create_dummy_axis()
971+
locator.set_view_interval(mdates.date2num(date1),
972+
mdates.date2num(date2))
973+
return locator
974+
975+
d1 = datetime.datetime(1990, 1, 1)
976+
results = ([datetime.timedelta(weeks=52 * 200),
977+
{'base': 20, 'month': 1, 'day': 1},
978+
['1980-01-01 00:00:00+00:00', '2000-01-01 00:00:00+00:00',
979+
'2020-01-01 00:00:00+00:00', '2040-01-01 00:00:00+00:00',
980+
'2060-01-01 00:00:00+00:00', '2080-01-01 00:00:00+00:00',
981+
'2100-01-01 00:00:00+00:00', '2120-01-01 00:00:00+00:00',
982+
'2140-01-01 00:00:00+00:00', '2160-01-01 00:00:00+00:00',
983+
'2180-01-01 00:00:00+00:00', '2200-01-01 00:00:00+00:00']
984+
],
985+
[datetime.timedelta(weeks=52 * 200),
986+
{'base': 20, 'month': 5, 'day': 16},
987+
['1980-05-16 00:00:00+00:00', '2000-05-16 00:00:00+00:00',
988+
'2020-05-16 00:00:00+00:00', '2040-05-16 00:00:00+00:00',
989+
'2060-05-16 00:00:00+00:00', '2080-05-16 00:00:00+00:00',
990+
'2100-05-16 00:00:00+00:00', '2120-05-16 00:00:00+00:00',
991+
'2140-05-16 00:00:00+00:00', '2160-05-16 00:00:00+00:00',
992+
'2180-05-16 00:00:00+00:00', '2200-05-16 00:00:00+00:00']
993+
],
994+
)
995+
996+
for delta, arguments, expected in results:
997+
d2 = d1 + delta
998+
locator = _create_year_locator(d1, d2, **arguments)
999+
assert list(map(str, mdates.num2date(locator()))) == expected
1000+
1001+
9671002
def test_DayLocator():
9681003
with pytest.raises(ValueError):
9691004
mdates.DayLocator(interval=-1)

0 commit comments

Comments
 (0)