Commits

shaib committed c8fc826

Fix tests to work with Django<1.3 (and Python<2.7)
by making sure skipUnless is available

Comments (0)

Files changed (3)

south/tests/__init__.py

 import unittest
 import os
 import sys
+from functools import wraps
 from django.conf import settings
 from south.hacks import hacks
 
         if getattr(self, 'installed_apps', None):
             hacks.reset_installed_apps()
 
+# Make sure skipUnless is available.
+try:
+    # skipUnless added in Python 2.7;
+    from unittest import skipUnless
+except ImportError:
+    try: 
+        # django.utils.unittest added in Django 1.3;
+        from django.utils.unittest import skipUnless
+    except ImportError:
+        def skipUnless(condition, message):
+            def decorator(testfunc):
+                @wraps(testfunc)
+                def wrapper(self):
+                    if condition:
+                        # Apply method
+                        testfunc(self)
+                    else:
+                        # The skip exceptions are not available either...
+                        print "Skipping", testfunc.__name__,"--", message
+                return wrapper
+            return decorator
+
 
 # Try importing all tests if asked for (then we can run 'em)
 try:

south/tests/db.py

 
 from south.db import db, generic
 from django.db import connection, models
-from django.utils.unittest.case import skipUnless
+
+from south.tests import skipUnless        
 
 # Create a list of error classes from the various database libraries
 errors = []

south/tests/inspector.py

 
 on_delete_is_available = hasattr(models, "PROTECT") # models here is django.db.models
 
-try:
-    # skipUnless added in Python 2.7;
-    from unittest import skipUnless
-    skipUnlessOnDeleteAvailable = skipUnless(on_delete_is_available, "not testing on_delete -- not available on Django<1.3")
-except ImportError:
-    try: 
-        # django.utils.unittest added in Django 1.3;
-        from django.utils.unittest import skipUnless
-        skipUnlessOnDeleteAvailable = skipUnless(on_delete_is_available, "not testing on_delete -- not available on Django<1.3")
-    except ImportError:
-        def skipUnlessOnDeleteAvailable(testfunc):
-            @wraps(testfunc)
-            def wrapper(self):
-                if on_delete_is_available:
-                    # Apply method
-                    getattr(self, testfunc.__name__)()
-                else:
-                    # The skip exceptions are not available either...
-                    print "Skipping", testfunc.__name__,"--", "not testing on_delete -- not available on Django<1.3"
-            return wrapper
-                    
-                
+from south.tests import skipUnless        
+skipUnlessOnDeleteAvailable = skipUnless(on_delete_is_available, "not testing on_delete -- not available on Django<1.3")                    
+
 
 class TestModelInspector(Monkeypatcher):