Mercurial > nosedjango
comparison nosedjango/nosedjango.py @ 5:22ae9aa457af
excercise more bits of the django 1.0b1 test framework
author | Victor Ng <victor@monkeybean.ca> |
---|---|
date | Thu, 28 Aug 2008 11:29:21 -0400 |
parents | b761c26773a3 |
children | dfba3a3a4343 |
comparison
equal
deleted
inserted
replaced
4:20bca08c0828 | 5:22ae9aa457af |
---|---|
2 nose plugin for easy testing of django projects and apps. Sets up a test | 2 nose plugin for easy testing of django projects and apps. Sets up a test |
3 database (or schema) and installs apps from test settings file before tests | 3 database (or schema) and installs apps from test settings file before tests |
4 are run, and tears the test database (or schema) down after all tests are run. | 4 are run, and tears the test database (or schema) down after all tests are run. |
5 """ | 5 """ |
6 | 6 |
7 import logging | |
8 import os, sys | 7 import os, sys |
9 import re | 8 import re |
10 | 9 |
11 from nose.plugins import Plugin | 10 from nose.plugins import Plugin |
12 import nose.case | 11 import nose.case |
14 # Force settings.py pointer | 13 # Force settings.py pointer |
15 # search the current working directory and all parent directories to find | 14 # search the current working directory and all parent directories to find |
16 # the settings file | 15 # the settings file |
17 from nose.importer import add_path | 16 from nose.importer import add_path |
18 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' | 17 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
18 import re | |
19 NT_ROOT = re.compile(r"^[a-zA-Z]:\\$") | |
19 def get_SETTINGS_PATH(): | 20 def get_SETTINGS_PATH(): |
21 ''' | |
22 Hunt down the settings.py module by going up the FS path | |
23 ''' | |
20 cwd = os.getcwd() | 24 cwd = os.getcwd() |
21 while cwd: | 25 while cwd: |
22 if 'settings.py' in os.listdir(cwd): | 26 if 'settings.py' in os.listdir(cwd): |
23 break | 27 break |
24 cwd = os.path.split(cwd)[0] | 28 cwd = os.path.split(cwd)[0] |
25 if cwd == '/': | 29 if os.name == 'nt' and NT_ROOT.match(cwd): |
30 return None | |
31 elif cwd == '/': | |
26 return None | 32 return None |
27 return cwd | 33 return cwd |
34 | |
28 SETTINGS_PATH = get_SETTINGS_PATH() | 35 SETTINGS_PATH = get_SETTINGS_PATH() |
29 | 36 |
30 log = logging.getLogger('nose.plugins.nosedjango') | |
31 | 37 |
32 class NoseDjango(Plugin): | 38 class NoseDjango(Plugin): |
33 """ | 39 """ |
34 Enable to set up django test environment before running all tests, and | 40 Enable to set up django test environment before running all tests, and |
35 tear it down after all tests. If the django database engine in use is not | 41 tear it down after all tests. If the django database engine in use is not |