[Zope3-checkins] CVS: Zope3/src/datetime/tests - __init__.py:1.2 test_datetime.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:14:13 -0500


Update of /cvs-repository/Zope3/src/datetime/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/datetime/tests

Added Files:
	__init__.py test_datetime.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/datetime/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:12 2002
+++ Zope3/src/datetime/tests/__init__.py	Wed Dec 25 09:12:12 2002
@@ -0,0 +1,14 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+# Make this directory a package


=== Zope3/src/datetime/tests/test_datetime.py 1.1 => 1.2 === (2296/2396 lines abridged)
--- /dev/null	Wed Dec 25 09:14:12 2002
+++ Zope3/src/datetime/tests/test_datetime.py	Wed Dec 25 09:12:12 2002
@@ -0,0 +1,2393 @@
+"""Test date/time type."""
+
+import sys
+import unittest
+
+from datetime import MINYEAR, MAXYEAR
+from datetime import timedelta
+from datetime import tzinfo
+from datetime import time, timetz
+from datetime import date, datetime, datetimetz
+
+
+# XXX The test suite uncovered a bug in Python 2.2.2:  if x and y are
+# XXX instances of new-style classes (like date and time) that both
+# XXX define __cmp__, and x is compared to y, and one of the __cmp__
+# XXX implementations raises an exception, the exception can get dropped
+# XXX on the floor when it occurs, and pop up again at some "random" time
+# XXX later (it depends on when the next opcode gets executed that
+# XXX bothers to check).  There isn't a workaround for this, so instead
+# XXX we disable the parts of the tests that trigger it unless
+# XXX CMP_BUG_FIXED is true.  The bug is still there, we simply avoid
+# XXX provoking it here.
+# XXX Guido checked into a fix that will go into 2.2.3.  The bug was
+# XXX already fixed in 2.3 CVS via a different means.
+CMP_BUG_FIXED = sys.version_info >= (2, 2, 3)
+
+#############################################################################
+# module tests
+
+class TestModule(unittest.TestCase):
+
+    def test_constants(self):
+        import datetime
+        self.assertEqual(datetime.MINYEAR, 1)
+        self.assertEqual(datetime.MAXYEAR, 9999)
+
+#############################################################################
+# tzinfo tests
+
+class FixedOffset(tzinfo):
+    def __init__(self, offset, name, dstoffset=42):
+        self.__offset = offset
+        self.__name = name
+        self.__dstoffset = dstoffset
+    def __repr__(self):
+        return self.__name.lower()
+    def utcoffset(self, dt):

[-=- -=- -=- 2296 lines omitted -=- -=- -=-]

+            self.failUnless(x.tzinfo is fnone)
+            self.assertEqual(x.date(), dt.date())
+            self.assertEqual(x.time(), dt.time())
+        # Ditt with None tz.
+        x = dt.astimezone(tz=None)
+        self.failUnless(x.tzinfo is None)
+        self.assertEqual(x.date(), dt.date())
+        self.assertEqual(x.time(), dt.time())
+        # Ditto replacing with same tzinfo.
+        x = dt.astimezone(dt.tzinfo)
+        self.failUnless(x.tzinfo is f44m)
+        self.assertEqual(x.date(), dt.date())
+        self.assertEqual(x.time(), dt.time())
+
+        # Replacing with different tzinfo does adjust.
+        got = dt.astimezone(fm5h)
+        self.failUnless(got.tzinfo is fm5h)
+        self.assertEqual(got.utcoffset(), timedelta(hours=-5))
+        expected = dt - dt.utcoffset()  # in effect, convert to UTC
+        expected += fm5h.utcoffset(dt)  # and from there to local time
+        expected = expected.replace(tzinfo=fm5h) # and attach new tzinfo
+        self.assertEqual(got.date(), expected.date())
+        self.assertEqual(got.time(), expected.time())
+        self.assertEqual(got.timetz(), expected.timetz())
+        self.failUnless(got.tzinfo is expected.tzinfo)
+        self.assertEqual(got, expected)
+
+
+def test_suite():
+    allsuites = [unittest.makeSuite(klass, 'test')
+                 for klass in (TestModule,
+                               TestTZInfo,
+                               TestTimeDelta,
+                               TestDateOnly,
+                               TestDate,
+                               TestDateTime,
+                               TestTime,
+                               TestTimeTZ,
+                               TestDateTimeTZ,
+                              )
+                ]
+    return unittest.TestSuite(allsuites)
+
+def test_main():
+    r = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
+    s = test_suite()
+    r.run(s)
+
+if __name__ == "__main__":
+    test_main()