Commits

Matt Chaput committed 179da53

Compatibility fixes for Python 2.5.

  • Participants
  • Parent commits 4ec6592

Comments (0)

Files changed (4)

File src/whoosh/qparser/plugins.py

         for part in parts:
             if "=" in part:
                 name, value = part.split("=", 1)
-                name = name.strip()
+                # Wrap with str() because Python 2.5 can't handle unicode kws
+                name = str(name.strip())
             else:
                 name = None
                 value = part

File src/whoosh/util/testing.py

     return decorating_function
 
 
-def skip_if_unavailable(modulename):
+def skip_if_unavailable(modulename, attr=None):
     """A Nose test decorator that only runs the decorated test if a module
     can be imported::
     
 
     def cantimport():
         try:
-            __import__(modulename)
+            if attr:
+                mod = __import__(modulename, fromlist=[attr])
+                return not hasattr(mod, attr)
+            else:
+                __import__(modulename)
         except ImportError:
             return True
         else:

File tests/test_analysis.py

                           ("lm", 14, 16)])
 
 
+@skip_if_unavailable("__future__", "unicode_literals")
 def test_language_analyzer():
     domain = [("da", u("Jeg gik mig over s\xf8 og land"),
                [u('gik'), u('s\xf8'), u('land')]),

File tests/test_columns.py

 
     rw(255)
 
-    # Column warns on additional unique values after 65535
-    with warnings.catch_warnings(record=True) as w:
-        # Cause all warnings to always be triggered.
-        warnings.simplefilter("always")
+    # warnings.catch_warnings is not available in Python 2.5
+    if hasattr(warnings, "catch_warnings"):
+        # Column warns on additional unique values after 65535
+        with warnings.catch_warnings(record=True) as w:
+            # Cause all warnings to always be triggered.
+            warnings.simplefilter("always")
+            rw(65537)
+
+            assert_equal(len(w), 2)
+            assert issubclass(w[-1].category, UserWarning)
+    else:
         rw(65537)
 
-        assert_equal(len(w), 2)
-        assert issubclass(w[-1].category, UserWarning)
 
 
 
 
 
 
-