1from __future__ import print_function 2 3#import unittest 4import os 5import sys 6from functools import wraps 7from django.conf import settings 8from south.hacks import hacks 9 10# Make sure skipping tests is available. 11try: 12 # easiest and best is unittest included in Django>=1.3 13 from django.utils import unittest 14except ImportError: 15 # earlier django... use unittest from stdlib 16 import unittest 17# however, skipUnless was only added in Python 2.7; 18# if not available, we need to do something else 19try: 20 skipUnless = unittest.skipUnless #@UnusedVariable 21except AttributeError: 22 def skipUnless(condition, message): 23 def decorator(testfunc): 24 @wraps(testfunc) 25 def wrapper(self): 26 if condition: 27 # Apply method 28 testfunc(self) 29 else: 30 # The skip exceptions are not available either... 31 print("Skipping", testfunc.__name__,"--", message) 32 return wrapper 33 return decorator 34 35# ditto for skipIf 36try: 37 skipIf = unittest.skipIf #@UnusedVariable 38except AttributeError: 39 def skipIf(condition, message): 40 def decorator(testfunc): 41 @wraps(testfunc) 42 def wrapper(self): 43 if condition: 44 print("Skipping", testfunc.__name__,"--", message) 45 else: 46 # Apply method 47 testfunc(self) 48 return wrapper 49 return decorator 50 51# Add the tests directory so fakeapp is on sys.path 52test_root = os.path.dirname(__file__) 53sys.path.append(test_root) 54 55# Note: the individual test files are imported below this. 56 57class Monkeypatcher(unittest.TestCase): 58 59 """ 60 Base test class for tests that play with the INSTALLED_APPS setting at runtime. 61 """ 62 63 def create_fake_app(self, name): 64 65 class Fake: 66 pass 67 68 fake = Fake() 69 fake.__name__ = name 70 try: 71 fake.migrations = __import__(name + ".migrations", {}, {}, ['migrations']) 72 except ImportError: 73 pass 74 return fake 75 76 def setUp(self): 77 """ 78 Changes the Django environment so we can run tests against our test apps. 79 """ 80 if hasattr(self, 'installed_apps'): 81 hacks.store_app_cache_state() 82 hacks.set_installed_apps(self.installed_apps) 83 # Make sure dependencies are calculated for new apps 84 Migrations._dependencies_done = False 85 86 def tearDown(self): 87 """ 88 Undoes what setUp did. 89 """ 90 if hasattr(self, 'installed_apps'): 91 hacks.reset_installed_apps() 92 hacks.restore_app_cache_state() 93 94 95# Try importing all tests if asked for (then we can run 'em) 96try: 97 skiptest = settings.SKIP_SOUTH_TESTS 98except: 99 skiptest = True 100 101if not skiptest: 102 from south.tests.db import * 103 from south.tests.db_mysql import * 104 from south.tests.db_firebird import * 105 from south.tests.logic import * 106 from south.tests.autodetection import * 107 from south.tests.logger import * 108 from south.tests.inspector import * 109 from south.tests.freezer import * 110