1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #13636 -- Migrated fixtures tests to use unittests, eliminating another set of expensive flush calls. Thanks to Eric Holscher for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13319 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2010-06-05 05:26:04 +00:00
parent 3e1e04d6d0
commit 5da6aeba17
5 changed files with 314 additions and 255 deletions

View File

@@ -213,6 +213,8 @@ class BaseCommand(object):
sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
sys.exit(1)
try:
self.stdout = options.get('stdout', sys.stdout)
self.stderr = options.get('stderr', sys.stderr)
if self.requires_model_validation:
self.validate()
output = self.handle(*args, **options)
@@ -223,12 +225,12 @@ class BaseCommand(object):
from django.db import connections, DEFAULT_DB_ALIAS
connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
if connection.ops.start_transaction_sql():
print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
print output
self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()))
self.stdout.write(output)
if self.output_transaction:
print self.style.SQL_KEYWORD(connection.ops.end_transaction_sql())
self.stdout.write(self.style.SQL_KEYWORD("COMMIT;") + '\n')
except CommandError, e:
sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
sys.exit(1)
def validate(self, app=None, display_num_errors=False):
@@ -250,7 +252,7 @@ class BaseCommand(object):
error_text = s.read()
raise CommandError("One or more models did not validate:\n%s" % error_text)
if display_num_errors:
print "%s error%s found" % (num_errors, num_errors != 1 and 's' or '')
self.stdout.write("%s error%s found\n" % (num_errors, num_errors != 1 and 's' or ''))
def handle(self, *args, **options):
"""