summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/south/tests/__init__.py
blob: 26779e35b206fe1a9dc301aa92a02fcdeee23604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from __future__ import print_function

#import unittest
import os
import sys
from functools import wraps
from django.conf import settings
from south.hacks import hacks

# Make sure skipping tests is available.
try:
    # easiest and best is unittest included in Django>=1.3
    from django.utils import unittest
except ImportError:
    # earlier django... use unittest from stdlib
    import unittest
# however, skipUnless was only added in Python 2.7;
# if not available, we need to do something else
try:
    skipUnless = unittest.skipUnless #@UnusedVariable
except AttributeError:
    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

# 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)

# Note: the individual test files are imported below this.

class Monkeypatcher(unittest.TestCase):

    """
    Base test class for tests that play with the INSTALLED_APPS setting at runtime.
    """

    def create_fake_app(self, name):
        
        class Fake:
            pass
        
        fake = Fake()
        fake.__name__ = name
        try:
            fake.migrations = __import__(name + ".migrations", {}, {}, ['migrations'])
        except ImportError:
            pass
        return fake

    def setUp(self):
        """
        Changes the Django environment so we can run tests against our test apps.
        """
        if hasattr(self, 'installed_apps'):
            hacks.store_app_cache_state()
            hacks.set_installed_apps(self.installed_apps)
            # Make sure dependencies are calculated for new apps
            Migrations._dependencies_done = False

    def tearDown(self):
        """
        Undoes what setUp did.
        """
        if hasattr(self, 'installed_apps'):
            hacks.reset_installed_apps()
            hacks.restore_app_cache_state()


# Try importing all tests if asked for (then we can run 'em)
try:
    skiptest = settings.SKIP_SOUTH_TESTS
except:
    skiptest = True

if not skiptest:
    from south.tests.db import *
    from south.tests.db_mysql import *
    from south.tests.db_firebird import *
    from south.tests.logic import *
    from south.tests.autodetection import *
    from south.tests.logger import *
    from south.tests.inspector import *
    from south.tests.freezer import *