[Python-checkins] python/dist/src/Lib/test test_datetime.py,1.41,1.42

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Fri, 16 May 2003 19:25:23 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv31716/lib/test

Modified Files:
	test_datetime.py 
Log Message:
test_subclass_date():  Beefed this up, to check that new instance
attributes and methods work, that new arguments can be passed to the
constructor, and that inherited methods and attrs still work.  Added
XXX comments about what to do when datetime becomes usably subclassable
too (it's not yet).


Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_datetime.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** test_datetime.py	14 Apr 2003 22:01:58 -0000	1.41
--- test_datetime.py	17 May 2003 02:25:20 -0000	1.42
***************
*** 481,488 ****
  
      def test_subclass_date(self):
          class C(date):
              theAnswer = 42
!         dt = C(2003, 4, 14)
!         self.assertEqual(dt.__class__, C)
  
  class TestDate(HarmlessMixedComparison):
--- 481,513 ----
  
      def test_subclass_date(self):
+ 
+         # XXX When datetime becomes usably subclassable, uncomment the
+         # XXX "self.theclass" lines and move this into TestDate.
+         # class C(self.theclass):
          class C(date):
              theAnswer = 42
! 
!             def __new__(cls, *args, **kws):
!                 temp = kws.copy()
!                 extra = temp.pop('extra')
!                 # result = self.theclass.__new__(cls, *args, **temp)
!                 result = date.__new__(cls, *args, **temp)
!                 result.extra = extra
!                 return result
! 
!             def newmeth(self, start):
!                 return start + self.year + self.month
! 
!         args = 2003, 4, 14
! 
!         # dt1 = self.theclass(*args)
!         dt1 = date(*args)
!         dt2 = C(*args, **{'extra': 7})
! 
!         self.assertEqual(dt2.__class__, C)
!         self.assertEqual(dt2.theAnswer, 42)
!         self.assertEqual(dt2.extra, 7)
!         self.assertEqual(dt1.toordinal(), dt2.toordinal())
!         self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7)
  
  class TestDate(HarmlessMixedComparison):
***************
*** 977,980 ****
--- 1002,1006 ----
          base = cls(2000, 2, 29)
          self.assertRaises(ValueError, base.replace, year=2001)
+ 
  
  #############################################################################