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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
        testBTrees.py testSetOps.py 
Log Message:

  - Removed all uses of the 'hasattr' builtin from the core, where
    the object being tested derives (or might) from Persistent.
    XXX:  currently, this branch imports a 'safe_hasattr' from ZODB.utils,
    which adds a dependency on ZODB for some packages;  we probably
    need a better location, and perhas a C implementation?


=== Packages/BTrees/tests/testBTrees.py 1.51.8.2 => 1.51.8.2.30.1 ===
--- Packages/BTrees/tests/testBTrees.py:1.51.8.2        Mon Nov 17 17:34:04 2003
+++ Packages/BTrees/tests/testBTrees.py Sat May 28 20:41:30 2005
@@ -28,6 +28,7 @@
 from ZODB.tests.StorageTestBase import removefs
 from ZODB import DB
 from ZODB.MappingStorage import MappingStorage
+from ZODB.utils import safe_hasattr
 
 class Base:
     """ Tests common to all types: sets, buckets, and BTrees """
@@ -58,7 +59,7 @@
             get_transaction().commit()
 
             root2 = self._getRoot()
-            if hasattr(t, 'items'):
+            if safe_hasattr(t, 'items'):
                 self.assertEqual(list(root2[i].items()) , list(t.items()))
             else:
                 self.assertEqual(list(root2[i].keys()) , list(t.keys()))
@@ -77,7 +78,7 @@
             root2 = self._getRoot()
             root2[i]._p_deactivate()
             get_transaction().commit()
-            if hasattr(t, 'items'):
+            if safe_hasattr(t, 'items'):
                 self.assertEqual(list(root2[i].items()) , list(t.items()))
             else:
                 self.assertEqual(list(root2[i].keys()) , list(t.keys()))


=== Packages/BTrees/tests/testSetOps.py 1.13 => 1.13.156.1 ===
--- Packages/BTrees/tests/testSetOps.py:1.13    Tue Jun 25 18:46:42 2002
+++ Packages/BTrees/tests/testSetOps.py Sat May 28 20:41:30 2005
@@ -18,6 +18,7 @@
 from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
 from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
 from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
+from ZODB.utils import safe_hasattr
 
 # Subclasses have to set up:
 #     builders - functions to build inputs, taking an optional keys arg
@@ -53,7 +54,7 @@
             if e in result:
                 result.remove(e)
         # Difference preserves LHS values.
-        if hasattr(x, "values"):
+        if safe_hasattr(x, "values"):
             result = [(k, x[k]) for k in result]
         return result
 
@@ -77,22 +78,22 @@
         for A in self.As:
             for E in self.emptys:
                 C = self.union(A, E)
-                self.assert_(not hasattr(C, "values"))
+                self.assert_(not safe_hasattr(C, "values"))
                 self.assertEqual(list(C), self.Akeys)
 
                 C = self.union(E, A)
-                self.assert_(not hasattr(C, "values"))
+                self.assert_(not safe_hasattr(C, "values"))
                 self.assertEqual(list(C), self.Akeys)
 
     def testEmptyIntersection(self):
         for A in self.As:
             for E in self.emptys:
                 C = self.intersection(A, E)
-                self.assert_(not hasattr(C, "values"))
+                self.assert_(not safe_hasattr(C, "values"))
                 self.assertEqual(list(C), [])
 
                 C = self.intersection(E, A)
-                self.assert_(not hasattr(C, "values"))
+                self.assert_(not safe_hasattr(C, "values"))
                 self.assertEqual(list(C), [])
 
     def testEmptyDifference(self):
@@ -100,14 +101,16 @@
             for E in self.emptys:
                 C = self.difference(A, E)
                 # Difference preserves LHS values.
-                self.assertEqual(hasattr(C, "values"), hasattr(A, "values"))
-                if hasattr(A, "values"):
+                self.assertEqual(safe_hasattr(C, "values"),
+                                 safe_hasattr(A, "values"))
+                if safe_hasattr(A, "values"):
                     self.assertEqual(list(C.items()), list(A.items()))
                 else:
                     self.assertEqual(list(C), self.Akeys)
 
                 C = self.difference(E, A)
-                self.assertEqual(hasattr(C, "values"), hasattr(E, "values"))
+                self.assertEqual(safe_hasattr(C, "values"),
+                                 safe_hasattr(E, "values"))
                 self.assertEqual(list(C.keys()), [])
 
     def testUnion(self):
@@ -115,7 +118,7 @@
         for A in inputs:
             for B in inputs:
                 C = self.union(A, B)
-                self.assert_(not hasattr(C, "values"))
+                self.assert_(not safe_hasattr(C, "values"))
                 self.assertEqual(list(C), self._union(A, B))
 
     def testIntersection(self):
@@ -123,7 +126,7 @@
         for A in inputs:
             for B in inputs:
                 C = self.intersection(A, B)
-                self.assert_(not hasattr(C, "values"))
+                self.assert_(not safe_hasattr(C, "values"))
                 self.assertEqual(list(C), self._intersection(A, B))
 
     def testDifference(self):
@@ -132,9 +135,10 @@
             for B in inputs:
                 C = self.difference(A, B)
                 # Difference preserves LHS values.
-                self.assertEqual(hasattr(C, "values"), hasattr(A, "values"))
+                self.assertEqual(safe_hasattr(C, "values"),
+                                 safe_hasattr(A, "values"))
                 want = self._difference(A, B)
-                if hasattr(A, "values"):
+                if safe_hasattr(A, "values"):
                     self.assertEqual(list(C.items()), want)
                 else:
                     self.assertEqual(list(C), want)
@@ -458,7 +462,7 @@
 # 'thing' is a bucket, btree, set or treeset.  Return true iff it's one of the
 # latter two.
 def isaset(thing):
-    return not hasattr(thing, 'values')
+    return not safe_hasattr(thing, 'values')
 
 class TestWeightedII(Weighted):
     from BTrees.IIBTree import weightedUnion, weightedIntersection

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to