[Zope3-checkins] CVS: Zope3/src/datetime/tests - test_datetime.py:1.8
Tim Peters
tim.one@comcast.net
Mon, 30 Dec 2002 14:45:54 -0500
Update of /cvs-repository/Zope3/src/datetime/tests
In directory cvs.zope.org:/tmp/cvs-serv5072/src/datetime/tests
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 (but I have to pause to bring the 2.3 C implementation into
synch with this change first).
=== Zope3/src/datetime/tests/test_datetime.py 1.7 => 1.8 ===
--- Zope3/src/datetime/tests/test_datetime.py:1.7 Mon Dec 30 12:38:27 2002
+++ Zope3/src/datetime/tests/test_datetime.py Mon Dec 30 14:45:53 2002
@@ -1565,6 +1565,23 @@
# must be legit (which is true for timetz and datetimetz).
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
self.assertRaises(TypeError, cls, 1, 1, 1, tzinfo=12)
@@ -1685,22 +1702,26 @@
self.assertEqual(got, expected)
# 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)
+ # 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)
class TestTimeTZ(TestTime, TZInfoBase):
@@ -2545,7 +2566,7 @@
return self.stdoffset + self.dst(dt)
def dst(self, dt):
- if dt is None or isinstance(dt, time) or dt.tzinfo is None:
+ if dt is None or dt.tzinfo is None:
# An exception instead may be sensible here, in one or more of
# the cases.
return ZERO