Commits

Andrew Godwin committed 496e5fe Merge

Merged in rctay/south (pull request #77)

Comments (0)

Files changed (3)

south/tests/__init__.py

             return wrapper
         return decorator
 
+# ditto for skipIf
+try:
+    skipIf = unittest.skipIf #@UnusedVariable
+except AttributeError:
+    def skipIf(condition, message):
+        def decorator(testfunc):
+            @wraps(testfunc)
+            def wrapper(self):
+                if condition:
+                    print "Skipping", testfunc.__name__,"--", message
+                else:
+                    # Apply method
+                    testfunc(self)
+            return wrapper
+        return decorator
+
 # Add the tests directory so fakeapp is on sys.path
 test_root = os.path.dirname(__file__)
 sys.path.append(test_root)

south/tests/db.py

 from south.db import db, generic
 from django.db import connection, models, IntegrityError
 
-from south.tests import unittest, skipUnless        
+from south.tests import unittest, skipIf, skipUnless
 
 # Create a list of error classes from the various database libraries
 errors = []
 
         db.delete_table("test_multiword")
     
+    @skipUnless(db.has_check_constraints, 'Only applies to databases that '
+                                          'support CHECK constraints.')
     def test_alter_constraints(self):
         """
         Tests that going from a PostiveIntegerField to an IntegerField drops
         the constraint on the database.
         """
-        # Only applies to databases that support CHECK constraints
-        if not db.has_check_constraints:
-            return
         # Make the test table
         db.create_table("test_alterc", [
             ('num', models.PositiveIntegerField()),
         # We need to match up for tearDown
         db.start_transaction()
     
+    @skipIf(db.backend_name == "sqlite3", "SQLite backend doesn't support this "
+                                          "yet.")
     def test_unique(self):
         """
         Tests creating/deleting unique constraints.
         """
-        
-        # SQLite backend doesn't support this yet.
-        if db.backend_name == "sqlite3":
-            return
-        
         db.create_table("test_unique2", [
             ('id', models.AutoField(primary_key=True)),
         ])
         
         db.delete_table("test_add_unique_fk")
         
+    @skipUnless(db.has_check_constraints, 'Only applies to databases that '
+                                          'support CHECK constraints.')
     def test_column_constraint(self):
         """
         Tests that the value constraint of PositiveIntegerField is enforced on
         the database level.
         """
-        if not db.has_check_constraints:
-            return
-        
         db.create_table("test_column_constraint", [
             ('spam', models.PositiveIntegerField()),
         ])
         ops.mv_column('table', 'column', 'column_new')
         self.assertEqual('constraint', ops.lookup_constraint('db', 'table', 'column_new'))
         self.assertEqual([], ops.lookup_constraint('db', 'table', 'column'))
-        return
 
     def test_valid(self):
         ops = self.CacheOps()

south/tests/db_mysql.py

 # Additional MySQL-specific tests
 # Written by: F. Gabriel Gosselin <gabrielNOSPAM@evidens.ca>
 # Based on tests by: aarranz
-from south.tests import unittest
+from south.tests import unittest, skipUnless
 
 
 from south.db import db, generic, mysql
 
 class TestMySQLOperations(unittest.TestCase):
     """MySQL-specific tests"""
+
+    # A class decoration may be used in lieu of this when Python 2.5 is the
+    # minimum.
+    def __metaclass__(name, bases, dict_):
+        decorator = skipUnless(db.backend_name == "mysql", 'MySQL-specific tests')
+
+        for key, method in dict_.iteritems():
+            if key.startswith('test'):
+                dict_[key] = decorator(method)
+
+        return type(name, bases, dict_)
+
     def setUp(self):
         db.debug = False
         db.clear_deferred_sql()
 
     def test_constraint_references(self):
         """Tests that referred table is reported accurately"""
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_cns_ref'
         reference_table = 'test_cr_foreign'
         db.start_transaction()
 
     def test_reverse_column_constraint(self):
         """Tests that referred column in a foreign key (ex. id) is found"""
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_reverse_ref'
         reference_table = 'test_rr_foreign'
         db.start_transaction()
         db.delete_table(reference_table)
 
     def test_delete_fk_column(self):
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_drop_foreign'
         ref_table = 'test_df_ref'
         self._create_foreign_tables(main_table, ref_table)
         db.delete_table(ref_table)
 
     def test_rename_fk_column(self):
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_rename_foreign'
         ref_table = 'test_rf_ref'
         self._create_foreign_tables(main_table, ref_table)
         Tests that the column referred to by an external column can be renamed.
         Edge case, but also useful as stepping stone to renaming tables.
         """
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_rename_fk_inbound'
         ref_table = 'test_rfi_ref'
         self._create_foreign_tables(main_table, ref_table)
 
     def test_rename_constrained_table(self):
         """Renames a table with a foreign key column (towards another table)"""
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_rn_table'
         ref_table = 'test_rt_ref'
         renamed_table = 'test_renamed_table'
 
     def test_renamed_referenced_table(self):
         """Rename a table referred to in a foreign key"""
-        if db.backend_name != "mysql":
-            return
         main_table = 'test_rn_refd_table'
         ref_table = 'test_rrt_ref'
         renamed_table = 'test_renamed_ref'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.