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

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:30:40 -0500


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

Added Files:
      Tag: NameGeddon-branch
	__init__.py test_datetime.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/datetime/tests/__init__.py ===
##############################################################################
#
# 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


=== Added File Zope3/src/datetime/tests/test_datetime.py === (2090/2190 lines abridged)
"""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):
        return self.__offset
    def tzname(self, dt):
        return self.__name

[-=- -=- -=- 2090 lines omitted -=- -=- -=-]

        self.assertEqual(t.tm_mday, 1)
        self.assertEqual(t.tm_hour, 23)
        self.assertEqual(t.tm_min, 58)
        self.assertEqual(t.tm_sec, 37)
        self.assertEqual(t.tm_yday, 1)
        self.assertEqual(t.tm_isdst, 0)

    def test_tzinfo_isoformat(self):
        zero = FixedOffset(0, "+00:00")
        plus = FixedOffset(220, "+03:40")
        minus = FixedOffset(-231, "-03:51")
        unknown = FixedOffset(None, "")

        cls = self.theclass
        datestr = '0001-02-03'
        for ofs in None, zero, plus, minus, unknown:
             for us in 0, 987001:
                d = cls(1, 2, 3, 4, 5, 59, us, tzinfo=ofs)
                timestr = '04:05:59' + (us and '.987001' or '')
                ofsstr = ofs is not None and d.tzname() or ''
                tailstr = timestr + ofsstr
                iso = d.isoformat()
                self.assertEqual(iso, datestr + 'T' + tailstr)
                self.assertEqual(iso, d.isoformat('T'))
                self.assertEqual(d.isoformat('k'), datestr + 'k' + tailstr)
                self.assertEqual(str(d), datestr + ' ' + tailstr)


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()