comparison test/test_indexer.py @ 3295:a615cc230160

added Xapian indexer; replaces standard indexers if Xapian is available
author Richard Jones <richard@users.sourceforge.net>
date Thu, 28 Apr 2005 00:21:42 +0000
parents 2fee36128471
children 8f7dc283bfa5
comparison
equal deleted inserted replaced
3293:8897483a9f8b 3295:a615cc230160
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE. 19 # SOFTWARE.
20 20
21 # $Id: test_indexer.py,v 1.6 2005-01-05 22:28:32 jlgijsbers Exp $ 21 # $Id: test_indexer.py,v 1.7 2005-04-28 00:21:42 richard Exp $
22 22
23 import os, unittest, shutil 23 import os, unittest, shutil
24
25 from roundup.backends.indexer_dbm import Indexer
26 24
27 class IndexerTest(unittest.TestCase): 25 class IndexerTest(unittest.TestCase):
28 def setUp(self): 26 def setUp(self):
29 if os.path.exists('test-index'): 27 if os.path.exists('test-index'):
30 shutil.rmtree('test-index') 28 shutil.rmtree('test-index')
31 os.mkdir('test-index') 29 os.mkdir('test-index')
32 os.mkdir('test-index/files') 30 os.mkdir('test-index/files')
31 from roundup.backends.indexer_dbm import Indexer
33 self.dex = Indexer('test-index') 32 self.dex = Indexer('test-index')
34 self.dex.load_index() 33 self.dex.load_index()
35 34
36 def test_basics(self): 35 def test_basics(self):
37 self.dex.add_text('testing1', 'a the hello world') 36 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
38 self.assertEqual(self.dex.words, {'HELLO': {1: 1}, 'WORLD': {1: 1}}) 37 self.dex.add_text(('test', '2', 'foo'), 'blah blah the world')
39 self.dex.add_text('testing2', 'blah blah the world') 38 self.assertEqual(self.dex.find(['world']), [('test', '1', 'foo'),
40 self.assertEqual(self.dex.words, {'BLAH': {2: 2}, 'HELLO': {1: 1}, 39 ('test', '2', 'foo')])
41 'WORLD': {2: 1, 1: 1}}) 40 self.assertEqual(self.dex.find(['blah']), [('test', '2', 'foo')])
42 self.assertEqual(self.dex.find(['world']), ['testing1',
43 'testing2'])
44 self.assertEqual(self.dex.find(['blah']), ['testing2'])
45 self.assertEqual(self.dex.find(['blah', 'hello']), []) 41 self.assertEqual(self.dex.find(['blah', 'hello']), [])
46 self.dex.save_index()
47 42
48 def tearDown(self): 43 def tearDown(self):
49 shutil.rmtree('test-index') 44 shutil.rmtree('test-index')
50 45
46 class XapianIndexerTest(IndexerTest):
47 def setUp(self):
48 if os.path.exists('text-index'):
49 shutil.rmtree('text-index')
50 from roundup.backends.indexer_xapian import Indexer
51 self.dex = Indexer('.')
52 def tearDown(self):
53 shutil.rmtree('text-index')
54
51 def test_suite(): 55 def test_suite():
52 suite = unittest.TestSuite() 56 suite = unittest.TestSuite()
53 suite.addTest(unittest.makeSuite(IndexerTest)) 57 suite.addTest(unittest.makeSuite(IndexerTest))
58 try:
59 import xapian
60 suite.addTest(unittest.makeSuite(XapianIndexerTest))
61 except ImportError:
62 print "Skipping Xapian indexer tests"
63 pass
54 return suite 64 return suite
55 65
56 if __name__ == '__main__': 66 if __name__ == '__main__':
57 runner = unittest.TextTestRunner() 67 runner = unittest.TextTestRunner()
58 unittest.main(testRunner=runner) 68 unittest.main(testRunner=runner)

Roundup Issue Tracker: http://roundup-tracker.org/