[Checkins] SVN: BTrees/branches/pure_python/ Avoid module-scope imports, test case attrs.

Tres Seaver cvs-admin at zope.org
Sun Nov 11 20:51:51 UTC 2012


Log message for revision 128237:
  Avoid module-scope imports, test case attrs.

Changed:
  _U  BTrees/branches/pure_python/
  U   BTrees/branches/pure_python/BTrees/tests/test_check.py

-=-
Modified: BTrees/branches/pure_python/BTrees/tests/test_check.py
===================================================================
--- BTrees/branches/pure_python/BTrees/tests/test_check.py	2012-11-11 20:51:50 UTC (rev 128236)
+++ BTrees/branches/pure_python/BTrees/tests/test_check.py	2012-11-11 20:51:51 UTC (rev 128237)
@@ -15,61 +15,68 @@
 
 import unittest
 
-from BTrees.OOBTree import OOBTree
-from BTrees.check import check
 
 class CheckTest(unittest.TestCase):
 
-    def setUp(self):
-        self.t = t = OOBTree()
+    def _makeOne(self):
+        from BTrees.OOBTree import OOBTree
+        tree = OOBTree()
         for i in range(31):
-            t[i] = 2*i
-        self.state = t.__getstate__()
+            tree[i] = 2*i
+        return tree
 
     def testNormal(self):
-        s = self.state
         # Looks like (state, first_bucket)
         # where state looks like (bucket0, 15, bucket1).
-        self.assertEqual(len(s), 2)
-        self.assertEqual(len(s[0]), 3)
-        self.assertEqual(s[0][1], 15)
-        self.t._check() # shouldn't blow up
-        check(self.t)   # shouldn't blow up
+        from BTrees.check import check
+        tree = self._makeOne()
+        state = tree.__getstate__()
+        self.assertEqual(len(state), 2)
+        self.assertEqual(len(state[0]), 3)
+        self.assertEqual(state[0][1], 15)
+        tree._check() # shouldn't blow up
+        check(tree)   # shouldn't blow up
 
     def testKeyTooLarge(self):
         # Damage an invariant by dropping the BTree key to 14.
-        s = self.state
-        news = (s[0][0], 14, s[0][2]), s[1]
-        self.t.__setstate__(news)
-        self.t._check() # not caught
+        from BTrees.check import check
+        tree = self._makeOne()
+        state = tree.__getstate__()
+        news = (state[0][0], 14, state[0][2]), state[1]
+        tree.__setstate__(news)
+        tree._check() # not caught
         try:
             # Expecting "... key %r >= upper bound %r at index %d"
-            check(self.t)
-        except AssertionError, detail:
-            self.failUnless(str(detail).find(">= upper bound") > 0)
+            check(tree)
+        except AssertionError as detail:
+            self.assertTrue(">= upper bound" in str(detail))
         else:
-            self.fail("expected self.t_check() to catch the problem")
+            self.fail("expected check(tree) to catch the problem")
 
     def testKeyTooSmall(self):
         # Damage an invariant by bumping the BTree key to 16.
-        s = self.state
-        news = (s[0][0], 16, s[0][2]), s[1]
-        self.t.__setstate__(news)
-        self.t._check() # not caught
+        from BTrees.check import check
+        tree = self._makeOne()
+        state = tree.__getstate__()
+        news = (state[0][0], 16, state[0][2]), state[1]
+        tree.__setstate__(news)
+        tree._check() # not caught
         try:
             # Expecting "... key %r < lower bound %r at index %d"
-            check(self.t)
-        except AssertionError, detail:
-            self.failUnless(str(detail).find("< lower bound") > 0)
+            check(tree)
+        except AssertionError as detail:
+            self.assertTrue("< lower bound" in str(detail))
         else:
-            self.fail("expected self.t_check() to catch the problem")
+            self.fail("expected check(tree) to catch the problem")
 
     def testKeysSwapped(self):
         # Damage an invariant by swapping two key/value pairs.
-        s = self.state
+        from BTrees.check import check
+        tree = self._makeOne()
+        state = tree.__getstate__()
         # Looks like (state, first_bucket)
         # where state looks like (bucket0, 15, bucket1).
-        (b0, num, b1), firstbucket = s
+        (b0, num, b1), firstbucket = state
         self.assertEqual(b0[4], 8)
         self.assertEqual(b0[5], 10)
         b0state = b0.__getstate__()
@@ -83,14 +90,14 @@
         self.assertEqual(pairs[11], 10)
         newpairs = pairs[:8] + (5, 10, 4, 8) + pairs[12:]
         b0.__setstate__((newpairs, nextbucket))
-        self.t._check() # not caught
+        tree._check() # not caught
         try:
-            check(self.t)
+            check(tree)
         except AssertionError, detail:
-            self.failUnless(str(detail).find(
-                "key 5 at index 4 >= key 4 at index 5") > 0)
+            self.assertTrue(
+                "key 5 at index 4 >= key 4 at index 5" in str(detail))
         else:
-            self.fail("expected self.t_check() to catch the problem")
+            self.fail("expected check(tree) to catch the problem")
 
 def test_suite():
     return unittest.makeSuite(CheckTest)



More information about the checkins mailing list