Log message for revision 115320:
  Avoid importing the modules under tests on the module scope
  

Changed:
  U   Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py

-=-
Modified: Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py      2010-08-01 
12:30:28 UTC (rev 115319)
+++ Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py      2010-08-01 
12:35:25 UTC (rev 115320)
@@ -32,10 +32,7 @@
 from ZODB.DemoStorage import DemoStorage
 import transaction
 
-from Products.ZCatalog.Catalog import Catalog
-from Products.ZCatalog.Catalog import CatalogError
 
-
 def createDatabase():
     # Create a DemoStorage and put an Application in it
     db = DB(DemoStorage())
@@ -88,10 +85,14 @@
         self.number = num
 
 
-class CatalogBase:
+class CatalogBase(object):
 
+    def _makeOne(self):
+        from Products.ZCatalog.Catalog import Catalog
+        return Catalog()
+
     def setUp(self):
-        self._catalog = Catalog()
+        self._catalog = self._makeOne()
 
     def tearDown(self):
         self._catalog = None
@@ -105,6 +106,7 @@
                          'add column failed')
 
     def testAddBad(self):
+        from Products.ZCatalog.Catalog import CatalogError
         self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
 
     def testDel(self):
@@ -162,7 +164,7 @@
                      'del index failed')
 
 
-class TestCatalogObject(unittest.TestCase):
+class TestCatalogObject(CatalogBase, unittest.TestCase):
 
     upper = 1000
 
@@ -175,7 +177,7 @@
 
     def setUp(self):
         self.warningshook = WarningsHook()
-        self._catalog = Catalog()
+        self._catalog = self._makeOne()
         self._catalog.lexicon = PLexicon('lexicon')
         col1 = FieldIndex('col1')
         col2 = ZCTextIndex('col2', caller=self._catalog,
@@ -303,12 +305,14 @@
             self.assertEqual(a[x].num, x)
 
     def testBadSortIndex(self):
+        from Products.ZCatalog.Catalog import CatalogError
         self.assertRaises(CatalogError, self.badsortindex)
 
     def badsortindex(self):
         self._catalog(sort_on='foofaraw')
 
     def testWrongKindOfIndexForSort(self):
+        from Products.ZCatalog.Catalog import CatalogError
         self.assertRaises(CatalogError, self.wrongsortindex)
 
     def wrongsortindex(self):
@@ -397,10 +401,10 @@
         self.assertEqual(brain.att1, 'foobar')
 
 
-class TestRangeSearch(unittest.TestCase):
+class TestRangeSearch(CatalogBase, unittest.TestCase):
 
     def setUp(self):
-        self._catalog = Catalog()
+        self._catalog = self._makeOne()
         index = FieldIndex('number')
         self._catalog.addIndex('number', index)
         self._catalog.addColumn('number')
@@ -424,13 +428,13 @@
                              "%d vs [%d,%d]" % (r.number, m, n))
 
 
-class TestMerge(unittest.TestCase):
+class TestMerge(CatalogBase, unittest.TestCase):
     # Test merging results from multiple catalogs
 
     def setUp(self):
         self.catalogs = []
         for i in range(3):
-            cat = Catalog()
+            cat = self._makeOne()
             cat.lexicon = PLexicon('lexicon')
             cat.addIndex('num', FieldIndex('num'))
             cat.addIndex('big', FieldIndex('big'))

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

Reply via email to