Commits

Georg Brandl committed 4dd56e9

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

  • Participants
  • Parent commits ac337b2

Comments (0)

Files changed (3)

tests/test_searchadapters.py

 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')

tests/test_websupport.py

 
 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, \
     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')
 
 
 __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):