Improve websupport test skipping, add new decorator for search adapter skipping.

This commit is contained in:
Georg Brandl 2010-08-21 23:03:06 +02:00
parent 9acc57b616
commit 2f2a09c919
3 changed files with 30 additions and 18 deletions

View File

@ -12,9 +12,13 @@
import os, sys
from StringIO import StringIO
from util import *
from nose import SkipTest
from sphinx.websupport import WebSupport
from test_websupport import sqlalchemy_missing
from util import *
def clear_builddir():
(test_root / 'websupport').rmtree(True)
@ -63,21 +67,13 @@ def search_adapter_helper(adapter):
html = support.get_search_results(u'SomeLongRandomWord')
@skip_unless_importable('xapian', 'needs xapian bindings installed')
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
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')
search_adapter_helper('xapian')
@skip_unless_importable('whoosh', 'needs whoosh package installed')
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
def test_whoosh():
# Don't run tests if whoosh is not installed.
try:
import whoosh
search_adapter_helper('whoosh')
except ImportError:
sys.stderr.write('info: not running whoosh tests, ' \
'whoosh doesn\'t seem to be installed')
search_adapter_helper('whoosh')

View File

@ -22,6 +22,7 @@ from nose import SkipTest
from sphinx.websupport import WebSupport
from sphinx.websupport.errors import *
from sphinx.websupport.storage import StorageBackend
from sphinx.websupport.storage.differ import CombinedHtmlDiff
try:
from sphinx.websupport.storage.sqlalchemystorage import Session, \
@ -57,17 +58,23 @@ def with_support(*args, **kwargs):
return generator
@with_support()
class NullStorage(StorageBackend):
pass
@with_support(storage=NullStorage())
def test_no_srcdir(support):
"""Make sure the correct exception is raised if srcdir is not given."""
raises(SrcdirNotSpecifiedError, support.build)
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
@with_support(srcdir=test_root)
def test_build(support):
support.build()
@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
@with_support()
def test_get_document(support):
raises(DocumentNotFoundError, support.get_document, 'nonexisting')

View File

@ -29,8 +29,8 @@ from nose import tools, SkipTest
__all__ = [
'test_root',
'raises', 'raises_msg', 'skip_if', 'skip_unless', 'Struct',
'test_root', 'raises', 'raises_msg',
'skip_if', 'skip_unless', 'skip_unless_importable', 'Struct',
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
'path', 'with_tempdir', 'write_file',
'sprint', 'remove_unicode_literals',
@ -86,6 +86,15 @@ def skip_unless(condition, msg=None):
"""Decorator to skip test if condition is false."""
return skip_if(not condition, msg)
def skip_unless_importable(module, msg=None):
"""Decorator to skip test if module is not importable."""
try:
__import__(module)
except ImportError:
return skip_if(True, msg)
else:
return skip_if(False, msg)
class Struct(object):
def __init__(self, **kwds):