[Zope-Checkins] CVS: Zope3/lib/python/Zope/Misc/tests - __init__.py:1.2 testDateTimeParse.py:1.2 testGetDescr.py:1.2 test_standard_dates.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:29:59 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Misc/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Misc/tests

Added Files:
	__init__.py testDateTimeParse.py testGetDescr.py 
	test_standard_dates.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.

=== Zope3/lib/python/Zope/Misc/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+


=== Zope3/lib/python/Zope/Misc/tests/testDateTimeParse.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+import unittest, sys
+from Zope.Misc.DateTimeParse import parse, time, DateTimeError
+
+class Test(unittest.TestCase):
+
+    def testParse(self):
+        from Zope.Misc.DateTimeParse import parse
+
+        self.assertEqual(parse('1999 12 31')[:6],
+                         (1999, 12, 31, 0, 0, 0))
+        self.assertEqual(parse('1999 12 31 EST'),
+                         (1999, 12, 31, 0, 0, 0, 'EST'))
+        self.assertEqual(parse('Dec 31, 1999')[:6],
+                         (1999, 12, 31, 0, 0, 0))
+        self.assertEqual(parse('Dec 31 1999')[:6],
+                         (1999, 12, 31, 0, 0, 0))
+        self.assertEqual(parse('Dec 31 1999')[:6],
+                         (1999, 12, 31, 0, 0, 0))
+        self.assertEqual(parse('1999/12/31 1:2:3')[:6],
+                         (1999, 12, 31, 1, 2, 3))
+        self.assertEqual(parse('1999-12-31 1:2:3')[:6],
+                         (1999, 12, 31, 1, 2, 3))
+        self.assertEqual(parse('1999-12-31T01:02:03')[:6],
+                         (1999, 12, 31, 1, 2, 3))
+        self.assertEqual(parse('1999-31-12 1:2:3')[:6],
+                         (1999, 12, 31, 1, 2, 3))
+        self.assertEqual(parse('1999-31-12 1:2:3.456')[:5],
+                         (1999, 12, 31, 1, 2))
+        self.assertEqual(int(parse('1999-31-12 1:2:3.456')[5]*1000+.000001),
+                         3456)
+        self.assertEqual(parse('1999-12-31T01:02:03.456')[:5],
+                         (1999, 12, 31, 1, 2))
+        self.assertEqual(int(parse('1999-12-31T01:02:03.456')[5]*1000+.000001),
+                         3456)
+        self.assertEqual(parse('Tue, 24 Jul 2001 09:41:03 -0400'),
+                         (2001, 7, 24, 9, 41, 3, '-0400'))
+
+    def testTime(self):
+        from time import gmtime
+        from Zope.Misc.DateTimeParse import time
+        self.assertEqual(gmtime(time('1999 12 31 GMT'))[:6],
+                         (1999, 12, 31, 0, 0, 0))
+        self.assertEqual(gmtime(time('1999 12 31 EST'))[:6],
+                         (1999, 12, 31, 5, 0, 0))
+        self.assertEqual(gmtime(time('1999 12 31 -0500'))[:6],
+                         (1999, 12, 31, 5, 0, 0))
+        self.assertEqual(gmtime(time('1999-12-31T00:11:22Z'))[:6],
+                         (1999, 12, 31, 0, 11, 22))
+        self.assertEqual(gmtime(time('1999-12-31T01:11:22+01:00'))[:6],
+                         (1999, 12, 31, 0, 11, 22))
+
+    def testBad(self):
+        from Zope.Misc.DateTimeParse import time, DateTimeError
+        self.assertRaises(DateTimeError, parse, '1999-31-12 1:2:63.456')
+        self.assertRaises(DateTimeError, parse, '1999-31-13 1:2:3.456')
+        self.assertRaises(DateTimeError, parse, '1999-2-30 1:2:3.456')
+        self.assertRaises(DateTimeError, parse, 'April 31, 1999 1:2:3.456')
+
+    def testLeap(self):
+        from Zope.Misc.DateTimeParse import time, DateTimeError
+        self.assertRaises(DateTimeError, parse, '1999-2-29 1:2:3.456')
+        self.assertRaises(DateTimeError, parse, '1900-2-29 1:2:3.456')
+        self.assertEqual(parse('2000-02-29 1:2:3')[:6],
+                         (2000, 2, 29, 1, 2, 3))
+        self.assertEqual(parse('2004-02-29 1:2:3')[:6],
+                         (2004, 2, 29, 1, 2, 3))
+        
+
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/lib/python/Zope/Misc/tests/testGetDescr.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+Test GetDescr.
+
+Revision information:
+$Id$
+"""
+
+import unittest
+from Zope.Misc.GetDescr import GetDescr
+
+class TestGetDescr(unittest.TestCase):
+
+    def test_errors(self):
+        class C: pass
+        # obj not a new-style instance
+        self.assertRaises(TypeError, GetDescr, C(), "foo")
+        # name not a string
+        self.assertRaises(TypeError, GetDescr, 0, 0)
+
+    def test_simple(self):
+        # Simple cases
+        class C(object):
+            def foo(self): pass
+        c = C()
+        self.assertEqual(GetDescr(c, "foo"), C.__dict__["foo"])
+        self.assertEqual(GetDescr(c, "bar"), None)
+        c.bar = 12
+        self.assertEqual(GetDescr(c, "bar"), None)
+        c.foo = 12
+        self.assertEqual(GetDescr(c, "foo"), None)
+        # Make sure method overrides overrid
+        class D(C):
+            def foo(self): pass
+        d = D()
+        self.assertEqual(GetDescr(d, "foo"), D.__dict__["foo"])
+        # Make sure properties always win
+        class E(C):
+            foo = property(lambda self: 42, lambda self, value: None)
+        e = E()
+        self.assertEqual(GetDescr(e, "foo"), E.__dict__["foo"])
+        e.foo = 12 # Ignored
+        self.assertEqual(e.foo, 42)
+        self.assertEqual(GetDescr(e, "foo"), E.__dict__["foo"])
+        e.__dict__["foo"] = 23 # Still ignored!
+        self.assertEqual(e.foo, 42)
+        self.assertEqual(GetDescr(e, "foo"), E.__dict__["foo"])
+
+def test_suite():
+    return unittest.makeSuite(TestGetDescr)
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/Misc/tests/test_standard_dates.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+import unittest, sys, time
+
+from Zope.Misc.DateTimeParse import time
+
+class Test(unittest.TestCase):
+
+    def testiso8601_date(self):
+        from Zope.Misc.standard_dates import iso8601_date
+        self.assertEqual(iso8601_date(time("2000-01-01T01:01:01.234Z")),
+                         "2000-01-01T01:01:01Z")
+
+    def testrfc850_date(self):
+        from Zope.Misc.standard_dates import rfc850_date
+        self.assertEqual(rfc850_date(time("2002-01-12T01:01:01.234Z")),
+                         "Saturday, 12-Jan-02 01:01:01 GMT")
+
+    def testrfc1123_date(self):
+        from Zope.Misc.standard_dates import rfc1123_date
+        self.assertEqual(rfc1123_date(time("2002-01-12T01:01:01.234Z")),
+                         "Sat, 12 Jan 2002 01:01:01 GMT")
+
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())