Changed name given to test applications in Django own test suite running tool from 'model' to 'module' or 'application'.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15257 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
190f6e5b45
commit
ccfd70c7ba
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os, subprocess, sys, traceback
|
import os, subprocess, sys
|
||||||
|
|
||||||
import django.contrib as contrib
|
import django.contrib as contrib
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
@ -36,31 +36,31 @@ def geodjango(settings):
|
||||||
if db_dict['ENGINE'].startswith('django.contrib.gis')]
|
if db_dict['ENGINE'].startswith('django.contrib.gis')]
|
||||||
return len(spatial_dbs) == len(settings.DATABASES)
|
return len(spatial_dbs) == len(settings.DATABASES)
|
||||||
|
|
||||||
def get_test_models():
|
def get_test_modules():
|
||||||
models = []
|
modules = []
|
||||||
for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
|
for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
|
||||||
for f in os.listdir(dirpath):
|
for f in os.listdir(dirpath):
|
||||||
if f.startswith('__init__') or f.startswith('.') or \
|
if f.startswith('__init__') or f.startswith('.') or \
|
||||||
f.startswith('sql') or f.startswith('invalid') or \
|
f.startswith('sql') or f.startswith('invalid') or \
|
||||||
os.path.basename(f) in REGRESSION_SUBDIRS_TO_SKIP:
|
os.path.basename(f) in REGRESSION_SUBDIRS_TO_SKIP:
|
||||||
continue
|
continue
|
||||||
models.append((loc, f))
|
modules.append((loc, f))
|
||||||
return models
|
return modules
|
||||||
|
|
||||||
def get_invalid_models():
|
def get_invalid_modules():
|
||||||
models = []
|
modules = []
|
||||||
for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
|
for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
|
||||||
for f in os.listdir(dirpath):
|
for f in os.listdir(dirpath):
|
||||||
if f.startswith('__init__') or f.startswith('.') or f.startswith('sql'):
|
if f.startswith('__init__') or f.startswith('.') or f.startswith('sql'):
|
||||||
continue
|
continue
|
||||||
if f.startswith('invalid'):
|
if f.startswith('invalid'):
|
||||||
models.append((loc, f))
|
modules.append((loc, f))
|
||||||
return models
|
return modules
|
||||||
|
|
||||||
class InvalidModelTestCase(unittest.TestCase):
|
class InvalidModelTestCase(unittest.TestCase):
|
||||||
def __init__(self, model_label):
|
def __init__(self, module_label):
|
||||||
unittest.TestCase.__init__(self)
|
unittest.TestCase.__init__(self)
|
||||||
self.model_label = model_label
|
self.module_label = module_label
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
from django.core.management.validation import get_validation_errors
|
from django.core.management.validation import get_validation_errors
|
||||||
|
@ -68,7 +68,7 @@ class InvalidModelTestCase(unittest.TestCase):
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
try:
|
try:
|
||||||
module = load_app(self.model_label)
|
module = load_app(self.module_label)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.fail('Unable to load invalid model module')
|
self.fail('Unable to load invalid model module')
|
||||||
|
|
||||||
|
@ -130,26 +130,26 @@ def setup(verbosity, test_labels):
|
||||||
|
|
||||||
# Load all the test model apps.
|
# Load all the test model apps.
|
||||||
test_labels_set = set([label.split('.')[0] for label in test_labels])
|
test_labels_set = set([label.split('.')[0] for label in test_labels])
|
||||||
test_models = get_test_models()
|
test_modules = get_test_modules()
|
||||||
|
|
||||||
# If GeoDjango, then we'll want to add in the test applications
|
# If GeoDjango, then we'll want to add in the test applications
|
||||||
# that are a part of its test suite.
|
# that are a part of its test suite.
|
||||||
if geodjango(settings):
|
if geodjango(settings):
|
||||||
from django.contrib.gis.tests import geo_apps
|
from django.contrib.gis.tests import geo_apps
|
||||||
test_models.extend(geo_apps(runtests=True))
|
test_modules.extend(geo_apps(runtests=True))
|
||||||
|
|
||||||
for model_dir, model_name in test_models:
|
for module_dir, module_name in test_modules:
|
||||||
model_label = '.'.join([model_dir, model_name])
|
module_label = '.'.join([module_dir, module_name])
|
||||||
# if the model was named on the command line, or
|
# if the module was named on the command line, or
|
||||||
# no models were named (i.e., run all), import
|
# no modules were named (i.e., run all), import
|
||||||
# this model and add it to the list to test.
|
# this module and add it to the list to test.
|
||||||
if not test_labels or model_name in test_labels_set:
|
if not test_labels or module_name in test_labels_set:
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
print "Importing model %s" % model_name
|
print "Importing application %s" % module_name
|
||||||
mod = load_app(model_label)
|
mod = load_app(module_label)
|
||||||
if mod:
|
if mod:
|
||||||
if model_label not in settings.INSTALLED_APPS:
|
if module_label not in settings.INSTALLED_APPS:
|
||||||
settings.INSTALLED_APPS.append(model_label)
|
settings.INSTALLED_APPS.append(module_label)
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
@ -163,16 +163,16 @@ def django_tests(verbosity, interactive, failfast, test_labels):
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
state = setup(verbosity, test_labels)
|
state = setup(verbosity, test_labels)
|
||||||
|
|
||||||
# Add tests for invalid models.
|
# Add tests for invalid models apps.
|
||||||
extra_tests = []
|
extra_tests = []
|
||||||
for model_dir, model_name in get_invalid_models():
|
for module_dir, module_name in get_invalid_modules():
|
||||||
model_label = '.'.join([model_dir, model_name])
|
module_label = '.'.join([module_dir, module_name])
|
||||||
if not test_labels or model_name in test_labels:
|
if not test_labels or module_name in test_labels:
|
||||||
extra_tests.append(InvalidModelTestCase(model_label))
|
extra_tests.append(InvalidModelTestCase(module_label))
|
||||||
try:
|
try:
|
||||||
# Invalid models are not working apps, so we cannot pass them into
|
# Invalid models are not working apps, so we cannot pass them into
|
||||||
# the test runner with the other test_labels
|
# the test runner with the other test_labels
|
||||||
test_labels.remove(model_name)
|
test_labels.remove(module_name)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ def paired_tests(paired_test, options, test_labels):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
usage = "%prog [options] [model model model ...]"
|
usage = "%prog [options] [module module module ...]"
|
||||||
parser = OptionParser(usage=usage)
|
parser = OptionParser(usage=usage)
|
||||||
parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1',
|
parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1',
|
||||||
type='choice', choices=['0', '1', '2', '3'],
|
type='choice', choices=['0', '1', '2', '3'],
|
||||||
|
|
Loading…
Reference in New Issue