|
2 | 2 | import numpy as np
|
3 | 3 | from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
|
4 | 4 | import matplotlib.pyplot as plt
|
5 |
| -from nose.tools import assert_raises |
| 5 | +from nose.tools import assert_raises, assert_equal |
6 | 6 | import warnings
|
7 | 7 |
|
8 | 8 | @image_comparison(baseline_images=['date_empty'])
|
@@ -69,7 +69,9 @@ def test_too_many_date_ticks():
|
69 | 69 | # setting equal datetimes triggers and expander call in
|
70 | 70 | # transforms.nonsingular which results in too many ticks in the
|
71 | 71 | # DayLocator. This should trigger a Locator.MAXTICKS RuntimeError
|
72 |
| - warnings.filterwarnings('ignore','Attempting to set identical left==right results\\nin singular transformations; automatically expanding.\\nleft=\d*\.\d*, right=\d*\.\d*',UserWarning,module='matplotlib.axes') |
| 72 | + warnings.filterwarnings('ignore', |
| 73 | + 'Attempting to set identical left==right results\\nin singular transformations; automatically expanding.\\nleft=\d*\.\d*, right=\d*\.\d*', |
| 74 | + UserWarning, module='matplotlib.axes') |
73 | 75 | t0 = datetime.datetime(2000, 1, 20)
|
74 | 76 | tf = datetime.datetime(2000, 1, 20)
|
75 | 77 | fig = plt.figure()
|
@@ -134,6 +136,31 @@ def test_DateFormatter():
|
134 | 136 | ax.autoscale_view()
|
135 | 137 | fig.autofmt_xdate()
|
136 | 138 |
|
| 139 | +def test_drange(): |
| 140 | + '''This test should check if drange works as expected, and if all the rounding errors |
| 141 | + are fixed''' |
| 142 | + from matplotlib import dates |
| 143 | + start = datetime.datetime(2011, 1,1, tzinfo=dates.UTC) |
| 144 | + end = datetime.datetime(2011, 1, 2, tzinfo=dates.UTC) |
| 145 | + delta = datetime.timedelta(hours=1) |
| 146 | + #We expect 24 values in drange(start, end, delta), because drange returns dates from |
| 147 | + #an half open interval [start, end) |
| 148 | + assert_equal(24, len(dates.drange(start, end, delta))) |
| 149 | + |
| 150 | + #if end is a little bit later, we expect the range to contain one element more |
| 151 | + end = end +datetime.timedelta(microseconds=1) |
| 152 | + assert_equal(25, len(dates.drange(start, end, delta))) |
| 153 | + |
| 154 | + #reset end |
| 155 | + end = datetime.datetime(2011, 1, 2, tzinfo=dates.UTC) |
| 156 | + |
| 157 | + #and tst drange with "complicated" floats: |
| 158 | + # 4 hours = 1/6 day, this is an "dangerous" float |
| 159 | + delta = datetime.timedelta(hours=4) |
| 160 | + daterange = dates.drange(start, end, delta) |
| 161 | + assert_equal(6, len(daterange)) |
| 162 | + assert_equal(dates.num2date(daterange[-1]), end-delta) |
| 163 | + |
137 | 164 | #@image_comparison(baseline_images=['empty_date_bug'])
|
138 | 165 | @cleanup
|
139 | 166 | @knownfailureif(True)
|
|
0 commit comments