annotate test/test_indexer.py @ 8526:0586f25eb25e

ruff: exclusions on imports ignore import locations and import used for side effect
author John Rouillard <rouilj@ieee.org>
date Fri, 20 Feb 2026 16:30:50 -0500
parents 94aafe3b0a0d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7070
c6b2534a58a9 Compatibility: unittest.mock vs. only mock
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6915
diff changeset
21 import os, sys, unittest, shutil
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
22
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
23 import pytest
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
24 from roundup.backends import get_backend, have_backend
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
25 from roundup.backends.indexer_rdbms import Indexer
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
26 from roundup.backends.indexer_common import get_indexer
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
27
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
28 from roundup.cgi.exceptions import IndexerQueryError
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
29
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
30 # borrow from other tests
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5109
diff changeset
31 from .db_test_base import setupSchema, config
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
32 from .test_postgresql import postgresqlOpener, skip_postgresql
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
33 from .test_mysql import mysqlOpener, skip_mysql
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5109
diff changeset
34 from .test_sqlite import sqliteOpener
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
35 from .test_anydbm import anydbmOpener
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
36
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
37 try:
7070
c6b2534a58a9 Compatibility: unittest.mock vs. only mock
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6915
diff changeset
38 from unittest import mock
c6b2534a58a9 Compatibility: unittest.mock vs. only mock
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6915
diff changeset
39 except ImportError:
c6b2534a58a9 Compatibility: unittest.mock vs. only mock
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6915
diff changeset
40 import mock
c6b2534a58a9 Compatibility: unittest.mock vs. only mock
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6915
diff changeset
41
c6b2534a58a9 Compatibility: unittest.mock vs. only mock
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6915
diff changeset
42 try:
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
43 import xapian
5038
c977f3530944 Work-around for pytest.mark.skipif() bug
John Kristensen <john@jerrykan.com>
parents: 5037
diff changeset
44 skip_xapian = lambda func, *args, **kwargs: func
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
45 except ImportError:
5109
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
46 # FIX: workaround for a bug in pytest.mark.skip():
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
47 # https://github.com/pytest-dev/pytest/issues/568
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
48 from .pytest_patcher import mark_class
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
49 skip_xapian = mark_class(pytest.mark.skip(
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
50 "Skipping Xapian indexer tests: 'xapian' not installed"))
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
51
5096
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
52 try:
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
53 import whoosh
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
54 skip_whoosh = lambda func, *args, **kwargs: func
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
55 except ImportError:
5109
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
56 # FIX: workaround for a bug in pytest.mark.skip():
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
57 # https://github.com/pytest-dev/pytest/issues/568
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
58 from .pytest_patcher import mark_class
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
59 skip_whoosh = mark_class(pytest.mark.skip(
43a1f7fe39f5 Improved work-around for pytest markers bug
John Kristensen <john@jerrykan.com>
parents: 5105
diff changeset
60 "Skipping Whoosh indexer tests: 'whoosh' not installed"))
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
61
3297
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
62 class db:
3546
a4edd24c32be test fixes and checking of indexer overwrites (xapian currently fails)
Richard Jones <richard@users.sourceforge.net>
parents: 3297
diff changeset
63 class config(dict):
3297
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
64 DATABASE = 'test-index'
3546
a4edd24c32be test fixes and checking of indexer overwrites (xapian currently fails)
Richard Jones <richard@users.sourceforge.net>
parents: 3297
diff changeset
65 config = config()
a4edd24c32be test fixes and checking of indexer overwrites (xapian currently fails)
Richard Jones <richard@users.sourceforge.net>
parents: 3297
diff changeset
66 config[('main', 'indexer_stopwords')] = []
6353
9d209d2b34ae Add indexer_language to change stemmer for xapian FTS indexer
John Rouillard <rouilj@ieee.org>
parents: 5964
diff changeset
67 config[('main', 'indexer_language')] = "english"
3297
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
68
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
69 class IndexerTest(anydbmOpener, unittest.TestCase):
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
70
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
71 indexer_name = "native"
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
72
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
73 def setUp(self):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
74 # remove previous test, ignore errors
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
75 if os.path.exists(config.DATABASE):
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
76 shutil.rmtree(config.DATABASE)
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
77 self.db = self.module.Database(config, 'admin')
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
78
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
79 if os.path.exists('test-index'):
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
80 shutil.rmtree('test-index')
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
81 os.mkdir('test-index')
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
82 os.mkdir('test-index/files')
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
83 from roundup.backends.indexer_dbm import Indexer
3297
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
84 self.dex = Indexer(db)
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
85 self.dex.load_index()
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
86
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
87 def assertSeqEqual(self, s1, s2):
4102
dcca66d56815 fix unit test compatibility
Richard Jones <richard@users.sourceforge.net>
parents: 4016
diff changeset
88 # First argument is the db result we're testing, second is the
dcca66d56815 fix unit test compatibility
Richard Jones <richard@users.sourceforge.net>
parents: 4016
diff changeset
89 # desired result. Some db results don't have iterable rows, so we
dcca66d56815 fix unit test compatibility
Richard Jones <richard@users.sourceforge.net>
parents: 4016
diff changeset
90 # have to work around that.
4015
6eec11b197aa fix for indexer-test:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4008
diff changeset
91 # Also work around some dbs not returning items in the expected
4102
dcca66d56815 fix unit test compatibility
Richard Jones <richard@users.sourceforge.net>
parents: 4016
diff changeset
92 # order.
dcca66d56815 fix unit test compatibility
Richard Jones <richard@users.sourceforge.net>
parents: 4016
diff changeset
93 s1 = list([tuple([r[n] for n in range(len(r))]) for r in s1])
4015
6eec11b197aa fix for indexer-test:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4008
diff changeset
94 s1.sort()
4102
dcca66d56815 fix unit test compatibility
Richard Jones <richard@users.sourceforge.net>
parents: 4016
diff changeset
95 if s1 != s2:
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
96 self.fail('contents of %r != %r'%(s1, s2))
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
97
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
98 def test_basics(self):
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
99 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
100 self.dex.add_text(('test', '2', 'foo'), 'blah blah the world')
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
101 self.assertSeqEqual(self.dex.find(['world']), [('test', '1', 'foo'),
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
102 ('test', '2', 'foo')])
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
103 self.assertSeqEqual(self.dex.find(['blah']), [('test', '2', 'foo')])
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
104 self.assertSeqEqual(self.dex.find(['blah', 'hello']), [])
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
105 self.assertSeqEqual(self.dex.find([]), [])
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
106
7690
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
107 def test_save_load(self):
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
108
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
109 # only run for anydbm test
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
110 if ( not type(self) is IndexerTest ):
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
111 pytest.skip("test_save_load tested only for anydbm backend")
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
112
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
113 self.dex.add_text(('test', '1', 'foo'), 'b the hello world')
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
114 self.assertSeqEqual(self.dex.find(['hello']), [('test', '1', 'foo')])
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
115 self.dex.save_index()
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
116
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
117 # reopen saved db.
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
118 from roundup.backends.indexer_dbm import Indexer
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
119 self.dex = Indexer(db)
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
120
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
121 # verify index is unloaded
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
122 self.assertEqual(self.dex.index_loaded(), False)
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
123
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
124 # add also calls load_index(), so it should load the first item.
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
125 self.dex.add_text(('test', '2', 'foo'), 'b the olleh world')
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
126
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
127 # note find also does a load_index() if not loaded.
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
128 self.assertSeqEqual(self.dex.find(['hello']), [('test', '1', 'foo')])
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
129 self.assertSeqEqual(self.dex.find(['olleh']), [('test', '2', 'foo')])
d17e57220a62 fix: close file properly in indexer_dbm.py:save_index()
John Rouillard <rouilj@ieee.org>
parents: 7073
diff changeset
130
3547
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
131 def test_change(self):
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
132 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
133 self.dex.add_text(('test', '2', 'foo'), 'blah blah the world')
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
134 self.assertSeqEqual(self.dex.find(['world']), [('test', '1', 'foo'),
3547
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
135 ('test', '2', 'foo')])
3546
a4edd24c32be test fixes and checking of indexer overwrites (xapian currently fails)
Richard Jones <richard@users.sourceforge.net>
parents: 3297
diff changeset
136 self.dex.add_text(('test', '1', 'foo'), 'a the hello')
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
137 self.assertSeqEqual(self.dex.find(['world']), [('test', '2', 'foo')])
3546
a4edd24c32be test fixes and checking of indexer overwrites (xapian currently fails)
Richard Jones <richard@users.sourceforge.net>
parents: 3297
diff changeset
138
3547
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
139 def test_clear(self):
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
140 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
141 self.dex.add_text(('test', '2', 'foo'), 'blah blah the world')
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
142 self.assertSeqEqual(self.dex.find(['world']), [('test', '1', 'foo'),
3547
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
143 ('test', '2', 'foo')])
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
144 self.dex.add_text(('test', '1', 'foo'), '')
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
145 self.assertSeqEqual(self.dex.find(['world']), [('test', '2', 'foo')])
3547
7728ee93efd2 fix reindexing in Xapian
Richard Jones <richard@users.sourceforge.net>
parents: 3546
diff changeset
146
6912
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
147 def test_get_indexer_specified(self):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
148 """Specify an indexer back end and make sure it's returned"""
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
149 def class_name_of(object):
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
150 """ take and object and return just the class name.
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
151 So in:
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
152
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
153 return the class name before "at".
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
154
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
155 """
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
156 return(str(object).split()[0])
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
157
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
158 old_indexer = self.db.config['INDEXER']
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
159 self.db.config['INDEXER'] = self.indexer_name
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
160
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
161 self.assertEqual(class_name_of(self.dex),
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
162 class_name_of(get_indexer(self.db.config, self.db)))
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
163
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
164 self.db.config['INDEXER'] = old_indexer
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
165
4251
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
166 def test_stopwords(self):
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
167 """Test that we can find a text with a stopword in it."""
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
168 stopword = "with"
5649
f8893e1cde0d assert_ is depricated. Replacing with assertTrue to reduce logs in travisci.
John Rouillard <rouilj@ieee.org>
parents: 5388
diff changeset
169 self.assertTrue(self.dex.is_stopword(stopword.upper()))
4251
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
170 self.dex.add_text(('test', '1', 'bar'), '%s hello world' % stopword)
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
171 self.dex.add_text(('test', '2', 'bar'), 'blah a %s world' % stopword)
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
172 self.dex.add_text(('test', '3', 'bar'), 'blah Blub river')
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
173 self.dex.add_text(('test', '4', 'bar'), 'blah river %s' % stopword)
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
174 self.assertSeqEqual(self.dex.find(['with','world']),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
175 [('test', '1', 'bar'),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
176 ('test', '2', 'bar')])
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
177 def test_extremewords(self):
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
178 """Testing too short or too long words."""
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
179
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
180 # skip this for FTS test
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
181 if ( isinstance(self,sqliteFtsIndexerTest) or
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
182 isinstance(self,postgresqlFtsIndexerTest)):
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
183 pytest.skip("extremewords not tested for native FTS backends")
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
184
4251
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
185 short = "b"
6599
39189dd94f2c issue2551189 - increase size of words in full text index.
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
186 long = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
4251
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
187 self.dex.add_text(('test', '1', 'a'), '%s hello world' % short)
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
188 self.dex.add_text(('test', '2', 'a'), 'blah a %s world' % short)
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
189 self.dex.add_text(('test', '3', 'a'), 'blah Blub river')
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
190 self.dex.add_text(('test', '4', 'a'), 'blah river %s %s'
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
191 % (short, long))
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
192 self.assertSeqEqual(self.dex.find([short,'world', long, short]),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
193 [('test', '1', 'a'),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
194 ('test', '2', 'a')])
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
195 self.assertSeqEqual(self.dex.find([long]),[])
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
196
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
197 # special test because some faulty code indexed length(word)>=2
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
198 # but only considered length(word)>=3 to be significant
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
199 self.dex.add_text(('test', '5', 'a'), 'blah py %s %s'
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
200 % (short, long))
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
201 self.assertSeqEqual(self.dex.find(["py"]), [('test', '5', 'a')])
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
202
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
203 def test_casesensitivity(self):
4251
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
204 """Test if searches are case-in-sensitive."""
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
205 self.dex.add_text(('test', '1', 'a'), 'aaaa bbbb')
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
206 self.dex.add_text(('test', '2', 'a'), 'aAaa BBBB')
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
207 self.assertSeqEqual(self.dex.find(['aaaa']),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
208 [('test', '1', 'a'),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
209 ('test', '2', 'a')])
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
210 self.assertSeqEqual(self.dex.find(['BBBB']),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
211 [('test', '1', 'a'),
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
212 ('test', '2', 'a')])
2b1241daaa20 Added more indexer tests for stopwords, case-insensitity...
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents: 4102
diff changeset
213
4314
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
214 def test_wordsplitting(self):
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
215 """Test if word splitting works."""
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
216 self.dex.add_text(('test', '1', 'a'), 'aaaa-aaa bbbb*bbb')
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
217 self.dex.add_text(('test', '2', 'a'), 'aaaA-aaa BBBB*BBB')
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
218 for k in 'aaaa', 'aaa', 'bbbb', 'bbb':
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
219 self.assertSeqEqual(self.dex.find([k]),
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
220 [('test', '1', 'a'), ('test', '2', 'a')])
b41a033bffcc - add a small word-splitting test for the indexers...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4251
diff changeset
221
4841
3ff1a288fb9c issue2550583, issue2550635 Do not limit results with Xapian indexer
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4570
diff changeset
222 def test_manyresults(self):
3ff1a288fb9c issue2550583, issue2550635 Do not limit results with Xapian indexer
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4570
diff changeset
223 """Test if searches find many results."""
3ff1a288fb9c issue2550583, issue2550635 Do not limit results with Xapian indexer
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4570
diff changeset
224 for i in range(123):
3ff1a288fb9c issue2550583, issue2550635 Do not limit results with Xapian indexer
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4570
diff changeset
225 self.dex.add_text(('test', str(i), 'many'), 'many')
3ff1a288fb9c issue2550583, issue2550635 Do not limit results with Xapian indexer
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4570
diff changeset
226 self.assertEqual(len(self.dex.find(['many'])), 123)
3ff1a288fb9c issue2550583, issue2550635 Do not limit results with Xapian indexer
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4570
diff changeset
227
5960
0db2621b6fee Add test for issue1344046 and maybe issue1195739
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
228 def test_unicode(self):
0db2621b6fee Add test for issue1344046 and maybe issue1195739
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
229 """Test with unicode words. see:
0db2621b6fee Add test for issue1344046 and maybe issue1195739
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
230 https://issues.roundup-tracker.org/issue1344046"""
5962
6137ea845438 Fix russian search/string
John Rouillard <rouilj@ieee.org>
parents: 5961
diff changeset
231 russian=u'\u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u0442\u0435\u043a\u0441\u0442Spr\xfcnge'
5961
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
232 german=u'Spr\xfcnge'
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
233 self.dex.add_text(('test', '1', 'a'), german )
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
234 self.dex.add_text(('test', '2', 'a'), russian + u' ' + german )
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
235
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
236 self.assertSeqEqual(self.dex.find([ u'Spr\xfcnge']),
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
237 [('test', '1', 'a'), ('test', '2', 'a')])
5962
6137ea845438 Fix russian search/string
John Rouillard <rouilj@ieee.org>
parents: 5961
diff changeset
238 self.assertSeqEqual(self.dex.find([u'\u0440\u0443\u0441\u0441\u043a\u0438\u0439']),
5961
f6c58a7b535c Add a russian string for unicode testing of indexer
John Rouillard <rouilj@ieee.org>
parents: 5960
diff changeset
239 [('test', '2', 'a')])
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
240
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
241 def testNullChar(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
242 """Test with null char in string. Postgres FTS will not index
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
243 it will just ignore string for now.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
244 """
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
245 string="\x00\x01fred\x255"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
246 self.dex.add_text(('test', '1', 'a'), string)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
247 self.assertSeqEqual(self.dex.find(string), [])
5960
0db2621b6fee Add test for issue1344046 and maybe issue1195739
John Rouillard <rouilj@ieee.org>
parents: 5649
diff changeset
248
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
249 def tearDown(self):
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
250 shutil.rmtree('test-index')
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
251 if hasattr(self, 'db'):
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
252 self.db.close()
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
253 if os.path.exists(config.DATABASE):
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
254 shutil.rmtree(config.DATABASE)
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
255
5096
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
256 @skip_whoosh
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
257 class WhooshIndexerTest(IndexerTest):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
258
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
259 indexer_name = "whoosh"
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
260
5096
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
261 def setUp(self):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
262 IndexerTest.setUp(self)
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
263
5096
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
264 if os.path.exists('test-index'):
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
265 shutil.rmtree('test-index')
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
266 os.mkdir('test-index')
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
267 from roundup.backends.indexer_whoosh import Indexer
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
268 self.dex = Indexer(db)
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5038
diff changeset
269 def tearDown(self):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
270 IndexerTest.tearDown(self)
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
271
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
272 @skip_xapian
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
273 class XapianIndexerTest(IndexerTest):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
274
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
275 indexer_name = "xapian"
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
276
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
277 def setUp(self):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
278 IndexerTest.setUp(self)
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
279
3297
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
280 if os.path.exists('test-index'):
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
281 shutil.rmtree('test-index')
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
282 os.mkdir('test-index')
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
283 from roundup.backends.indexer_xapian import Indexer
3297
8f7dc283bfa5 some more Xapian stuff (doc, test fixes)
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
284 self.dex = Indexer(db)
3295
a615cc230160 added Xapian indexer; replaces standard indexers if Xapian is available
Richard Jones <richard@users.sourceforge.net>
parents: 3078
diff changeset
285 def tearDown(self):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
286 IndexerTest.tearDown(self)
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
287
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
288 class Get_IndexerTest(anydbmOpener, unittest.TestCase):
6912
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
289
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
290 def setUp(self):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
291 # remove previous test, ignore errors
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
292 if os.path.exists(config.DATABASE):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
293 shutil.rmtree(config.DATABASE)
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
294 self.db = self.module.Database(config, 'admin')
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
295 # this is the default, but set it in case default
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
296 # changes in future
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
297 self.db.config['INDEXER'] = ''
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
298
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
299 def tearDown(self):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
300 if hasattr(self, 'db'):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
301 self.db.close()
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
302 if os.path.exists(config.DATABASE):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
303 shutil.rmtree(config.DATABASE)
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
304
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
305 @skip_xapian
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
306 def test_xapian_autoselect(self):
6912
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
307 indexer = get_indexer(self.db.config, self.db)
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
308 self.assertIn('roundup.backends.indexer_xapian.Indexer', str(indexer))
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
309
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
310 @skip_whoosh
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
311 def test_whoosh_autoselect(self):
6912
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
312 with mock.patch.dict('sys.modules',
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
313 {'roundup.backends.indexer_xapian': None}):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
314 indexer = get_indexer(self.db.config, self.db)
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
315 self.assertIn('roundup.backends.indexer_whoosh.Indexer', str(indexer))
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
316
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
317 def test_native_autoselect(self):
6912
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
318 with mock.patch.dict('sys.modules',
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
319 {'roundup.backends.indexer_xapian': None,
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
320 'roundup.backends.indexer_whoosh': None}):
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
321 indexer = get_indexer(self.db.config, self.db)
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
322 self.assertIn('roundup.backends.indexer_dbm.Indexer', str(indexer))
a23eaa3013e6 test get_indexer three autosearch options: xapian, whoosh, native
John Rouillard <rouilj@ieee.org>
parents: 6909
diff changeset
323
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
324 def test_invalid_indexer(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
325 """There is code at the end of indexer_common::get_indexer() to
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
326 raise an AssertionError if the indexer name is invalid.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
327 This should never be triggered. If it is, it means that
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
328 the code in configure.py that validates indexer names
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
329 allows a name through that get_indexer can't handle.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
330
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
331 Simulate that failure and make sure that the
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
332 AssertionError is raised.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
333
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
334 """
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
335
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
336 with self.assertRaises(ValueError) as cm:
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
337 self.db.config['INDEXER'] = 'no_such_indexer'
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
338
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
339 # mangle things so we can test AssertionError at end
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
340 # get_indexer()
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
341 from roundup.configuration import IndexerOption
7851
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
342 io_orig = IndexerOption.allowed
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
343 io = list(io_orig)
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
344 io.append("unrecognized_indexer")
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
345 IndexerOption.allowed = tuple(io)
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
346 self.db.config['INDEXER'] = "unrecognized_indexer"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
347
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
348 with self.assertRaises(AssertionError) as cm:
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
349 indexer = get_indexer(self.db.config, self.db)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
350
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
351 # unmangle state
7851
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
352 IndexerOption.allowed = io_orig
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
353 self.assertNotIn("unrecognized_indexer", IndexerOption.allowed)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
354 self.db.config['INDEXER'] = ""
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
355
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
356 def test_unsupported_by_db(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
357 """This requires that the db associated with the test
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
358 is not sqlite or postgres. anydbm works fine to trigger
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
359 the error.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
360 """
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
361 self.db.config['INDEXER'] = 'native-fts'
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
362 with self.assertRaises(AssertionError) as cm:
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
363 get_indexer(self.db.config, self.db)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
364
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
365 self.assertIn("native-fts", cm.exception.args[0])
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
366 self.db.config['INDEXER'] = ''
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
367
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
368 class RDBMSIndexerTest(object):
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
369 def setUp(self):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
370 # remove previous test, ignore errors
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
371 if os.path.exists(config.DATABASE):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
372 shutil.rmtree(config.DATABASE)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
373 self.db = self.module.Database(config, 'admin')
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
374 self.dex = Indexer(self.db)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
375 def tearDown(self):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
376 if hasattr(self, 'db'):
7904
94aafe3b0a0d issue2551334 - get more tests working under windows
John Rouillard <rouilj@ieee.org>
parents: 7851
diff changeset
377 # commit any outstanding cursors.
94aafe3b0a0d issue2551334 - get more tests working under windows
John Rouillard <rouilj@ieee.org>
parents: 7851
diff changeset
378 # close() doesn't actually close file handle on
94aafe3b0a0d issue2551334 - get more tests working under windows
John Rouillard <rouilj@ieee.org>
parents: 7851
diff changeset
379 # windows unless commit() is called.
94aafe3b0a0d issue2551334 - get more tests working under windows
John Rouillard <rouilj@ieee.org>
parents: 7851
diff changeset
380 self.db.commit()
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
381 self.db.close()
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
382 if os.path.exists(config.DATABASE):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
383 shutil.rmtree(config.DATABASE)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
384
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
385
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
386 @skip_postgresql
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
387 class postgresqlIndexerTest(postgresqlOpener, RDBMSIndexerTest, IndexerTest):
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
388 def setUp(self):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
389 postgresqlOpener.setUp(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
390 RDBMSIndexerTest.setUp(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
391 def tearDown(self):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
392 RDBMSIndexerTest.tearDown(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
393 postgresqlOpener.tearDown(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
394
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
395
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
396 @skip_postgresql
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
397 class postgresqlFtsIndexerTest(postgresqlOpener, RDBMSIndexerTest, IndexerTest):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
398
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
399 indexer_name = "native-fts"
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
400
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
401 def setUp(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
402 postgresqlOpener.setUp(self)
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
403 RDBMSIndexerTest.setUp(self)
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
404 from roundup.backends.indexer_postgresql_fts import Indexer
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
405 self.dex = Indexer(self.db)
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
406 self.dex.db = self.db
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
407
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
408 def tearDown(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
409 RDBMSIndexerTest.tearDown(self)
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
410 postgresqlOpener.tearDown(self)
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
411
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
412 def test_websearch_syntax(self):
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
413 """Test searches using websearch_to_tsquery. These never throw
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
414 errors regardless of how wacky the input.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
415 """
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
416
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
417 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
418 self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
419 self.dex.add_text(('test', '3', 'foo'), 'blah hello the world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
420 self.dex.add_text(('test', '4', 'foo'), 'hello blah blech the world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
421 self.dex.add_text(('test', '5', 'foo'), 'a car drove')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
422 self.dex.add_text(('test', '6', 'foo'), 'a car driving itself')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
423 self.dex.add_text(('test', '7', 'foo'), "let's drive in the car")
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
424 self.dex.add_text(('test', '8', 'foo'), 'a drive-in movie')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
425
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
426 # test two separate words for sanity
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
427 self.assertSeqEqual(self.dex.find(['"hello" "world"']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
428 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
429 ('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
430 ('test', '4', 'foo')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
431 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
432 # now check the phrase
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
433 self.assertSeqEqual(self.dex.find(['"hello world"']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
434 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
435 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
436
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
437 # test negation
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
438 self.assertSeqEqual(self.dex.find(['hello world -blech']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
439 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
440 ('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
441 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
442
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
443 # phrase negation
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
444 self.assertSeqEqual(self.dex.find(['hello world -"blah hello"']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
445 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
446 ('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
447 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
448
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
449 # test without or
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
450 self.assertSeqEqual(self.dex.find(['blah blech']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
451 [('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
452 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
453
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
454 # test with or
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
455 self.assertSeqEqual(self.dex.find(['blah or blech']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
456 [ ('test', '2', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
457 ('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
458 ('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
459 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
460
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
461 # stemmer test for english
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
462 self.assertSeqEqual(self.dex.find(['ts:drive']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
463 [('test', '6', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
464 ('test', '7', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
465 ('test', '8', 'foo')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
466 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
467
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
468 # stemmer is not disabled by quotes 8-(
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
469 self.assertSeqEqual(self.dex.find(['ts:"drive"']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
470 [('test', '6', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
471 ('test', '7', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
472 ('test', '8', 'foo')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
473 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
474
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
475
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
476 # this is missing ts: at the start, so uses the websearch
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
477 # parser. We search for operator characters and wanr the user
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
478 # Otherwise "hello <-> world" is the same as "hello world"
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
479 # and is not a phrase search.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
480 with self.assertRaises(IndexerQueryError) as ctx:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
481 self.dex.find(['hello <-> world'])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
482
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
483 self.assertIn('do a tsquery search', ctx.exception.args[0])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
484
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
485 def test_tsquery_syntax(self):
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
486 """Because websearch_to_tsquery doesn't allow prefix searches,
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
487 near searches with any value except 1 (phrase search), allow
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
488 use of to_tsquery by prefixing the search term wih ts:.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
489
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
490 However, unlike websearch_to_tsquery, this will throw a
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
491 psycopg2.errors.SyntaxError on bad input. SyntaxError is
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
492 re-raised as IndexerQueryError. But it makes a bunch of
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
493 useful expert functionality available.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
494
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
495 """
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
496
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
497 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
498 self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
499 self.dex.add_text(('test', '3', 'foo'), 'blah hello the world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
500 self.dex.add_text(('test', '4', 'foo'), 'hello blah blech the world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
501 self.dex.add_text(('test', '5', 'foo'), 'a car drove')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
502 self.dex.add_text(('test', '6', 'foo'), 'a car driving itself')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
503 self.dex.add_text(('test', '7', 'foo'), "let's drive in the car")
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
504 self.dex.add_text(('test', '8', 'foo'), 'a drive-in movie')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
505 self.dex.db.commit()
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
506
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
507 # test two separate words for sanity
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
508 self.assertSeqEqual(self.dex.find(['ts:hello & world']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
509 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
510 ('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
511 ('test', '4', 'foo')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
512 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
513 # now check the phrase
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
514 self.assertSeqEqual(self.dex.find(['ts:hello <-> world']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
515 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
516 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
517
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
518 # test negation
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
519 self.assertSeqEqual(self.dex.find(['ts:hello & world & !blech']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
520 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
521 ('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
522 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
523
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
524 self.assertSeqEqual(self.dex.find(
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
525 ['ts:hello & world & !(blah <-> hello)']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
526 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
527 ('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
528 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
529
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
530 # test without or
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
531 self.assertSeqEqual(self.dex.find(['ts:blah & blech']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
532 [('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
533 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
534
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
535 # test with or
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
536 self.assertSeqEqual(self.dex.find(['ts:blah | blech']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
537 [ ('test', '2', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
538 ('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
539 ('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
540 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
541 # stemmer test for english
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
542 self.assertSeqEqual(self.dex.find(['ts:drive']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
543 [('test', '6', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
544 ('test', '7', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
545 ('test', '8', 'foo')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
546 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
547
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
548 # stemmer is not disabled by quotes 8-(
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
549 self.assertSeqEqual(self.dex.find(['ts:"drive"']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
550 [('test', '6', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
551 ('test', '7', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
552 ('test', '8', 'foo')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
553 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
554
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
555
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
556 # test with syntax error
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
557 with self.assertRaises(IndexerQueryError) as ctx:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
558 self.dex.find(['ts:blah blech'])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
559
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
560 self.assertEqual(ctx.exception.args[0],
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
561 'syntax error in tsquery: "blah blech"\n')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
562
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
563 # now check the phrase Note unlike sqlite, order matters,
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
564 # hello must come first.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
565 self.assertSeqEqual(self.dex.find(['ts:hello <-> world']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
566 [('test', '1', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
567 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
568
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
569 # now check the phrase with explicitly 1 intervening item
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
570 self.assertSeqEqual(self.dex.find(['ts:hello <2> world']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
571 [('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
572 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
573 # now check the phrase with near explicitly 1 or 3 intervening items
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
574 self.assertSeqEqual(self.dex.find([
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
575 'ts:(hello <4> world) | (hello<2>world)']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
576 [('test', '3', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
577 ('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
578 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
579
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
580 # now check the phrase with near explicitly 3 intervening item
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
581 # with prefix for world.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
582 self.assertSeqEqual(self.dex.find(['ts:hello <4> wor:*']),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
583 [('test', '4', 'foo'),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
584 ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
585
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
586 def test_invalid_language(self):
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
587 import psycopg2
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
588
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
589 from roundup.configuration import IndexerOption
7851
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
590 io_orig = IndexerOption.valid_langs
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
591
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
592 io = list(io_orig)
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
593 io.append("foo")
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
594 self.db.config["INDEXER_LANGUAGE"] = "foo"
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
595
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
596 with self.assertRaises(psycopg2.errors.UndefinedObject) as ctx:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
597 # psycopg2.errors.UndefinedObject: text search configuration
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
598 # "foo" does not exist
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
599 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
600 self.assertIn('search configuration "foo" does', ctx.exception.args[0])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
601 self.db.rollback()
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
602
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
603 with self.assertRaises(ValueError) as ctx:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
604 self.dex.find(['"hello" "world"'])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
605 self.assertIn('search configuration "foo" does', ctx.exception.args[0])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
606 self.db.rollback()
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
607
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
608 self.db.config["INDEXER_LANGUAGE"] = "english"
7851
5be92f16a684 test: fix test_indexer for change from list to tuples in config.
John Rouillard <rouilj@ieee.org>
parents: 7690
diff changeset
609 IndexerOption.valid_langs = io_orig
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
610
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
611 def testNullChar(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
612 """Test with null char in string. Postgres FTS throws a ValueError
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
613 on indexing which we ignore. This could happen when
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
614 indexing a binary file with a bad mime type. On find, it
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
615 throws a ProgrammingError that we remap to
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
616 IndexerQueryError and pass up. If a null gets to that
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
617 level on search somebody entered it (not sure how you
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
618 could actually do that) but we want a crash in that case
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
619 as the person is probably up to "no good" (R) (TM).
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
620
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
621 """
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
622 import psycopg2
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
623
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
624 string="\x00\x01fred\x255"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
625 self.dex.add_text(('test', '1', 'a'), string)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
626 with self.assertRaises(IndexerQueryError) as ctx:
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
627 self.assertSeqEqual(self.dex.find(string), [])
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
628
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
629 self.assertIn("null", ctx.exception.args[0])
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
630
5036
380d8d8b30a3 Replace existing run_tests.py script with a pytest script
John Kristensen <john@jerrykan.com>
parents: 5033
diff changeset
631 @skip_mysql
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
632 class mysqlIndexerTest(mysqlOpener, RDBMSIndexerTest, IndexerTest):
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
633 def setUp(self):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
634 mysqlOpener.setUp(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
635 RDBMSIndexerTest.setUp(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
636 def tearDown(self):
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
637 RDBMSIndexerTest.tearDown(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
638 mysqlOpener.tearDown(self)
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
639
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
640
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4841
diff changeset
641 class sqliteIndexerTest(sqliteOpener, RDBMSIndexerTest, IndexerTest):
4008
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
642 pass
0bf9f8ae7d1b fix bug introduced in 1.4.5 in RDBMS full-text indexing;
Richard Jones <richard@users.sourceforge.net>
parents: 3547
diff changeset
643
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
644 class sqliteFtsIndexerTest(sqliteOpener, RDBMSIndexerTest, IndexerTest):
6909
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
645
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
646 indexer_name = "native-fts"
86cde9cae7e1 Improve test coverage of backends/indexer_common::get_indexer() method
John Rouillard <rouilj@ieee.org>
parents: 6908
diff changeset
647
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
648 def setUp(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
649 RDBMSIndexerTest.setUp(self)
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
650 from roundup.backends.indexer_sqlite_fts import Indexer
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6599
diff changeset
651 self.dex = Indexer(self.db)
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
652 self.dex.db = self.db
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
653
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
654 def test_phrase_and_near(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
655 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
656 self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
657 self.dex.add_text(('test', '3', 'foo'), 'blah hello the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
658 self.dex.add_text(('test', '4', 'foo'), 'hello blah blech the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
659
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
660 # test two separate words for sanity
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
661 self.assertSeqEqual(self.dex.find(['"hello" "world"']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
662 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
663 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
664 ('test', '4', 'foo')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
665 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
666 # now check the phrase
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
667 self.assertSeqEqual(self.dex.find(['"hello world"']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
668 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
669 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
670
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
671 # now check the phrase with near explicitly 0 intervening items
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
672 self.assertSeqEqual(self.dex.find(['NEAR(hello world, 0)']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
673 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
674 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
675
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
676 # now check the phrase with near explicitly 1 intervening item
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
677 self.assertSeqEqual(self.dex.find(['NEAR(hello world, 1)']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
678 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
679 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
680 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
681 # now check the phrase with near explicitly 3 intervening item
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
682 self.assertSeqEqual(self.dex.find(['NEAR(hello world, 3)']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
683 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
684 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
685 ('test', '4', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
686 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
687
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
688 def test_prefix(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
689 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
690 self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
691 self.dex.add_text(('test', '3', 'foo'), 'blah hello the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
692 self.dex.add_text(('test', '4', 'foo'), 'hello blah blech the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
693
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
694 self.assertSeqEqual(self.dex.find(['hel*']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
695 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
696 ('test', '2', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
697 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
698 ('test', '4', 'foo')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
699 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
700
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
701
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
702 def test_bool_start(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
703 self.dex.add_text(('test', '1', 'foo'), 'a the hello world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
704 self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
705 self.dex.add_text(('test', '3', 'foo'), 'blah hello the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
706 self.dex.add_text(('test', '4', 'foo'), 'hello blah blech the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
707
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
708 self.assertSeqEqual(self.dex.find(['hel* NOT helh NOT blech']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
709 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
710 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
711 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
712
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
713 self.assertSeqEqual(self.dex.find(['hel* NOT helh NOT blech OR the']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
714 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
715 ('test', '2', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
716 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
717 ('test', '4', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
718 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
719
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
720 self.assertSeqEqual(self.dex.find(['helh OR hello']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
721 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
722 ('test', '2', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
723 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
724 ('test', '4', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
725 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
726
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
727
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
728 self.assertSeqEqual(self.dex.find(['helh AND hello']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
729 [])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
730 # matches if line starts with hello
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
731 self.assertSeqEqual(self.dex.find(['^hello']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
732 [
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
733 ('test', '4', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
734 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
735
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
736 self.assertSeqEqual(self.dex.find(['hello']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
737 [
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
738 ('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
739 ('test', '3', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
740 ('test', '4', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
741 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
742
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
743 def test_query_errors(self):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
744 """test query phrases that generate an error. Also test the
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
745 correction"""
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
746
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
747 self.dex.add_text(('test', '1', 'foo'), 'a the hello-world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
748 self.dex.add_text(('test', '2', 'foo'), 'helh blah blah the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
749 self.dex.add_text(('test', '3', 'foo'), 'blah hello the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
750 self.dex.add_text(('test', '4', 'foo'), 'hello blah blech the world')
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
751
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
752 # handle known error that roundup recognizes and tries to diagnose
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
753 with self.assertRaises(IndexerQueryError) as ctx:
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
754 self.dex.find(['the hello-world'])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
755
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
756 error = ( "Search failed. Try quoting any terms that include a '-' "
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
757 "and retry the search.")
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
758 self.assertEqual(str(ctx.exception), error)
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
759
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
760
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
761 self.assertSeqEqual(self.dex.find(['the "hello-world"']),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
762 [('test', '1', 'foo'),
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
763 ])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
764
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
765 # handle known error that roundup recognizes and tries to diagnose
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
766 with self.assertRaises(IndexerQueryError) as ctx:
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
767 self.dex.find(['hello world + ^the'])
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
768
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
769 error = 'Query error: syntax error near "^"'
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
770 self.assertEqual(str(ctx.exception), error)
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
771
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
772 def testNullChar(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
773 """Test with null char in string. FTS will throw
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
774 an error on null.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
775 """
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
776 string="\x00\x01fred\x255"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
777 self.dex.add_text(('test', '1', 'a'), string)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
778 with self.assertRaises(IndexerQueryError) as cm:
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
779 self.assertSeqEqual(self.dex.find(string), [])
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6912
diff changeset
780
848
2a928d404af8 ehem, forgot to add
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
781 # vim: set filetype=python ts=4 sw=4 et si

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