Skip to content

Commit 28b58bd

Browse files
committed
Improve test coverage of backends/indexer_common::get_indexer() method
1 parent 66f5155 commit 28b58bd

File tree

1 file changed

+51
-45
lines changed

1 file changed

+51
-45
lines changed

test/test_indexer.py

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import pytest
2424
from roundup.backends import get_backend, have_backend
2525
from roundup.backends.indexer_rdbms import Indexer
26+
from roundup.backends.indexer_common import get_indexer
2627

2728
from roundup.cgi.exceptions import IndexerQueryError
2829

@@ -31,6 +32,7 @@
3132
from .test_postgresql import postgresqlOpener, skip_postgresql
3233
from .test_mysql import mysqlOpener, skip_mysql
3334
from .test_sqlite import sqliteOpener
35+
from .test_anydbm import anydbmOpener
3436

3537
try:
3638
import xapian
@@ -59,8 +61,16 @@ class config(dict):
5961
config[('main', 'indexer_stopwords')] = []
6062
config[('main', 'indexer_language')] = "english"
6163

62-
class IndexerTest(unittest.TestCase):
64+
class IndexerTest(anydbmOpener, unittest.TestCase):
65+
66+
indexer_name = "native"
67+
6368
def setUp(self):
69+
# remove previous test, ignore errors
70+
if os.path.exists(config.DATABASE):
71+
shutil.rmtree(config.DATABASE)
72+
self.db = self.module.Database(config, 'admin')
73+
6474
if os.path.exists('test-index'):
6575
shutil.rmtree('test-index')
6676
os.mkdir('test-index')
@@ -104,6 +114,24 @@ def test_clear(self):
104114
self.dex.add_text(('test', '1', 'foo'), '')
105115
self.assertSeqEqual(self.dex.find(['world']), [('test', '2', 'foo')])
106116

117+
def test_get_indexer(self):
118+
def class_name_of(object):
119+
""" take and object and return just the class name.
120+
So in:
121+
122+
return the class name before "at".
123+
124+
"""
125+
return(str(object).split()[0])
126+
127+
old_indexer = self.db.config['INDEXER']
128+
self.db.config['INDEXER'] = self.indexer_name
129+
130+
self.assertEqual(class_name_of(self.dex),
131+
class_name_of(get_indexer(self.db.config, self.db)))
132+
133+
self.db.config['INDEXER'] = old_indexer
134+
107135
def test_stopwords(self):
108136
"""Test that we can find a text with a stopword in it."""
109137
stopword = "with"
@@ -181,28 +209,42 @@ def test_unicode(self):
181209

182210
def tearDown(self):
183211
shutil.rmtree('test-index')
212+
if hasattr(self, 'db'):
213+
self.db.close()
214+
if os.path.exists(config.DATABASE):
215+
shutil.rmtree(config.DATABASE)
184216

185217
@skip_whoosh
186218
class WhooshIndexerTest(IndexerTest):
219+
220+
indexer_name = "whoosh"
221+
187222
def setUp(self):
223+
IndexerTest.setUp(self)
224+
188225
if os.path.exists('test-index'):
189226
shutil.rmtree('test-index')
190227
os.mkdir('test-index')
191228
from roundup.backends.indexer_whoosh import Indexer
192229
self.dex = Indexer(db)
193230
def tearDown(self):
194-
shutil.rmtree('test-index')
231+
IndexerTest.tearDown(self)
195232

196233
@skip_xapian
197234
class XapianIndexerTest(IndexerTest):
235+
236+
indexer_name = "xapian"
237+
198238
def setUp(self):
239+
IndexerTest.setUp(self)
240+
199241
if os.path.exists('test-index'):
200242
shutil.rmtree('test-index')
201243
os.mkdir('test-index')
202244
from roundup.backends.indexer_xapian import Indexer
203245
self.dex = Indexer(db)
204246
def tearDown(self):
205-
shutil.rmtree('test-index')
247+
IndexerTest.tearDown(self)
206248

207249
class RDBMSIndexerTest(object):
208250
def setUp(self):
@@ -230,6 +272,9 @@ def tearDown(self):
230272

231273
@skip_postgresql
232274
class postgresqlFtsIndexerTest(postgresqlOpener, RDBMSIndexerTest, IndexerTest):
275+
276+
indexer_name = "native-fts"
277+
233278
def setUp(self):
234279
postgresqlOpener.setUp(self)
235280
RDBMSIndexerTest.setUp(self)
@@ -241,27 +286,6 @@ def tearDown(self):
241286
RDBMSIndexerTest.tearDown(self)
242287
postgresqlOpener.tearDown(self)
243288

244-
def test_get_indexer(self):
245-
def class_name_of(object):
246-
""" take and object and return just the class name.
247-
So in:
248-
249-
return the class name before "at".
250-
251-
"""
252-
return(str(object).split()[0])
253-
254-
from roundup.backends.indexer_common import get_indexer
255-
old_indexer = self.db.config['INDEXER']
256-
self.db.config['INDEXER'] = 'native-fts'
257-
258-
get_indexer(self.db.config, self.db)
259-
260-
self.assertEqual(class_name_of(self.dex),
261-
class_name_of(get_indexer(self.db.config, self.db)))
262-
263-
self.db.config['INDEXER'] = old_indexer
264-
265289
def test_websearch_syntax(self):
266290
"""Test searches using websearch_to_tsquery. These never throw
267291
errors regardless of how wacky the input.
@@ -471,33 +495,15 @@ class sqliteIndexerTest(sqliteOpener, RDBMSIndexerTest, IndexerTest):
471495
pass
472496

473497
class sqliteFtsIndexerTest(sqliteOpener, RDBMSIndexerTest, IndexerTest):
498+
499+
indexer_name = "native-fts"
500+
474501
def setUp(self):
475502
RDBMSIndexerTest.setUp(self)
476503
from roundup.backends.indexer_sqlite_fts import Indexer
477504
self.dex = Indexer(self.db)
478505
self.dex.db = self.db
479506

480-
def test_get_indexer(self):
481-
def class_name_of(object):
482-
""" take and object and return just the class name.
483-
So in:
484-
485-
return the class name before "at".
486-
487-
"""
488-
return(str(object).split()[0])
489-
490-
from roundup.backends.indexer_common import get_indexer
491-
old_indexer = 'native-fts'
492-
self.db.config['INDEXER'] = 'native-fts'
493-
494-
get_indexer(self.db.config, self.db)
495-
496-
self.assertEqual(class_name_of(self.dex),
497-
class_name_of(get_indexer(self.db.config, self.db)))
498-
499-
self.db.config['INDEXER'] = old_indexer
500-
501507
def test_phrase_and_near(self):
502508
self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
503509
self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')

0 commit comments

Comments
 (0)