Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77ab11b

Browse files
Refs #2333 - Added 'test' target to django-admin script. Includes addition of --verbosity and --noinput options to django-admin, and a new TEST_RUNNER setting to control the tool used to execute tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 89fa97b commit 77ab11b

File tree

5 files changed

+61
-13
lines changed

5 files changed

+61
-13
lines changed

‎django/conf/global_settings.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,9 @@
296296
##################
297297

298298
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
299+
300+
###########
301+
# TESTING #
302+
###########
303+
304+
TEST_RUNNER='django.test.simple.run_tests'

‎django/contrib/auth/management.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _get_all_permissions(opts):
1616
perms.append((_get_permission_codename(action, opts), 'Can %s %s' % (action, opts.verbose_name)))
1717
return perms + list(opts.permissions)
1818

19-
def create_permissions(app, created_models):
19+
def create_permissions(app, created_models, verbosity):
2020
from django.contrib.contenttypes.models import ContentType
2121
from django.contrib.auth.models import Permission
2222
app_models = get_models(app)
@@ -27,13 +27,13 @@ def create_permissions(app, created_models):
2727
for codename, name in _get_all_permissions(klass._meta):
2828
p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
2929
defaults={'name': name, 'content_type': ctype})
30-
if created:
30+
if createdandverbosity>=2:
3131
print "Adding permission '%s'" % p
3232

33-
def create_superuser(app, created_models):
33+
def create_superuser(app, created_models, verbosity, **kwargs):
3434
from django.contrib.auth.models import User
3535
from django.contrib.auth.create_superuser import createsuperuser as do_create
36-
if User in created_models:
36+
if User in created_modelsandkwargs.get('interactive', True):
3737
msg = "\nYou just installed Django's auth system, which means you don't have " \
3838
"any superusers defined.\nWould you like to create one now? (yes/no): "
3939
confirm = raw_input(msg)

‎django/contrib/contenttypes/management.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.dispatch import dispatcher
66
from django.db.models import get_models, signals
77

8-
def create_contenttypes(app, created_models):
8+
def create_contenttypes(app, created_models, verbosity):
99
from django.contrib.contenttypes.models import ContentType
1010
app_models = get_models(app)
1111
if not app_models:
@@ -19,6 +19,7 @@ def create_contenttypes(app, created_models):
1919
ct = ContentType(name=str(opts.verbose_name),
2020
app_label=opts.app_label, model=opts.object_name.lower())
2121
ct.save()
22-
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
22+
if verbosity >= 2:
23+
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
2324

2425
dispatcher.connect(create_contenttypes, signal=signals.post_syncdb)

‎django/contrib/sites/management.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from django.contrib.sites.models import Site
88
from django.contrib.sites import models as site_app
99

10-
def create_default_site(app, created_models):
10+
def create_default_site(app, created_models, verbosity):
1111
if Site in created_models:
12-
print "Creating example.com Site object"
12+
if verbosity >= 2:
13+
print "Creating example.com Site object"
1314
s = Site(domain="example.com", name="example.com")
1415
s.save()
1516

‎django/core/management.py‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def get_sql_all(app):
423423
get_sql_all.help_doc = "Prints the CREATE TABLE, initial-data and CREATE INDEX SQL statements for the given model module name(s)."
424424
get_sql_all.args = APP_ARGS
425425

426-
def syncdb():
426+
def syncdb(verbosity=2, interactive=True):
427427
"Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
428428
from django.db import connection, transaction, models, get_creation_module
429429
from django.db.models import signals
@@ -471,7 +471,8 @@ def syncdb():
471471
except KeyError:
472472
pending_references[refto] = refs
473473
sql.extend(_get_sql_for_pending_references(model, pending_references))
474-
print "Creating table %s" % model._meta.db_table
474+
if verbosity >= 2:
475+
print "Creating table %s" % model._meta.db_table
475476
for statement in sql:
476477
cursor.execute(statement)
477478
table_list.append(model._meta.db_table)
@@ -480,7 +481,8 @@ def syncdb():
480481
if model in created_models:
481482
sql = _get_many_to_many_sql_for_model(model)
482483
if sql:
483-
print "Creating many-to-many tables for %s model" % model.__name__
484+
if verbosity >= 2:
485+
print "Creating many-to-many tables for %s model" % model.__name__
484486
for statement in sql:
485487
cursor.execute(statement)
486488

@@ -490,7 +492,8 @@ def syncdb():
490492
# to do at this point.
491493
for app in models.get_apps():
492494
dispatcher.send(signal=signals.post_syncdb, sender=app,
493-
app=app, created_models=created_models)
495+
app=app, created_models=created_models,
496+
verbosity=verbosity, interactive=interactive)
494497

495498
# Install initial data for the app (but only if this is a model we've
496499
# just created)
@@ -1154,6 +1157,29 @@ def runfcgi(args):
11541157
runfastcgi(args)
11551158
runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]'
11561159

1160+
def test(verbosity, app_labels):
1161+
"Runs the test suite for the specified applications"
1162+
from django.conf import settings
1163+
from django.db.models import get_app, get_apps
1164+
1165+
if len(app_labels) == 0:
1166+
app_list = get_apps()
1167+
else:
1168+
app_list = [get_app(app_label) for app_label in app_labels]
1169+
1170+
test_path = settings.TEST_RUNNER.split('.')
1171+
# Allow for Python 2.5 relative paths
1172+
if len(test_path) > 1:
1173+
test_module_name = '.'.join(test_path[:-1])
1174+
else:
1175+
test_module_name = '.'
1176+
test_module = __import__(test_module_name, [],[],test_path[-1])
1177+
test_runner = getattr(test_module, test_path[-1])
1178+
1179+
test_runner(app_list, verbosity)
1180+
test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified'
1181+
test.args = '[--verbosity] ' + APP_ARGS
1182+
11571183
# Utilities for command-line script
11581184

11591185
DEFAULT_ACTION_MAPPING = {
@@ -1178,6 +1204,7 @@ def runfcgi(args):
11781204
'startproject': startproject,
11791205
'syncdb': syncdb,
11801206
'validate': validate,
1207+
'test':test,
11811208
}
11821209

11831210
NO_SQL_TRANSACTION = (
@@ -1228,8 +1255,14 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
12281255
help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".')
12291256
parser.add_option('--plain', action='store_true', dest='plain',
12301257
help='Tells Django to use plain Python, not IPython, for "shell" command.')
1258+
parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
1259+
help='Tells Django to NOT prompt the user for input of any kind.')
12311260
parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True,
12321261
help='Tells Django to NOT use the auto-reloader when running the development server.')
1262+
parser.add_option('--verbosity', action='store', dest='verbosity', default='2',
1263+
type='choice', choices=['0', '1', '2'],
1264+
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
1265+
12331266
options, args = parser.parse_args(argv[1:])
12341267

12351268
# Take care of options.
@@ -1256,8 +1289,10 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
12561289

12571290
if action == 'shell':
12581291
action_mapping[action](options.plain is True)
1259-
elif action in ('syncdb', 'validate', 'diffsettings', 'dbshell'):
1292+
elif action in ('validate', 'diffsettings', 'dbshell'):
12601293
action_mapping[action]()
1294+
elif action == 'syncdb':
1295+
action_mapping[action](int(options.verbosity), options.interactive)
12611296
elif action == 'inspectdb':
12621297
try:
12631298
for line in action_mapping[action]():
@@ -1270,6 +1305,11 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
12701305
action_mapping[action](args[1])
12711306
except IndexError:
12721307
parser.print_usage_and_exit()
1308+
elif action == 'test':
1309+
try:
1310+
action_mapping[action](int(options.verbosity), args[1:])
1311+
except IndexError:
1312+
parser.print_usage_and_exit()
12731313
elif action in ('startapp', 'startproject'):
12741314
try:
12751315
name = args[1]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /