|
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 |
|
7 | 7 | @image_comparison(baseline_images=['date_empty'])
|
8 | 8 | def test_date_empty():
|
@@ -132,6 +132,31 @@ def test_DateFormatter():
|
132 | 132 | ax.autoscale_view()
|
133 | 133 | fig.autofmt_xdate()
|
134 | 134 |
|
| 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 | + |
135 | 160 | #@image_comparison(baseline_images=['empty_date_bug'])
|
136 | 161 | @cleanup
|
137 | 162 | @knownfailureif(True)
|
|
0 commit comments