10000 Added test fpr drange · sgowda/matplotlib@3dd84af · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dd84af

Browse files
committed
Added test fpr drange
1 parent 06195c3 commit 3dd84af

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lib/matplotlib/tests/test_dates.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
44
import matplotlib.pyplot as plt
5-
from nose.tools import assert_raises
5+
from nose.tools import assert_raises, assert_equal
66

77
@image_comparison(baseline_images=['date_empty'])
88
def test_date_empty():
@@ -132,6 +132,31 @@ def test_DateFormatter():
132132
ax.autoscale_view()
133133
fig.autofmt_xdate()
134134

135+
def test_drange():
136+
'''This test should check if drange works as expected, and if all the rounding errors
137+
are fixed'''
138+
from matplotlib import dates
139+
start = datetime.datetime(2011, 1,1, tzinfo=dates.UTC)
140+
end = datetime.datetime(2011, 1, 2, tzinfo=dates.UTC)
141+
delta = datetime.timedelta(hours=1)
142+
#We expect 24 values in drange(start, end, delta), because drange returns dates from
143+
#an half open interval [start, end)
144+
assert_equal(24, len(dates.drange(start, end, delta)))
145+
146+
#if end is a little bit later, we expect the range to contain one element more
147+
end = end +datetime.timedelta(microseconds=1)
148+
assert_equal(25, len(dates.drange(start, end, delta)))
149+
150+
#reset end
151+
end = datetime.datetime(2011, 1, 2, tzinfo=dates.UTC)
152+
153+
#and tst drange with "complicated" floats:
154+
# 4 hours = 1/6 day, this is an "dangerous" float
155+
delta = datetime.timedelta(hours=4)
156+
daterange = dates.drange(start, end, delta)
157+
assert_equal(6, len(daterange))
158+
assert_equal(dates.num2date(daterange[-1]), end-delta)
159+
135160
#@image_comparison(baseline_images=['empty_date_bug'])
136161
@cleanup
137162
@knownfailureif(True)

0 commit comments

Comments
 (0)
0