Mercurial > p > roundup > code
annotate test/test_indexer.py @ 2089:93f03c6714d8
A few big changes in this commit:
1. The current indexer has been moved to backends/indexer_dbm in
anticipation of my writing an indexer_rdbms,
2. Changed indexer invocation during create / set to follow the pattern
set by the metakit backend, which was much cleaner, and
3. The "content" property of FileClass is now mutable in all but the
metakit backend.
Metakit needs to be changed to support the editing of "content". Hey, and
I learnt today that the metakit backend implements its own indexer. How
about that... :)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 19 Mar 2004 04:47:59 +0000 |
| parents | f63aa57386b0 |
| children | 0e1860dcb328 9c8de04a76b1 |
| rev | line source |
|---|---|
|
848
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 # Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/) |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 # |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 # Permission is hereby granted, free of charge, to any person obtaining a copy |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 # of this software and associated documentation files (the "Software"), to deal |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
5 # in the Software without restriction, including without limitation the rights |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 # copies of the Software, and to permit persons to whom the Software is |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 # furnished to do so, subject to the following conditions: |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 # |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 # The above copyright notice and this permission notice shall be included in |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 # all copies or substantial portions of the Software. |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 # |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 # SOFTWARE. |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
20 |
|
2089
93f03c6714d8
A few big changes in this commit:
Richard Jones <richard@users.sourceforge.net>
parents:
1873
diff
changeset
|
21 # $Id: test_indexer.py,v 1.4 2004-03-19 04:47:59 richard Exp $ |
|
848
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 import os, unittest, shutil |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 |
|
2089
93f03c6714d8
A few big changes in this commit:
Richard Jones <richard@users.sourceforge.net>
parents:
1873
diff
changeset
|
25 from roundup.backends.indexer_dbm import Indexer |
|
848
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
27 class IndexerTest(unittest.TestCase): |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 def setUp(self): |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 if os.path.exists('test-index'): |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 shutil.rmtree('test-index') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 os.mkdir('test-index') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 os.mkdir('test-index/files') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 self.dex = Indexer('test-index') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 self.dex.load_index() |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 def test_basics(self): |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 self.dex.add_text('testing1', 'a the hello world') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
38 self.assertEqual(self.dex.words, {'HELLO': {1: 1}, 'THE': {1: 1}, |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
39 'WORLD': {1: 1}}) |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 self.dex.add_text('testing2', 'blah blah the world') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 self.assertEqual(self.dex.words, {'BLAH': {2: 2}, 'HELLO': {1: 1}, |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 'THE': {2: 1, 1: 1}, 'WORLD': {2: 1, 1: 1}}) |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
43 self.assertEqual(self.dex.find(['world']), {2: 'testing2', |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
44 1: 'testing1'}) |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 self.assertEqual(self.dex.find(['blah']), {2: 'testing2'}) |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 self.assertEqual(self.dex.find(['blah', 'hello']), {}) |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
47 self.dex.save_index() |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
48 |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 def tearDown(self): |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 shutil.rmtree('test-index') |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 |
|
1873
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
52 def test_suite(): |
|
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
53 suite = unittest.TestSuite() |
|
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
54 suite.addTest(unittest.makeSuite(IndexerTest)) |
|
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
55 return suite |
|
848
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
56 |
|
1873
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
57 if __name__ == '__main__': |
|
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
58 runner = unittest.TextTestRunner() |
|
f63aa57386b0
Backend improvements.
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
59 unittest.main(testRunner=runner) |
|
848
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
60 |
|
2a928d404af8
ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 # vim: set filetype=python ts=4 sw=4 et si |
