mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added basic search tests.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os, sys
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from sphinx.websupport import WebSupport
|
from sphinx.websupport import WebSupport
|
||||||
@@ -24,15 +24,22 @@ except ImportError:
|
|||||||
from util import *
|
from util import *
|
||||||
|
|
||||||
|
|
||||||
def teardown_module():
|
default_settings = {'outdir': os.path.join(test_root, 'websupport'),
|
||||||
|
'status': StringIO(),
|
||||||
|
'warning': StringIO()}
|
||||||
|
|
||||||
|
|
||||||
|
def clear_builddir():
|
||||||
(test_root / 'websupport').rmtree(True)
|
(test_root / 'websupport').rmtree(True)
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_module():
|
||||||
|
clear_builddir()
|
||||||
|
|
||||||
|
|
||||||
def with_support(*args, **kwargs):
|
def with_support(*args, **kwargs):
|
||||||
"""Make a WebSupport object and pass it the test."""
|
"""Make a WebSupport object and pass it the test."""
|
||||||
settings = {'outdir': os.path.join(test_root, 'websupport'),
|
settings = default_settings.copy()
|
||||||
'status': StringIO(),
|
|
||||||
'warning': StringIO()}
|
|
||||||
settings.update(kwargs)
|
settings.update(kwargs)
|
||||||
|
|
||||||
def generator(func):
|
def generator(func):
|
||||||
@@ -49,10 +56,12 @@ def test_no_srcdir(support):
|
|||||||
"""Make sure the correct exception is raised if srcdir is not given."""
|
"""Make sure the correct exception is raised if srcdir is not given."""
|
||||||
raises(SrcdirNotSpecifiedError, support.build)
|
raises(SrcdirNotSpecifiedError, support.build)
|
||||||
|
|
||||||
|
|
||||||
@with_support(srcdir=test_root)
|
@with_support(srcdir=test_root)
|
||||||
def test_build(support):
|
def test_build(support):
|
||||||
support.build()
|
support.build()
|
||||||
|
|
||||||
|
|
||||||
@with_support()
|
@with_support()
|
||||||
def test_get_document(support):
|
def test_get_document(support):
|
||||||
raises(DocumentNotFoundError, support.get_document, 'nonexisting')
|
raises(DocumentNotFoundError, support.get_document, 'nonexisting')
|
||||||
@@ -60,3 +69,34 @@ def test_get_document(support):
|
|||||||
contents = support.get_document('contents')
|
contents = support.get_document('contents')
|
||||||
assert contents['title'] and contents['body'] \
|
assert contents['title'] and contents['body'] \
|
||||||
and contents['sidebar'] and contents['relbar']
|
and contents['sidebar'] and contents['relbar']
|
||||||
|
|
||||||
|
|
||||||
|
def search_adapter_helper(adapter):
|
||||||
|
clear_builddir()
|
||||||
|
|
||||||
|
settings = default_settings.copy()
|
||||||
|
settings.update({'srcdir': test_root,
|
||||||
|
'search': adapter})
|
||||||
|
support = WebSupport(**settings)
|
||||||
|
|
||||||
|
support.build()
|
||||||
|
|
||||||
|
|
||||||
|
def test_xapian():
|
||||||
|
# Don't run tests if xapian is not installed.
|
||||||
|
try:
|
||||||
|
import xapian
|
||||||
|
search_adapter_helper('xapian')
|
||||||
|
except ImportError:
|
||||||
|
sys.stderr.write('info: not running xapian tests, ' \
|
||||||
|
'xapian doesn\'t seem to be installed')
|
||||||
|
|
||||||
|
|
||||||
|
def test_whoosh():
|
||||||
|
# Don't run tests if xapian is not installed.
|
||||||
|
try:
|
||||||
|
import whoosh
|
||||||
|
search_adapter_helper('whoosh')
|
||||||
|
except ImportError:
|
||||||
|
sys.stderr.write('info: not running xapian tests, ' \
|
||||||
|
'whoosh doesn\'t seem to be installed')
|
||||||
|
|||||||
Reference in New Issue
Block a user