Commits

Tay Ray Chuan committed 8b85d7b

tests.db_mysql: use skipUnless on suite

Do this with a metaclass that applies the skipUnless decorator on test
methods.

  • Participants
  • Parent commits 0398e80

Comments (0)

Files changed (1)

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'