Project

General

Profile

Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / south / tests / __init__.py @ d1a4905f

History | View | Annotate | Download (2.47 KB)

1

    
2
#import unittest
3
import os
4
import sys
5
from functools import wraps
6
from django.conf import settings
7
from south.hacks import hacks
8

    
9
# Make sure skipping tests is available.
10
try:
11
    # easiest and best is unittest included in Django>=1.3
12
    from django.utils import unittest
13
except ImportError:
14
    # earlier django... use unittest from stdlib
15
    import unittest
16
# however, skipUnless was only added in Python 2.7;
17
# if not available, we need to do something else
18
try:
19
    skipUnless = unittest.skipUnless #@UnusedVariable
20
except AttributeError:
21
    def skipUnless(condition, message):
22
        def decorator(testfunc):
23
            @wraps(testfunc)
24
            def wrapper(self):
25
                if condition:
26
                    # Apply method
27
                    testfunc(self)
28
                else:
29
                    # The skip exceptions are not available either...
30
                    print "Skipping", testfunc.__name__,"--", message
31
            return wrapper
32
        return decorator
33

    
34
# Add the tests directory so fakeapp is on sys.path
35
test_root = os.path.dirname(__file__)
36
sys.path.append(test_root)
37

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

    
40
class Monkeypatcher(unittest.TestCase):
41

    
42
    """
43
    Base test class for tests that play with the INSTALLED_APPS setting at runtime.
44
    """
45

    
46
    def create_fake_app(self, name):
47
        
48
        class Fake:
49
            pass
50
        
51
        fake = Fake()
52
        fake.__name__ = name
53
        try:
54
            fake.migrations = __import__(name + ".migrations", {}, {}, ['migrations'])
55
        except ImportError:
56
            pass
57
        return fake
58

    
59
    def setUp(self):
60
        """
61
        Changes the Django environment so we can run tests against our test apps.
62
        """
63
        if hasattr(self, 'installed_apps'):
64
            hacks.store_app_cache_state()
65
            hacks.set_installed_apps(self.installed_apps)
66

    
67
    def tearDown(self):
68
        """
69
        Undoes what setUp did.
70
        """
71
        if hasattr(self, 'installed_apps'):
72
            hacks.reset_installed_apps()
73
            hacks.restore_app_cache_state()
74

    
75

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

    
82
if not skiptest:
83
    from south.tests.db import *
84
    from south.tests.db_mysql import *
85
    from south.tests.logic import *
86
    from south.tests.autodetection import *
87
    from south.tests.logger import *
88
    from south.tests.inspector import *
89
    from south.tests.freezer import *