mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added test for build and made web support buildable without specifying search adapter
This commit is contained in:
parent
0039b09a36
commit
f014641405
@ -10,7 +10,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
import re
|
import re, sys
|
||||||
from os import path
|
from os import path
|
||||||
from cgi import escape
|
from cgi import escape
|
||||||
from difflib import Differ
|
from difflib import Differ
|
||||||
@ -35,7 +35,7 @@ class WebSupport(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, srcdir='', outdir='', datadir='', search=None,
|
def __init__(self, srcdir='', outdir='', datadir='', search=None,
|
||||||
storage=None):
|
storage=None, status=sys.stdout, warning=sys.stderr):
|
||||||
self.srcdir = srcdir
|
self.srcdir = srcdir
|
||||||
self.outdir = outdir or path.join(self.srcdir, '_build',
|
self.outdir = outdir or path.join(self.srcdir, '_build',
|
||||||
'websupport')
|
'websupport')
|
||||||
@ -43,9 +43,10 @@ class WebSupport(object):
|
|||||||
|
|
||||||
self.outdir = outdir or datadir
|
self.outdir = outdir or datadir
|
||||||
|
|
||||||
if search is not None:
|
self.status = status
|
||||||
self._init_search(search)
|
self.warning = warning
|
||||||
|
|
||||||
|
self._init_search(search)
|
||||||
self._init_storage(storage)
|
self._init_storage(storage)
|
||||||
|
|
||||||
def _init_storage(self, storage):
|
def _init_storage(self, storage):
|
||||||
@ -73,11 +74,11 @@ class WebSupport(object):
|
|||||||
if isinstance(search, BaseSearch):
|
if isinstance(search, BaseSearch):
|
||||||
self.search = search
|
self.search = search
|
||||||
else:
|
else:
|
||||||
mod, cls = search_adapters[search]
|
mod, cls = search_adapters[search or 'null']
|
||||||
search_class = getattr(__import__('sphinx.websupport.search.' + mod,
|
mod = 'sphinx.websupport.search.' + mod
|
||||||
None, None, [cls]), cls)
|
SearchClass = getattr(__import__(mod, None, None, [cls]), cls)
|
||||||
search_path = path.join(self.outdir, 'search')
|
search_path = path.join(self.outdir, 'search')
|
||||||
self.search = search_class(search_path)
|
self.search = SearchClass(search_path)
|
||||||
self.results_template = \
|
self.results_template = \
|
||||||
self.template_env.get_template('searchresults.html')
|
self.template_env.get_template('searchresults.html')
|
||||||
|
|
||||||
@ -95,8 +96,8 @@ class WebSupport(object):
|
|||||||
doctreedir = path.join(self.outdir, 'doctrees')
|
doctreedir = path.join(self.outdir, 'doctrees')
|
||||||
app = WebSupportApp(self.srcdir, self.srcdir,
|
app = WebSupportApp(self.srcdir, self.srcdir,
|
||||||
self.outdir, doctreedir, 'websupport',
|
self.outdir, doctreedir, 'websupport',
|
||||||
search=self.search,
|
search=self.search, status=self.status,
|
||||||
storage=self.storage)
|
warning=self.warning, storage=self.storage)
|
||||||
|
|
||||||
self.storage.pre_build()
|
self.storage.pre_build()
|
||||||
app.build()
|
app.build()
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
class BaseSearch(object):
|
class BaseSearch(object):
|
||||||
|
def __init__(self, path):
|
||||||
|
pass
|
||||||
|
|
||||||
def init_indexing(self, changed=[]):
|
def init_indexing(self, changed=[]):
|
||||||
"""Called by the builder to initialize the search indexer. `changed`
|
"""Called by the builder to initialize the search indexer. `changed`
|
||||||
is a list of pagenames that will be reindexed. You may want to remove
|
is a list of pagenames that will be reindexed. You may want to remove
|
||||||
@ -117,4 +120,6 @@ class BaseSearch(object):
|
|||||||
search_adapters = {
|
search_adapters = {
|
||||||
'xapian': ('xapiansearch', 'XapianSearch'),
|
'xapian': ('xapiansearch', 'XapianSearch'),
|
||||||
'whoosh': ('whooshsearch', 'WhooshSearch'),
|
'whoosh': ('whooshsearch', 'WhooshSearch'),
|
||||||
|
'null': ('nullsearch', 'NullSearch')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
sphinx/websupport/search/nullsearch.py
Normal file
22
sphinx/websupport/search/nullsearch.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
sphinx.websupport.search.nullsearch
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The default search adapter, does nothing.
|
||||||
|
|
||||||
|
:copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
||||||
|
:license: BSD, see LICENSE for details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from sphinx.websupport.search import BaseSearch
|
||||||
|
|
||||||
|
class NullSearchException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class NullSearch(BaseSearch):
|
||||||
|
def feed(self, pagename, title, doctree):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def query(self, q):
|
||||||
|
raise NullSearchException('No search adapter specified.')
|
47
tests/test_websupport.py
Normal file
47
tests/test_websupport.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
test_websupport
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Test the Web Support Package
|
||||||
|
|
||||||
|
:copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
||||||
|
:license: BSD, see LICENSE for details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
from sphinx.websupport import WebSupport
|
||||||
|
|
||||||
|
try:
|
||||||
|
from functools import wraps
|
||||||
|
except ImportError:
|
||||||
|
# functools is new in 2.4
|
||||||
|
wraps = lambda f: (lambda w: w)
|
||||||
|
|
||||||
|
from util import *
|
||||||
|
|
||||||
|
def teardown_module():
|
||||||
|
(test_root / 'websupport').rmtree(True)
|
||||||
|
|
||||||
|
def with_support(*args, **kwargs):
|
||||||
|
"""Make a WebSupport object and pass it the test."""
|
||||||
|
settings = {'srcdir': test_root,
|
||||||
|
'outdir': os.path.join(test_root, 'websupport'),
|
||||||
|
'status': StringIO(),
|
||||||
|
'warning': StringIO()}
|
||||||
|
settings.update(kwargs)
|
||||||
|
|
||||||
|
def generator(func):
|
||||||
|
@wraps(func)
|
||||||
|
def new_func(*args2, **kwargs2):
|
||||||
|
support = WebSupport(**settings)
|
||||||
|
func(support, *args2, **kwargs2)
|
||||||
|
return new_func
|
||||||
|
return generator
|
||||||
|
|
||||||
|
@with_support()
|
||||||
|
def test_build(support):
|
||||||
|
support.build()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user