Add some UT for Date.set2_... and fix bugs

Cut and paste is evil ;-) fix bugs before I refactor the code...

svn: r23054
This commit is contained in:
Vassilii Khachaturov 2013-09-08 19:22:40 +00:00
parent 14a69143e1
commit 7e04c4b136
2 changed files with 50 additions and 2 deletions

View File

@ -1369,7 +1369,8 @@ class Date(object):
dv[Date._POS_RMON] = dv[Date._POS_RMON] % 12 dv[Date._POS_RMON] = dv[Date._POS_RMON] % 12
self.dateval = tuple(dv) self.dateval = tuple(dv)
if day != 0 or dv[Date._POS_RDAY] > 28: if day != 0 or dv[Date._POS_RDAY] > 28:
self.set2_yr_mon_day(*self.offset(day)) stop = Date(dv[Date._POS_RYR], dv[Date._POS_RMON], dv[Date._POS_RDAY])
self.set2_yr_mon_day(*stop.offset(day))
def copy_offset_ymd(self, year=0, month=0, day=0): def copy_offset_ymd(self, year=0, month=0, day=0):
""" """
@ -1399,7 +1400,7 @@ class Date(object):
retval.set_yr_mon_day(year, month, day) retval.set_yr_mon_day(year, month, day)
if (self.get_modifier() == Date.MOD_RANGE or if (self.get_modifier() == Date.MOD_RANGE or
self.get_modifier() == Date.MOD_SPAN): self.get_modifier() == Date.MOD_SPAN):
retval.set2_yr_mon_day_offset(year, month, day) retval.set2_yr_mon_day(year, month, day)
return retval return retval
def set_year(self, year): def set_year(self, year):

View File

@ -422,6 +422,53 @@ class SwedishDateTest(BaseDateTest):
self.assertEqual(date.sortval, self.assertEqual(date.sortval,
date.to_calendar('gregorian').sortval) date.to_calendar('gregorian').sortval)
class Test_set2(BaseDateTest):
"""
Test the Date.set2_... setters -- the ones to manipulate the 2nd date
of a compound date
"""
def setUp(self):
self.date = d = Date()
d.set(Date.QUAL_NONE, Date.MOD_RANGE, Date.CAL_GREGORIAN,
#d m y sl--d m y sl
(1, 1, 2000, 0, 1, 1, 2010, 0))
def testStartStopSanity(self):
start,stop = self.date.get_start_stop_range()
self.assertEqual(start, (2000, 1, 1))
self.assertEqual(stop, (2010, 1, 1))
def test_set2_ymd_overrides_stop_date(self):
self.date.set2_yr_mon_day(2013, 2, 2)
start,stop = self.date.get_start_stop_range()
self.assertEqual(start, (2000, 1, 1))
self.assertEqual(stop, (2013, 2, 2))
def test_set2_ymd_overrides_stop_date(self):
self.date.set2_yr_mon_day(2013, 2, 2)
start,stop = self.date.get_start_stop_range()
self.assertEqual(start, (2000, 1, 1))
self.assertEqual(stop, (2013, 2, 2))
def test_set2_ymd_offset_updates_stop_date(self):
self.date.set2_yr_mon_day_offset(+7, +5, +5)
start,stop = self.date.get_start_stop_range()
self.assertEqual(start, (2000, 1, 1))
self.assertEqual(stop, (2017, 6, 6))
def test_copy_offset_ymd_preserves_orig(self):
copied = self.date.copy_offset_ymd(year=-1)
self.testStartStopSanity()
start,stop = copied.get_start_stop_range()
self.assertEqual(start, (1999, 1, 1))
self.assertEqual(stop, (2009, 1, 1))
def test_copy_ymd_preserves_orig(self):
copied = self.date.copy_ymd(year=1000, month=10, day=10)
self.testStartStopSanity()
start,stop = copied.get_start_stop_range()
self.assertEqual(start, (1000, 10, 10))
self.assertEqual(stop, (1000, 10, 10))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()