[Zodb-checkins] CVS: Packages/ZODB/tests - testTimeStamp.py:22.214.171.124
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
Collector #1397: testTimeStamp fails on FreeBSD
The checkFullTimeStamp() test was sensitive to unique mktime() behavior
on FreeBSD. See:
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 126.96.36.199 => 188.8.131.52 ===
--- Packages/ZODB/tests/testTimeStamp.py:184.108.40.206 Mon Sep 15 17:26:57 2003
+++ Packages/ZODB/tests/testTimeStamp.py Fri Jul 2 18:33:53 2004
@@ -41,16 +41,28 @@
- 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.assert_(abs(ts.second() - t) < EPSILON)
More information about the Zodb-checkins