summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-08-21 23:03:06 +0200
committerGeorg Brandl <georg@python.org>2010-08-21 23:03:06 +0200
commit4ead60c306775e951aff469cc126309aaffc3520 (patch)
treebe4410f2ccf51a69e6056e57fc13ed53b703a381
parent73e9cebc68f2e60193b6f3f685eb1245bd7825a0 (diff)
downloadsphinx-4ead60c306775e951aff469cc126309aaffc3520.tar.gz
Improve websupport test skipping, add new decorator for search adapter skipping.
-rw-r--r--tests/test_searchadapters.py26
-rw-r--r--tests/test_websupport.py9
-rw-r--r--tests/util.py13
3 files changed, 30 insertions, 18 deletions
diff --git a/tests/test_searchadapters.py b/tests/test_searchadapters.py
index a30141df..cf5accb9 100644
--- a/tests/test_searchadapters.py
+++ b/tests/test_searchadapters.py
@@ -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')
diff --git a/tests/test_websupport.py b/tests/test_websupport.py
index 1ac96f8d..65957378 100644
--- a/tests/test_websupport.py
+++ b/tests/test_websupport.py
@@ -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')
diff --git a/tests/util.py b/tests/util.py
index cb1a980a..d56f3464 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -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):