1. Daniel Neuhäuser
  2. sphinx-multiprocessing


Georg Brandl  committed 4dd56e9

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

  • Participants
  • Parent commits ac337b2
  • Branches default

Comments (0)

Files changed (3)

File tests/test_searchadapters.py

View file
 import os, sys
 from StringIO import StringIO
+from nose import SkipTest
+from sphinx.websupport import WebSupport
+from test_websupport import sqlalchemy_missing
 from util import *
-from sphinx.websupport import WebSupport
 def clear_builddir():
     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')

File tests/test_websupport.py

View file
 from sphinx.websupport import WebSupport
 from sphinx.websupport.errors import *
+from sphinx.websupport.storage import StorageBackend
 from sphinx.websupport.storage.differ import CombinedHtmlDiff
     from sphinx.websupport.storage.sqlalchemystorage import Session, \
     return generator
+class NullStorage(StorageBackend):
+    pass
 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')
 def test_build(support):
+@skip_if(sqlalchemy_missing, 'needs sqlalchemy')
 def test_get_document(support):
     raises(DocumentNotFoundError, support.get_document, 'nonexisting')

File tests/util.py

View file
 __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',
     """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):