[date] Fixed: wrong incrementation of month in date_range function (closes #186698).

Add a unit test.

authorDamien Garaud <damien.garaud@logilab.fr>
changeset9450099defff
branchdefault
phasepublic
hiddenno
parent revision#e0434df41a2e [testlib] handle skips in setUp and tearDown
child revision#f52d0719609c prepare 0.60.1
files modified by this revision
date.py
test/unittest_date.py
# HG changeset patch
# User Damien Garaud <damien.garaud@logilab.fr>
# Date 1383208585 -3600
# Thu Oct 31 09:36:25 2013 +0100
# Node ID 9450099defff4bfe5a487deeae2362babeb65cf9
# Parent e0434df41a2eeef6bb97707ed941a7210c8866a7
[date] Fixed: wrong incrementation of month in date_range function (closes #186698).

Add a unit test.

diff --git a/date.py b/date.py
@@ -186,12 +186,12 @@
1      assert not (incday and incmonth)
2      begin = todate(begin)
3      end = todate(end)
4      if incmonth:
5          while begin < end:
6 +            yield begin
7              begin = next_month(begin, incmonth)
8 -            yield begin
9      else:
10          incr = get_step(begin, incday or 1)
11          while begin < end:
12             yield begin
13             begin += incr
diff --git a/test/unittest_date.py b/test/unittest_date.py
@@ -136,10 +136,17 @@
14      def test_ticks2datetime_before_1900(self):
15          ticks = -2209075200000
16          date = ticks2datetime(ticks)
17          self.assertEqual(ustrftime(date, '%Y-%m-%d'), u'1899-12-31')
18 
19 +    def test_month(self):
20 +        """enumerate months"""
21 +        r = list(date_range(self.datecls(2006, 5, 6), self.datecls(2006, 8, 27),
22 +                            incmonth=True))
23 +        expected = [self.datecls(2006, 5, 6), self.datecls(2006, 6, 1), self.datecls(2006, 7, 1), self.datecls(2006, 8, 1)]
24 +        self.assertListEqual(expected, r)
25 +
26 
27  class MxDateTC(DateTC):
28      datecls = mxDate
29      datetimecls = mxDateTime
30      timedeltacls = RelativeDateTime