comparison MoinMoin/search/_tests/test_search.py @ 4974:eb5644419456

Xapian2009: pagename field now is sortable. test_search.py pep8 fixes, TestSearch is done for both Moin and Xapian searchers.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Mon, 03 Aug 2009 19:23:54 +0200
parents 75c067fb7d1b
children 2171281b6d79
comparison
equal deleted inserted replaced
4973:2f16bd87444d 4974:eb5644419456
5 @copyright: 2005 by Nir Soffer <nirs@freeshell.org>, 5 @copyright: 2005 by Nir Soffer <nirs@freeshell.org>,
6 2007 by MoinMoin:ThomasWaldmann 6 2007 by MoinMoin:ThomasWaldmann
7 @license: GNU GPL, see COPYING for details. 7 @license: GNU GPL, see COPYING for details.
8 """ 8 """
9 9
10
10 import py 11 import py
11 12
12 from MoinMoin.search import QueryError 13 from MoinMoin.search import QueryError
13 from MoinMoin.search.queryparser import QueryParser 14 from MoinMoin.search.queryparser import QueryParser
14 from MoinMoin.search import Xapian 15 from MoinMoin.search import Xapian
15 from MoinMoin import search 16 from MoinMoin import search
16 from MoinMoin._tests import nuke_xapian_index 17 from MoinMoin._tests import nuke_xapian_index, wikiconfig
18
17 19
18 class TestQueryParsing: 20 class TestQueryParsing:
19 """ search: query parser tests """ 21 """ search: query parser tests """
20 22
21 def testQueryParser(self): 23 def testQueryParser(self):
60 assert str(result) == wanted 62 assert str(result) == wanted
61 63
62 def testQueryParserExceptions(self): 64 def testQueryParserExceptions(self):
63 """ search: test the query parser """ 65 """ search: test the query parser """
64 parser = QueryParser() 66 parser = QueryParser()
67
65 def _test(q): 68 def _test(q):
66 py.test.raises(QueryError, parser.parse_query, q) 69 py.test.raises(QueryError, parser.parse_query, q)
70
67 for query in ['""', '(', ')', '(a or b']: 71 for query in ['""', '(', ')', '(a or b']:
68 yield _test, query 72 yield _test, query
73
69 74
70 class TestSearch: 75 class TestSearch:
71 """ search: test search """ 76 """ search: test search """
72 doesnotexist = u'jfhsdaASDLASKDJ' 77 doesnotexist = u'jfhsdaASDLASKDJ'
73 78
106 """ search: full search for a AND expression with a negative term """ 111 """ search: full search for a AND expression with a negative term """
107 helpon_count = len(search.searchPages(self.request, u"HelpOn").hits) 112 helpon_count = len(search.searchPages(self.request, u"HelpOn").hits)
108 result = search.searchPages(self.request, u"HelpOn -ACL") 113 result = search.searchPages(self.request, u"HelpOn -ACL")
109 assert 0 < len(result.hits) < helpon_count 114 assert 0 < len(result.hits) < helpon_count
110 115
116 def test_title_search(self):
111 117
112 class TestXapianIndex: 118 query = QueryParser(titlesearch=True).parse_query('Moin')
119 result = search.searchPages(self.request, query, sort='page_name')
120
121
122 class TestXapianIndex(TestSearch):
113 """ search: test Xapian indexing """ 123 """ search: test Xapian indexing """
124 # XXX skip it if xapian is not available
114 125
115 def testIndex(self): 126 class Config(wikiconfig.Config):
127
128 xapian_search = True
129
130 def setup_class(self):
116 """ search: kicks off indexing for a single pages in Xapian """ 131 """ search: kicks off indexing for a single pages in Xapian """
117 # This only tests that the call to indexing doesn't raise. 132 # This only tests that the call to indexing doesn't raise.
118 nuke_xapian_index(self.request) 133 nuke_xapian_index(self.request)
119 idx = Xapian.Index(self.request) 134 idx = Xapian.Index(self.request)
120 idx.indexPages(mode='add') # slow: builds an index of all pages 135 idx.indexPages(mode='add') # slow: builds an index of all pages
121 136
122 def testIndexInNewThread(self): 137 def teardown_class(self):
123 """ search: kicks off indexing for a page in a new thread in Xapian""" 138 nuke_xapian_index(self.request)
139
140
141 class TestXapianInNewThread(object):
142 """ search: test Xapian indexing """
143 # XXX skip it if xapian is not available
144
145 def setup_class(self):
146 """ search: kicks off indexing for a single pages in Xapian """
124 # This only tests that the call to indexing doesn't raise. 147 # This only tests that the call to indexing doesn't raise.
125 nuke_xapian_index(self.request) 148 nuke_xapian_index(self.request)
126 idx = Xapian.Index(self.request) 149 idx = Xapian.Index(self.request)
127 idx.indexPagesInNewThread(mode='add') # slow: builds an index of all pages 150 idx.indexPagesInNewThread(mode='add') # slow: builds an index of all pages
128 151
152 def teardown_class(self):
153 nuke_xapian_index(self.request)
154
155
129 coverage_modules = ['MoinMoin.search'] 156 coverage_modules = ['MoinMoin.search']
130 157