[Zope-Checkins] CVS: Zope/lib/python/BTrees/tests - testBTrees.py:1.14.36.4

Andreas Jung andreas@zope.com
Wed, 5 Sep 2001 09:11:19 -0400


Update of /cvs-repository/Zope/lib/python/BTrees/tests
In directory cvs.zope.org:/tmp/cvs-serv8829/tests

Modified Files:
      Tag: Zope-2_4-branch
	testBTrees.py 
Log Message:
XXBucket.values() returned keys() instead of values.
Also adjusted unittest to catch this problem.


=== Zope/lib/python/BTrees/tests/testBTrees.py 1.14.36.3 => 1.14.36.4 ===
 # 
 ##############################################################################
-import sys, os, time, whrandom
-
-try:
-    sys.path.insert(0, '.')
-    import ZODB
-except:
-    sys.path.insert(0, '../..')
-    import ZODB
+import sys, os, time, random
+import os, sys
+execfile(os.path.join(sys.path[0], 'framework.py'))
 
 from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
 from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
@@ -98,7 +93,6 @@
 from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
 
 from glob import glob
-import os
 
 class Base:
     """ Tests common to all types: sets, buckets, and BTrees """
@@ -208,7 +202,7 @@
         added = {}
         r = range(1000)
         for x in r:
-            k = whrandom.choice(r)
+            k = random.choice(r)
             self.t[k] = x
             added[k] = x
         addl = added.keys()
@@ -220,12 +214,11 @@
 
     def testValuesWorks(self):
         for x in range(100):
-            self.t[x] = x
+            self.t[x] = x*x
         v = self.t.values()
-        i = 0
-        for x in v:
-            assert x == i, (x,i)
-            i = i + 1
+        for i in range(100):
+            assert v[i]==i*i , (i*i,i)
+
             
     def testKeysWorks(self):
         for x in range(100):
@@ -276,7 +269,7 @@
     def testClear(self):
         r = range(100)
         for x in r:
-            rnd = whrandom.choice(r)
+            rnd = random.choice(r)
             self.t[rnd] = 0
         self.t.clear()
         diff = lsubtract(list(self.t.keys()), [])
@@ -287,7 +280,7 @@
         d={}
         l=[]
         for i in range(10000):
-            k=whrandom.randint(-2000, 2000)
+            k=random.randrange(-2000, 2001)
             d[k]=i
             l.append((k, i))
             
@@ -396,7 +389,7 @@
         d={}
         l=[]
         for i in range(10000):
-            k=whrandom.randint(-2000, 2000)
+            k=random.randrange(-2000, 2001)
             d[k]=i
             l.append(k)
             
@@ -502,7 +495,7 @@
         added = {}
         r = range(100)
         for x in r:
-            k = whrandom.choice(r)
+            k = random.choice(r)
             if not added.has_key(k):
                 self.t[k] = x
                 added[k] = 1
@@ -515,7 +508,7 @@
         added = {}
         r = range(100)
         for x in r:
-            k = whrandom.choice(r)
+            k = random.choice(r)
             self.t[k] = x
             added[k] = 1
         addl = added.keys()
@@ -527,12 +520,12 @@
         r = range(1000)
         added = []
         for x in r:
-            k = whrandom.choice(r)
+            k = random.choice(r)
             self.t[k] = x
             added.append(k)
         deleted = []
         for x in r:
-            k = whrandom.choice(r)
+            k = random.choice(r)
             if self.t.has_key(k):
                 del self.t[k]
                 deleted.append(k)
@@ -547,7 +540,7 @@
     def testTargetedDeletes(self):
         r = range(1000)
         for x in r:
-            k = whrandom.choice(r)
+            k = random.choice(r)
             self.t[k] = x
         for x in r:
             try:
@@ -634,7 +627,7 @@
         r = range(100)
         a = {}
         for x in r:
-            rnd = whrandom.choice(r)
+            rnd = random.choice(r)
             self.t[rnd] = 0
             a[rnd] = 0
         diff = lsubtract(list(self.t.keys(0, 100)), a.keys())
@@ -815,15 +808,6 @@
 
     return alltests
 
-def main():
-    alltests=test_suite()
-    runner = TextTestRunner(verbosity=2)
-    runner.run(alltests)
-
-def debug():
-   test_suite().debug()
-    
-
 ## utility functions
 
 def lsubtract(l1, l2):
@@ -836,9 +820,4 @@
 def realseq(itemsob):
     return map(lambda x: x, itemsob)
 
-if __name__=='__main__':
-   if len(sys.argv) > 1:
-      globals()[sys.argv[1]]()
-   else:
-      main()
-
+framework()