Commit 9fec7fa1 authored by Hanno Schlichting's avatar Hanno Schlichting

Avoid importing the modules under tests on the module scope

parent aa22e7a2
...@@ -32,9 +32,6 @@ from ZODB.DB import DB ...@@ -32,9 +32,6 @@ from ZODB.DB import DB
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
import transaction import transaction
from Products.ZCatalog.Catalog import Catalog
from Products.ZCatalog.Catalog import CatalogError
def createDatabase(): def createDatabase():
# Create a DemoStorage and put an Application in it # Create a DemoStorage and put an Application in it
...@@ -88,10 +85,14 @@ class objRS(ExtensionClass.Base): ...@@ -88,10 +85,14 @@ class objRS(ExtensionClass.Base):
self.number = num self.number = num
class CatalogBase: class CatalogBase(object):
def _makeOne(self):
from Products.ZCatalog.Catalog import Catalog
return Catalog()
def setUp(self): def setUp(self):
self._catalog = Catalog() self._catalog = self._makeOne()
def tearDown(self): def tearDown(self):
self._catalog = None self._catalog = None
...@@ -105,6 +106,7 @@ class TestAddDelColumn(CatalogBase, unittest.TestCase): ...@@ -105,6 +106,7 @@ class TestAddDelColumn(CatalogBase, unittest.TestCase):
'add column failed') 'add column failed')
def testAddBad(self): def testAddBad(self):
from Products.ZCatalog.Catalog import CatalogError
self.assertRaises(CatalogError, self._catalog.addColumn, '_id') self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
def testDel(self): def testDel(self):
...@@ -162,7 +164,7 @@ class TestAddDelIndexes(CatalogBase, unittest.TestCase): ...@@ -162,7 +164,7 @@ class TestAddDelIndexes(CatalogBase, unittest.TestCase):
'del index failed') 'del index failed')
class TestCatalogObject(unittest.TestCase): class TestCatalogObject(CatalogBase, unittest.TestCase):
upper = 1000 upper = 1000
...@@ -175,7 +177,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -175,7 +177,7 @@ class TestCatalogObject(unittest.TestCase):
def setUp(self): def setUp(self):
self.warningshook = WarningsHook() self.warningshook = WarningsHook()
self._catalog = Catalog() self._catalog = self._makeOne()
self._catalog.lexicon = PLexicon('lexicon') self._catalog.lexicon = PLexicon('lexicon')
col1 = FieldIndex('col1') col1 = FieldIndex('col1')
col2 = ZCTextIndex('col2', caller=self._catalog, col2 = ZCTextIndex('col2', caller=self._catalog,
...@@ -303,12 +305,14 @@ class TestCatalogObject(unittest.TestCase): ...@@ -303,12 +305,14 @@ class TestCatalogObject(unittest.TestCase):
self.assertEqual(a[x].num, x) self.assertEqual(a[x].num, x)
def testBadSortIndex(self): def testBadSortIndex(self):
from Products.ZCatalog.Catalog import CatalogError
self.assertRaises(CatalogError, self.badsortindex) self.assertRaises(CatalogError, self.badsortindex)
def badsortindex(self): def badsortindex(self):
self._catalog(sort_on='foofaraw') self._catalog(sort_on='foofaraw')
def testWrongKindOfIndexForSort(self): def testWrongKindOfIndexForSort(self):
from Products.ZCatalog.Catalog import CatalogError
self.assertRaises(CatalogError, self.wrongsortindex) self.assertRaises(CatalogError, self.wrongsortindex)
def wrongsortindex(self): def wrongsortindex(self):
...@@ -397,10 +401,10 @@ class TestCatalogObject(unittest.TestCase): ...@@ -397,10 +401,10 @@ class TestCatalogObject(unittest.TestCase):
self.assertEqual(brain.att1, 'foobar') self.assertEqual(brain.att1, 'foobar')
class TestRangeSearch(unittest.TestCase): class TestRangeSearch(CatalogBase, unittest.TestCase):
def setUp(self): def setUp(self):
self._catalog = Catalog() self._catalog = self._makeOne()
index = FieldIndex('number') index = FieldIndex('number')
self._catalog.addIndex('number', index) self._catalog.addIndex('number', index)
self._catalog.addColumn('number') self._catalog.addColumn('number')
...@@ -424,13 +428,13 @@ class TestRangeSearch(unittest.TestCase): ...@@ -424,13 +428,13 @@ class TestRangeSearch(unittest.TestCase):
"%d vs [%d,%d]" % (r.number, m, n)) "%d vs [%d,%d]" % (r.number, m, n))
class TestMerge(unittest.TestCase): class TestMerge(CatalogBase, unittest.TestCase):
# Test merging results from multiple catalogs # Test merging results from multiple catalogs
def setUp(self): def setUp(self):
self.catalogs = [] self.catalogs = []
for i in range(3): for i in range(3):
cat = Catalog() cat = self._makeOne()
cat.lexicon = PLexicon('lexicon') cat.lexicon = PLexicon('lexicon')
cat.addIndex('num', FieldIndex('num')) cat.addIndex('num', FieldIndex('num'))
cat.addIndex('big', FieldIndex('big')) cat.addIndex('big', FieldIndex('big'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment