[Python-checkins] python/nondist/sandbox/datetime test_both.py,1.34,1.35 test_datetime.py,1.53,1.54

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月04日 15:08:57 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv19359
Modified Files:
	test_both.py test_datetime.py 
Log Message:
Moved the beefy test_ordinal_conversions() from test_datetime into
test_both, replacing the latter's weaker version (it had a crippled
version because the C date type didn't support an ordinal->date
method before today). That was the last remaining date test in
test_datetime, so removed the TestDate class from test_datetime too.
Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** test_both.py	4 Dec 2002 22:49:04 -0000	1.34
--- test_both.py	4 Dec 2002 23:08:47 -0000	1.35
***************
*** 326,352 ****
 # first example from "Calendrical Calculations"
 (1945, 11, 12, 710347)]:
! d = date(y, m, d)
! self.assertEqual(d.toordinal(), n)
 
! # Check first and last days of year exhaustively across the whole
! # range of years date objects support.
! n = 1
! for year in range(MINYEAR, MAXYEAR+1):
! self.assertEqual(date(year, 1, 1).toordinal(), n)
 # Verify that moving back a day gets to the end of year-1.
! if year > MINYEAR:
! self.assertEqual(date(year - 1, 12, 31).toordinal(), n-1)
! n += 365
! n += year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
 
! # Check every day in a leap-year and a non-leap year.
 dim = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
! for year, isleap in (2000, True), (2002, False):
! n = date(year, 1, 1).toordinal()
 for month, maxday in zip(range(1, 13), dim):
 if month == 2 and isleap:
 maxday += 1
 for day in range(1, maxday+1):
! self.assertEqual(date(year, month, day).toordinal(), n)
 n += 1
 
--- 326,359 ----
 # first example from "Calendrical Calculations"
 (1945, 11, 12, 710347)]:
! d = self.theclass(y, m, d)
! self.assertEqual(n, d.toordinal())
! self.assertEqual(d, self.theclass.fromordinal(n))
 
! # Check first and last days of year spottily across the whole
! # range of years supported.
! for year in xrange(MINYEAR, MAXYEAR+1, 7):
! # Verify (year, 1, 1) -> ordinal -> y, m, d is identity.
! d = self.theclass(year, 1, 1)
! n = d.toordinal()
! d2 = self.theclass.fromordinal(n)
! self.assertEqual(d, d2)
 # Verify that moving back a day gets to the end of year-1.
! if year > 1:
! d = self.theclass.fromordinal(n-1)
! d2 = self.theclass(year-1, 12, 31)
! self.assertEqual(d, d2)
! self.assertEqual(d2.toordinal(), n-1)
 
! # Test every day in a leap-year and a non-leap year.
 dim = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
! for year, isleap in (2000, 1), (2002, 0):
! n = self.theclass(year, 1, 1).toordinal()
 for month, maxday in zip(range(1, 13), dim):
 if month == 2 and isleap:
 maxday += 1
 for day in range(1, maxday+1):
! d = self.theclass(year, month, day)
! self.assertEqual(d.toordinal(), n)
! self.assertEqual(d, self.theclass.fromordinal(n))
 n += 1
 
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** test_datetime.py	1 Dec 2002 19:37:28 -0000	1.53
--- test_datetime.py	4 Dec 2002 23:08:49 -0000	1.54
***************
*** 10,56 ****
 MINYEAR, MAXYEAR
 
- 
- class TestDate(unittest.TestCase):
- 
- theclass = date
- 
- # All the other tests here have been moved into test_both. This one
- # relies on stuff only the Python version implements.
- def test_ordinal_conversions(self):
- from datetime import _ymd2ord, _ord2ymd
- 
- # Check some fixed values.
- for y, m, d, n in [(1, 1, 1, 1), # calendar origin
- (0, 12, 31, 0),
- (0, 12, 30, -1),
- # first example from "Calendrical Calculations"
- (1945, 11, 12, 710347)]:
- self.assertEqual(n, _ymd2ord(y, m, d))
- self.assertEqual((y, m, d), _ord2ymd(n))
- 
- # Check first and last days of year exhaustively across 2000 years
- # centered at the origin, and spottily over the whole range of
- # years datetime objects support.
- for year in range(-1001, 1002) + range(MINYEAR, MAXYEAR+1, 7):
- # Verify (year, 1, 1) -> ordinal -> y, m, d is identity.
- n = _ymd2ord(year, 1, 1)
- self.assertEqual((year, 1, 1), _ord2ymd(n))
- # Verify that moving back a day gets to the end of year-1.
- self.assertEqual((year-1, 12, 31), _ord2ymd(n-1))
- self.assertEqual(_ymd2ord(year-1, 12, 31), n-1)
- 
- # Test every day in a leap-year and a non-leap year.
- dim = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- for year, isleap in (2000, 1), (2002, 0):
- n = _ymd2ord(year, 1, 1)
- for month, maxday in zip(range(1, 13), dim):
- if month == 2 and isleap:
- maxday += 1
- for day in range(1, maxday+1):
- self.assertEqual((year, month, day), _ord2ymd(n))
- self.assertEqual(n, _ymd2ord(year, month, day))
- n += 1
- 
- 
 class TestTime(unittest.TestCase):
 
--- 10,13 ----
***************
*** 211,215 ****
 
 
! class TestDateTime(TestDate):
 
 theclass = datetime
--- 168,172 ----
 
 
! class TestDateTime(unittest.TestCase):
 
 theclass = datetime
***************
*** 308,317 ****
 
 def test_suite():
- s2 = unittest.makeSuite(TestDate, 'test')
 s3 = unittest.makeSuite(TestTime, 'test')
 s4 = unittest.makeSuite(TestTimeTZ, 'test')
 s5 = unittest.makeSuite(TestDateTime, 'test')
 s6 = unittest.makeSuite(TestDateTimeTZ, 'test')
! return unittest.TestSuite([s2, s3, s4, s5, s6])
 
 def test_main():
--- 265,273 ----
 
 def test_suite():
 s3 = unittest.makeSuite(TestTime, 'test')
 s4 = unittest.makeSuite(TestTimeTZ, 'test')
 s5 = unittest.makeSuite(TestDateTime, 'test')
 s6 = unittest.makeSuite(TestDateTimeTZ, 'test')
! return unittest.TestSuite([s3, s4, s5, s6])
 
 def test_main():

AltStyle によって変換されたページ (->オリジナル) /