diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2024-11-24 16:53:39 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-09 08:31:25 +0100 |
| commit | d345e5b5f88af64b1c3d95582cdaea4beb773120 (patch) | |
| tree | 455327f85c5a15e7cb5fbaccd9398a72901b827e /tests/migrations | |
| parent | c075d4c2c8cef3c9b28180c749d421c63544a9dd (diff) | |
Fixed #35935 -- Colorized system checks when running sqlmigrate.
Diffstat (limited to 'tests/migrations')
| -rw-r--r-- | tests/migrations/test_commands.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 6c3c67fd61..18f7e1e157 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -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", |
