mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #35935 -- Colorized system checks when running sqlmigrate.
This commit is contained in:
parent
c075d4c2c8
commit
d345e5b5f8
@ -32,10 +32,9 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def execute(self, *args, **options):
|
||||
# sqlmigrate doesn't support coloring its output but we need to force
|
||||
# no_color=True so that the BEGIN/COMMIT statements added by
|
||||
# output_transaction don't get colored either.
|
||||
options["no_color"] = True
|
||||
# sqlmigrate doesn't support coloring its output, so make the
|
||||
# BEGIN/COMMIT statements added by output_transaction colorless also.
|
||||
self.style.SQL_KEYWORD = lambda noop: noop
|
||||
return super().execute(*args, **options)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
@ -9,6 +9,7 @@ from unittest import mock
|
||||
|
||||
from django.apps import apps
|
||||
from django.core.management import CommandError, call_command
|
||||
from django.core.management.base import SystemCheckError
|
||||
from django.core.management.commands.makemigrations import (
|
||||
Command as MakeMigrationsCommand,
|
||||
)
|
||||
@ -859,7 +860,7 @@ class MigrateTests(MigrationTestBase):
|
||||
sqlmigrate outputs forward looking SQL.
|
||||
"""
|
||||
out = io.StringIO()
|
||||
call_command("sqlmigrate", "migrations", "0001", stdout=out)
|
||||
call_command("sqlmigrate", "migrations", "0001", stdout=out, no_color=True)
|
||||
|
||||
lines = out.getvalue().splitlines()
|
||||
|
||||
@ -921,7 +922,14 @@ class MigrateTests(MigrationTestBase):
|
||||
call_command("migrate", "migrations", verbosity=0)
|
||||
|
||||
out = io.StringIO()
|
||||
call_command("sqlmigrate", "migrations", "0001", stdout=out, backwards=True)
|
||||
call_command(
|
||||
"sqlmigrate",
|
||||
"migrations",
|
||||
"0001",
|
||||
stdout=out,
|
||||
backwards=True,
|
||||
no_color=True,
|
||||
)
|
||||
|
||||
lines = out.getvalue().splitlines()
|
||||
try:
|
||||
@ -1098,6 +1106,30 @@ class MigrateTests(MigrationTestBase):
|
||||
],
|
||||
)
|
||||
|
||||
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
|
||||
def test_sqlmigrate_transaction_keywords_not_colorized(self):
|
||||
out = io.StringIO()
|
||||
with mock.patch(
|
||||
"django.core.management.color.supports_color", lambda *args: True
|
||||
):
|
||||
call_command("sqlmigrate", "migrations", "0001", stdout=out, no_color=False)
|
||||
self.assertNotIn("\x1b", out.getvalue())
|
||||
|
||||
@override_settings(
|
||||
MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_operations"},
|
||||
INSTALLED_APPS=["django.contrib.auth"],
|
||||
)
|
||||
def test_sqlmigrate_system_checks_colorized(self):
|
||||
with (
|
||||
mock.patch(
|
||||
"django.core.management.color.supports_color", lambda *args: True
|
||||
),
|
||||
self.assertRaisesMessage(SystemCheckError, "\x1b"),
|
||||
):
|
||||
call_command(
|
||||
"sqlmigrate", "migrations", "0001", skip_checks=False, no_color=False
|
||||
)
|
||||
|
||||
@override_settings(
|
||||
INSTALLED_APPS=[
|
||||
"migrations.migrations_test_apps.migrated_app",
|
||||
|
Loading…
Reference in New Issue
Block a user