[Python-checkins] python/dist/src/Lib/test test_datetime.py,1.15,1.16

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Mon, 30 Dec 2002 12:52:35 -0800


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

Modified Files:
	test_datetime.py 
Log Message:
A step on the way to making tzinfo classes writable by mortals:  get rid
of the timetz case.  A tzinfo method will always see a datetimetz arg,
or None, now.  In the former case, it's still possible that it will get
a datetimetz argument belonging to a different timezone.  That will get
fixed next.


Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_datetime.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** test_datetime.py	30 Dec 2002 17:37:30 -0000	1.15
--- test_datetime.py	30 Dec 2002 20:52:32 -0000	1.16
***************
*** 1558,1561 ****
--- 1558,1578 ----
  class TZInfoBase(unittest.TestCase):
  
+     def test_argument_passing(self):
+         cls = self.theclass
+         # A datetimetz passes itself on, a timetz passes None.
+         class introspective(tzinfo):
+             def tzname(self, dt):    return dt and "real" or "none"
+             def utcoffset(self, dt): return dt and 42 or -42
+             dst = utcoffset
+ 
+         obj = cls(1, 2, 3, tzinfo=introspective())
+ 
+         expected = cls is timetz and "none" or "real"
+         self.assertEqual(obj.tzname(), expected)
+ 
+         expected = timedelta(minutes=(cls is timetz and -42 or 42))
+         self.assertEqual(obj.utcoffset(), expected)
+         self.assertEqual(obj.dst(), expected)
+ 
      def test_bad_tzinfo_classes(self):
          cls = self.theclass
***************
*** 1678,1697 ****
  
          # However, if they're different members, uctoffset is not ignored.
!         d0 = base.replace(minute=3, tzinfo=OperandDependentOffset())
!         d1 = base.replace(minute=9, tzinfo=OperandDependentOffset())
!         d2 = base.replace(minute=11, tzinfo=OperandDependentOffset())
!         for x in d0, d1, d2:
!             for y in d0, d1, d2:
!                 got = cmp(x, y)
!                 if (x is d0 or x is d1) and (y is d0 or y is d1):
!                     expected = 0
!                 elif x is y is d2:
!                     expected = 0
!                 elif x is d2:
!                     expected = -1
!                 else:
!                     assert y is d2
!                     expected = 1
!                 self.assertEqual(got, expected)
  
  
--- 1695,1718 ----
  
          # However, if they're different members, uctoffset is not ignored.
!         # Note that a timetz can't actually have an operand-depedent offset,
!         # though (and timetz.utcoffset() passes None to tzinfo.utcoffset()),
!         # so skip this test for timetz.
!         if cls is not timetz:
!             d0 = base.replace(minute=3, tzinfo=OperandDependentOffset())
!             d1 = base.replace(minute=9, tzinfo=OperandDependentOffset())
!             d2 = base.replace(minute=11, tzinfo=OperandDependentOffset())
!             for x in d0, d1, d2:
!                 for y in d0, d1, d2:
!                     got = cmp(x, y)
!                     if (x is d0 or x is d1) and (y is d0 or y is d1):
!                         expected = 0
!                     elif x is y is d2:
!                         expected = 0
!                     elif x is d2:
!                         expected = -1
!                     else:
!                         assert y is d2
!                         expected = 1
!                     self.assertEqual(got, expected)
  
  
***************
*** 2536,2540 ****
  
      def dst(self, dt):
!         if dt is None or isinstance(dt, time) or dt.tzinfo is None:
              # An exception instead may be sensible here, in one or more of
              # the cases.
--- 2557,2561 ----
  
      def dst(self, dt):
!         if dt is None or dt.tzinfo is None:
              # An exception instead may be sensible here, in one or more of
              # the cases.