Skip to content

Commit 0d571e0

Browse files
committed
test get_indexer three autosearch options: xapian, whoosh, native
1 parent b498b4b commit 0d571e0

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

test/test_indexer.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def test_clear(self):
114114
self.dex.add_text(('test', '1', 'foo'), '')
115115
self.assertSeqEqual(self.dex.find(['world']), [('test', '2', 'foo')])
116116

117-
def test_get_indexer(self):
117+
def test_get_indexer_specified(self):
118+
"""Specify an indexer back end and make sure it's returned"""
118119
def class_name_of(object):
119120
""" take and object and return just the class name.
120121
So in:
@@ -246,6 +247,44 @@ def setUp(self):
246247
def tearDown(self):
247248
IndexerTest.tearDown(self)
248249

250+
class Get_IndexerAutoSelectTest(anydbmOpener, unittest.TestCase):
251+
252+
def setUp(self):
253+
# remove previous test, ignore errors
254+
if os.path.exists(config.DATABASE):
255+
shutil.rmtree(config.DATABASE)
256+
self.db = self.module.Database(config, 'admin')
257+
# this is the default, but set it in case default
258+
# changes in future
259+
self.db.config['INDEXER'] = ''
260+
261+
def tearDown(self):
262+
if hasattr(self, 'db'):
263+
self.db.close()
264+
if os.path.exists(config.DATABASE):
265+
shutil.rmtree(config.DATABASE)
266+
267+
@skip_xapian
268+
def test_xapian_select(self):
269+
indexer = get_indexer(self.db.config, self.db)
270+
self.assertIn('roundup.backends.indexer_xapian.Indexer', str(indexer))
271+
272+
@skip_whoosh
273+
def test_whoosh_select(self):
274+
import mock, sys
275+
with mock.patch.dict('sys.modules',
276+
{'roundup.backends.indexer_xapian': None}):
277+
indexer = get_indexer(self.db.config, self.db)
278+
self.assertIn('roundup.backends.indexer_whoosh.Indexer', str(indexer))
279+
280+
def test_native_select(self):
281+
import mock, sys
282+
with mock.patch.dict('sys.modules',
283+
{'roundup.backends.indexer_xapian': None,
284+
'roundup.backends.indexer_whoosh': None}):
285+
indexer = get_indexer(self.db.config, self.db)
286+
self.assertIn('roundup.backends.indexer_dbm.Indexer', str(indexer))
287+
249288
class RDBMSIndexerTest(object):
250289
def setUp(self):
251290
# remove previous test, ignore errors

0 commit comments

Comments
 (0)