[Zodb-checkins] CVS: StandaloneZConfig/ZConfig/tests - test_datatypes.py:1.14

Barry Warsaw barry at zope.com
Mon Apr 19 09:47:16 EDT 2004


Update of /cvs-repository/StandaloneZConfig/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv7727/ZConfig/tests

Modified Files:
	test_datatypes.py 
Log Message:
Added the timedelta standard datatype, which is similar to time-interval, but
returns a datetime.timedelta instead of a float.

Added test case and documentation.


=== StandaloneZConfig/ZConfig/tests/test_datatypes.py 1.13 => 1.14 ===
--- StandaloneZConfig/ZConfig/tests/test_datatypes.py:1.13	Mon Apr 12 11:27:01 2004
+++ StandaloneZConfig/ZConfig/tests/test_datatypes.py	Mon Apr 19 09:47:12 2004
@@ -17,6 +17,7 @@
 import sys
 import shutil
 import socket
+import datetime
 import tempfile
 import unittest
 
@@ -32,9 +33,9 @@
 try:
     unicode
 except NameError:
-    have_unicode = 0
+    have_unicode = False
 else:
-    have_unicode = 1
+    have_unicode = True
 
 
 class DatatypeTestCase(unittest.TestCase):
@@ -341,6 +342,18 @@
         eq(convert('120h'), 120*60*60)
         eq(convert('120d'), 120*60*60*24)
         raises(ValueError, convert, '120w')
+
+    def test_timedelta(self):
+        eq = self.assertEqual
+        raises = self.assertRaises
+        convert = self.types.get('timedelta')
+        eq(convert('4w'), datetime.timedelta(weeks=4))
+        eq(convert('2d'), datetime.timedelta(days=2))
+        eq(convert('7h'), datetime.timedelta(hours=7))
+        eq(convert('12m'), datetime.timedelta(minutes=12))
+        eq(convert('14s'), datetime.timedelta(seconds=14))
+        eq(convert('4w 2d 7h 12m 14s'),
+           datetime.timedelta(2, 14, minutes=12, hours=7, weeks=4))
 
 
 class RegistryTestCase(unittest.TestCase):




More information about the Zodb-checkins mailing list