SVN: ZODB/trunk/src/ZEO/ Normalize ctime for tests to avoid spurios test failures in

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20100713101612.CA64C941DF__14677.0434840166$1279016181$gmane$org@cvs.zope.org>
Log message for revision 114691:
  Normalize ctime for tests to avoid spurios test failures in
  non-standart ;) time zones.
  
  Cleanup trailing whitespace in verbose stats output.
  

Changed:
  U   ZODB/trunk/src/ZEO/scripts/cache_simul.py
  U   ZODB/trunk/src/ZEO/scripts/cache_stats.py
  U   ZODB/trunk/src/ZEO/tests/test_cache.py

-=-
Modified: ZODB/trunk/src/ZEO/scripts/cache_simul.py
===================================================================
--- ZODB/trunk/src/ZEO/scripts/cache_simul.py	2010-07-13 10:11:47 UTC (rev 114690)
+++ ZODB/trunk/src/ZEO/scripts/cache_simul.py	2010-07-13 10:16:12 UTC (rev 114691)
@@ -41,6 +41,9 @@
 
 from ZODB.utils import z64, u64
 
+# we assign ctime locally to facilitate test replacement!
+from time import ctime
+
 def usage(msg):
     print >> sys.stderr, msg
     print >> sys.stderr, __doc__
@@ -250,7 +253,7 @@
 
     def report(self):
         self.nreports += 1
-        args = (time.ctime(self.ts0)[4:-8],
+        args = (ctime(self.ts0)[4:-8],
                 duration(self.ts1 - self.ts0),
                 self.loads, self.hits, self.invals, self.writes,
                 hitrate(self.loads, self.hits))
@@ -267,7 +270,7 @@
         else:
             self.report()
             args = (
-                time.ctime(self.epoch)[4:-8],
+                ctime(self.epoch)[4:-8],
                 duration(self.ts1 - self.epoch),
                 self.total_loads,
                 self.total_hits,

Modified: ZODB/trunk/src/ZEO/scripts/cache_stats.py
===================================================================
--- ZODB/trunk/src/ZEO/scripts/cache_stats.py	2010-07-13 10:11:47 UTC (rev 114690)
+++ ZODB/trunk/src/ZEO/scripts/cache_stats.py	2010-07-13 10:16:12 UTC (rev 114691)
@@ -62,6 +62,9 @@
 import struct
 from types import StringType
 
+# we assign ctime locally to facilitate test replacement!
+from time import ctime
+
 def usage(msg):
     print >> sys.stderr, msg
     print >> sys.stderr, __doc__
@@ -206,14 +209,14 @@
                     bysizew[dlen] = d = bysizew.get(dlen) or {}
                     d[oid] = d.get(oid, 0) + 1
             if verbose:
-                print "%s %02x %s %016x %016x %c %s" % (
-                    time.ctime(ts)[4:-5],
+                print "%s %02x %s %016x %016x %c%s" % (
+                    ctime(ts)[4:-5],
                     code,
                     oid_repr(oid),
                     U64(start_tid),
                     U64(end_tid),
                     version,
-                    dlen and str(dlen) or "")
+                    dlen and (' '+str(dlen)) or "")
             if code & 0x70 == 0x20:
                 oids[oid] = oids.get(oid, 0) + 1
                 total_loads += 1
@@ -224,7 +227,7 @@
                 thisinterval = ts // interval
                 h0 = he = ts
                 if not quiet:
-                    print time.ctime(ts)[4:-5],
+                    print ctime(ts)[4:-5],
                     print '='*20, "Restart", '='*20
     except KeyboardInterrupt:
         print "\nInterrupted.  Stats so far:\n"
@@ -246,8 +249,8 @@
         print "Read %s trace records (%s bytes) in %.1f seconds" % (
             addcommas(records), addcommas(end_pos), rte-rt0)
         print "Versions:   %s records used a version" % addcommas(versions)
-        print "First time: %s" % time.ctime(t0)
-        print "Last time:  %s" % time.ctime(te)
+        print "First time: %s" % ctime(t0)
+        print "Last time:  %s" % ctime(te)
         print "Duration:   %s seconds" % addcommas(te-t0)
         print "Data recs:  %s (%.1f%%), average size %d bytes" % (
             addcommas(datarecords),
@@ -326,7 +329,7 @@
         hr = 'n/a'
 
     print "%s-%s %7s %7s %7s %7s %7s" % (
-        time.ctime(h0)[4:-8], time.ctime(he)[14:-8],
+        ctime(h0)[4:-8], ctime(he)[14:-8],
         loads, hits, invals, writes, hr)
 
 def hitrate(bycode):

Modified: ZODB/trunk/src/ZEO/tests/test_cache.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/test_cache.py	2010-07-13 10:11:47 UTC (rev 114690)
+++ ZODB/trunk/src/ZEO/tests/test_cache.py	2010-07-13 10:16:12 UTC (rev 114691)
@@ -537,6 +537,11 @@
 
     >>> import ZEO.scripts.cache_stats, ZEO.scripts.cache_simul
 
+    >>> def ctime(t):
+    ...     return time.asctime(time.gmtime(t-3600*4))
+    >>> ZEO.scripts.cache_stats.ctime = ctime
+    >>> ZEO.scripts.cache_stats.simul = ctime
+
     ############################################################
     Stats
 
@@ -597,26 +602,26 @@
     >>> ZEO.scripts.cache_stats.main('-v cache.trace'.split())
     ... # doctest: +ELLIPSIS
                        loads    hits  inv(h)  writes hitrate
-    Jul 11 12:11:41 00 '' 0000000000000000 0000000000000000 - 
+    Jul 11 12:11:41 00 '' 0000000000000000 0000000000000000 -
     Jul 11 12:11-11       0       0       0       0     n/a
     Jul 11 12:11:41 ==================== Restart ====================
-    Jul 11 12:11:42 10             1065 0000000000000002 0000000000000000 - 
+    Jul 11 12:11:42 10             1065 0000000000000002 0000000000000000 -
     Jul 11 12:11:42 52             1065 0000000000000002 0000000000000000 - 245
-    Jul 11 12:11:43 20              947 0000000000000000 0000000000000000 - 
+    Jul 11 12:11:43 20              947 0000000000000000 0000000000000000 -
     Jul 11 12:11:43 52              947 0000000000000002 0000000000000000 - 602
-    Jul 11 12:11:44 20             124b 0000000000000000 0000000000000000 - 
+    Jul 11 12:11:44 20             124b 0000000000000000 0000000000000000 -
     Jul 11 12:11:44 52             124b 0000000000000002 0000000000000000 - 1418
     ...
     Jul 11 15:14:55 52             10cc 00000000000003e9 0000000000000000 - 1306
-    Jul 11 15:14:56 20             18a7 0000000000000000 0000000000000000 - 
+    Jul 11 15:14:56 20             18a7 0000000000000000 0000000000000000 -
     Jul 11 15:14:56 52             18a7 00000000000003e9 0000000000000000 - 1610
     Jul 11 15:14:57 22             18b5 000000000000031d 0000000000000000 - 1636
-    Jul 11 15:14:58 20              b8a 0000000000000000 0000000000000000 - 
+    Jul 11 15:14:58 20              b8a 0000000000000000 0000000000000000 -
     Jul 11 15:14:58 52              b8a 00000000000003e9 0000000000000000 - 838
     Jul 11 15:14:59 22             1085 0000000000000357 0000000000000000 - 217
     Jul 11 15:00-14     818     292      30     608   35.7%
     Jul 11 15:15:00 22             1072 000000000000037e 0000000000000000 - 204
-    Jul 11 15:15:01 20             16c5 0000000000000000 0000000000000000 - 
+    Jul 11 15:15:01 20             16c5 0000000000000000 0000000000000000 -
     Jul 11 15:15:01 52             16c5 00000000000003e9 0000000000000000 - 1712
     Jul 11 15:15-15       2       1       0       1   50.0%
     <BLANKLINE>
@@ -1016,6 +1021,8 @@
 
     >>> del os.environ["ZEO_CACHE_TRACE"]
     >>> time.time = timetime
+    >>> ZEO.scripts.cache_stats.ctime = time.ctime
+    >>> ZEO.scripts.cache_stats.simul = time.ctime
 
 """
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.