Code

removed Log
[roundup.git] / test / test_indexer.py
1 # Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 #   The above copyright notice and this permission notice shall be included in
11 #   all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
21 # $Id: test_indexer.py,v 1.2 2002-09-10 00:19:54 richard Exp $
23 import os, unittest, shutil
25 from roundup.indexer import Indexer
27 class IndexerTest(unittest.TestCase):
28     def setUp(self):
29         if os.path.exists('test-index'):
30             shutil.rmtree('test-index')
31         os.mkdir('test-index')
32         os.mkdir('test-index/files')
33         self.dex = Indexer('test-index')
34         self.dex.load_index()
36     def test_basics(self):
37         self.dex.add_text('testing1', 'a the hello world')
38         self.assertEqual(self.dex.words, {'HELLO': {1: 1}, 'THE': {1: 1},
39             'WORLD': {1: 1}})
40         self.dex.add_text('testing2', 'blah blah the world')
41         self.assertEqual(self.dex.words, {'BLAH': {2: 2}, 'HELLO': {1: 1},
42             'THE': {2: 1, 1: 1}, 'WORLD': {2: 1, 1: 1}})
43         self.assertEqual(self.dex.find(['world']), {2: 'testing2',
44             1: 'testing1'})
45         self.assertEqual(self.dex.find(['blah']), {2: 'testing2'})
46         self.assertEqual(self.dex.find(['blah', 'hello']), {})
47         self.dex.save_index()
49     def tearDown(self):
50         shutil.rmtree('test-index')
52 def suite():
53     return unittest.makeSuite(IndexerTest)
56 # vim: set filetype=python ts=4 sw=4 et si