Mercurial > p > roundup > code
comparison test/test_indexer.py @ 6912:a23eaa3013e6
test get_indexer three autosearch options: xapian, whoosh, native
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 03 Sep 2022 22:35:09 -0400 |
| parents | 86cde9cae7e1 |
| children | 9ff091537f43 |
comparison
equal
deleted
inserted
replaced
| 6911:8bda74ee7070 | 6912:a23eaa3013e6 |
|---|---|
| 112 self.assertSeqEqual(self.dex.find(['world']), [('test', '1', 'foo'), | 112 self.assertSeqEqual(self.dex.find(['world']), [('test', '1', 'foo'), |
| 113 ('test', '2', 'foo')]) | 113 ('test', '2', 'foo')]) |
| 114 self.dex.add_text(('test', '1', 'foo'), '') | 114 self.dex.add_text(('test', '1', 'foo'), '') |
| 115 self.assertSeqEqual(self.dex.find(['world']), [('test', '2', 'foo')]) | 115 self.assertSeqEqual(self.dex.find(['world']), [('test', '2', 'foo')]) |
| 116 | 116 |
| 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""" | |
| 118 def class_name_of(object): | 119 def class_name_of(object): |
| 119 """ take and object and return just the class name. | 120 """ take and object and return just the class name. |
| 120 So in: | 121 So in: |
| 121 | 122 |
| 122 return the class name before "at". | 123 return the class name before "at". |
| 244 from roundup.backends.indexer_xapian import Indexer | 245 from roundup.backends.indexer_xapian import Indexer |
| 245 self.dex = Indexer(db) | 246 self.dex = Indexer(db) |
| 246 def tearDown(self): | 247 def tearDown(self): |
| 247 IndexerTest.tearDown(self) | 248 IndexerTest.tearDown(self) |
| 248 | 249 |
| 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 | |
| 249 class RDBMSIndexerTest(object): | 288 class RDBMSIndexerTest(object): |
| 250 def setUp(self): | 289 def setUp(self): |
| 251 # remove previous test, ignore errors | 290 # remove previous test, ignore errors |
| 252 if os.path.exists(config.DATABASE): | 291 if os.path.exists(config.DATABASE): |
| 253 shutil.rmtree(config.DATABASE) | 292 shutil.rmtree(config.DATABASE) |
