[Zope-Checkins] CVS: Packages/ZODB/tests - testTimeStamp.py:1.4.34.2

Tim Peters tim.one at comcast.net
Fri Jul 2 18:33:53 EDT 2004


Update of /cvs-repository/Packages/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv29071/ZODB/tests

Modified Files:
      Tag: Zope-2_7-branch
	testTimeStamp.py 
Log Message:
Collector #1397: testTimeStamp fails on FreeBSD

The checkFullTimeStamp() test was sensitive to unique mktime() behavior
on FreeBSD.  See:

http://lists.freebsd.org/pipermail/freebsd-standards/2003-November/000268.html 

The purpose of this test is to exercise ZODB's TimeStamp object, so got
rid of dependence on platform mktime() and time.timezone quirks --
TimeStamp works in GMT, so how mktime() treats tm_isdst should be
irrelevant in all TimeStamp tests.

Also added a comment about the highly non-obvious numeric characteristics
of TimeStamp's treatment of seconds (round-tripping is surprisingly
inaccurate, but for a real reason).


=== Packages/ZODB/tests/testTimeStamp.py 1.4.34.1 => 1.4.34.2 ===
--- Packages/ZODB/tests/testTimeStamp.py:1.4.34.1	Mon Sep 15 17:26:57 2003
+++ Packages/ZODB/tests/testTimeStamp.py	Fri Jul  2 18:33:53 2004
@@ -41,16 +41,28 @@
         self.assertEquals(dy, t[2])
 
     def checkFullTimeStamp(self):
-        t = time.gmtime()
+        native_ts = int(time.time()) # fractional seconds get in the way
+        t = time.gmtime(native_ts)   # the corresponding GMT struct tm
         ts = TimeStamp(*t[:6])
 
-        # XXX floating point comparison
-        self.assertEquals(ts.timeTime() + time.timezone, time.mktime(t))
+        # Seconds are stored internally via (conceptually) multiplying by
+        # 2**32 then dividing by 60, ending up with a 32-bit integer.
+        # While this gives a lot of room for cramming many distinct
+        # TimeStamps into a second, it's not good at roundtrip accuracy.
+        # For example, 1 second is stored as int(2**32/60) == 71582788.
+        # Converting back gives 71582788*60.0/2**32 == 0.9999999962747097.
+        # In general, we can lose up to 0.999... to trunction during
+        # storing, creating an absolute error up to about 1*60.0/2**32 ==
+        # 0.000000014 on the seconds value we get back.  This is so even
+        # when we have an exact integral second value going in (as we
+        # do in this test), so we can't expect equality in any comparison
+        # involving seconds.  Minutes (etc) are stored exactly, so we
+        # can expect equality for those.
 
+        self.assert_(abs(ts.timeTime() - native_ts) < EPSILON)
         self.assertEqual(ts.year(), t[0])
         self.assertEqual(ts.month(), t[1])
         self.assertEqual(ts.day(), t[2])
-
         self.assertEquals(ts.hour(), t[3])
         self.assertEquals(ts.minute(), t[4])
         self.assert_(abs(ts.second() - t[5]) < EPSILON)



More information about the Zope-Checkins mailing list