2010-08-04 11:25:30 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_searchadapters
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the Web Support Package search adapters.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2010-08-04 11:25:30 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
2014-04-30 07:30:46 -05:00
|
|
|
from six import StringIO
|
2010-08-04 11:25:30 -05:00
|
|
|
|
|
|
|
from sphinx.websupport import WebSupport
|
|
|
|
|
2010-08-21 16:03:06 -05:00
|
|
|
from test_websupport import sqlalchemy_missing
|
2014-09-21 10:17:02 -05:00
|
|
|
from util import rootdir, tempdir, skip_if, skip_unless_importable
|
2010-08-04 11:25:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
def teardown_module():
|
2014-09-21 10:17:02 -05:00
|
|
|
(tempdir / 'websupport').rmtree(True)
|
2010-08-04 11:25:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
def search_adapter_helper(adapter):
|
2014-09-21 10:17:02 -05:00
|
|
|
settings = {'srcdir': rootdir / 'root',
|
|
|
|
'builddir': tempdir / 'websupport',
|
2014-04-30 07:30:46 -05:00
|
|
|
'status': StringIO(),
|
2014-09-21 10:17:02 -05:00
|
|
|
'warning': StringIO(),
|
|
|
|
'search': adapter}
|
2010-08-04 11:25:30 -05:00
|
|
|
support = WebSupport(**settings)
|
|
|
|
support.build()
|
|
|
|
|
|
|
|
s = support.search
|
|
|
|
|
|
|
|
# Test the adapters query method. A search for "Epigraph" should return
|
|
|
|
# one result.
|
|
|
|
results = s.query(u'Epigraph')
|
|
|
|
assert len(results) == 1, \
|
|
|
|
'%s search adapter returned %s search result(s), should have been 1'\
|
|
|
|
% (adapter, len(results))
|
|
|
|
|
|
|
|
# Make sure documents are properly updated by the search adapter.
|
|
|
|
s.init_indexing(changed=['markup'])
|
|
|
|
s.add_document(u'markup', u'title', u'SomeLongRandomWord')
|
|
|
|
s.finish_indexing()
|
|
|
|
# Now a search for "Epigraph" should return zero results.
|
|
|
|
results = s.query(u'Epigraph')
|
|
|
|
assert len(results) == 0, \
|
|
|
|
'%s search adapter returned %s search result(s), should have been 0'\
|
|
|
|
% (adapter, len(results))
|
|
|
|
# A search for "SomeLongRandomWord" should return one result.
|
|
|
|
results = s.query(u'SomeLongRandomWord')
|
|
|
|
assert len(results) == 1, \
|
|
|
|
'%s search adapter returned %s search result(s), should have been 1'\
|
|
|
|
% (adapter, len(results))
|
2010-08-04 13:09:07 -05:00
|
|
|
# Make sure it works through the WebSupport API
|
2014-09-21 10:17:02 -05:00
|
|
|
support.get_search_results(u'SomeLongRandomWord')
|
2010-08-04 13:09:07 -05:00
|
|
|
|
2010-08-04 11:25:30 -05:00
|
|
|
|
2010-08-21 16:03:06 -05:00
|
|
|
@skip_unless_importable('xapian', 'needs xapian bindings installed')
|
|
|
|
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
|
2010-08-04 11:25:30 -05:00
|
|
|
def test_xapian():
|
2010-08-21 16:03:06 -05:00
|
|
|
search_adapter_helper('xapian')
|
2010-08-04 11:25:30 -05:00
|
|
|
|
|
|
|
|
2010-08-21 16:03:06 -05:00
|
|
|
@skip_unless_importable('whoosh', 'needs whoosh package installed')
|
|
|
|
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
|
2010-08-04 11:25:30 -05:00
|
|
|
def test_whoosh():
|
2010-08-21 16:03:06 -05:00
|
|
|
search_adapter_helper('whoosh')
|