From e08318b4ef25cfe7d1cfbc5ae7d134ee477506ba Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Thu, 1 Jan 2015 15:42:40 +0100 Subject: [PATCH] Refs #23359 -- Removed double newline from output of migrate --list Thanks Berker Peksag for the review. --- django/core/management/commands/migrate.py | 5 ++- tests/migrations/test_commands.py | 49 ++++++++++++++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index df2d0ce026..8f414d38a0 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -68,14 +68,15 @@ class Command(BaseCommand): warnings.warn( "The 'migrate --list' command is deprecated. Use 'showmigrations' instead.", RemovedInDjango20Warning, stacklevel=2) + self.stdout.ending = None # Remove when #21429 is fixed return call_command( 'showmigrations', '--list', app_labels=[options['app_label']] if options['app_label'] else None, database=db, - no_color=options.get('no-color'), + no_color=options.get('no_color'), settings=options.get('settings'), - stdout=options.get('stdout', self.stdout), + stdout=self.stdout, traceback=self.show_traceback, verbosity=self.verbosity, ) diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index a9505dd82e..91b81d0370 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -9,7 +9,7 @@ from django.apps import apps from django.db import connection, models from django.core.management import call_command, CommandError from django.db.migrations import questioner -from django.test import ignore_warnings, override_settings +from django.test import ignore_warnings, mock, override_settings from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_text @@ -66,19 +66,27 @@ class MigrateTests(MigrationTestBase): Tests --list output of migrate command """ out = six.StringIO() - call_command("migrate", list=True, stdout=out, verbosity=0) - self.assertIn("migrations", out.getvalue().lower()) - self.assertIn("[ ] 0001_initial", out.getvalue().lower()) - self.assertIn("[ ] 0002_second", out.getvalue().lower()) + with mock.patch('django.core.management.color.supports_color', lambda *args: True): + call_command("migrate", list=True, stdout=out, verbosity=0, no_color=False) + self.assertEqual( + '\x1b[1mmigrations\n\x1b[0m' + ' [ ] 0001_initial\n' + ' [ ] 0002_second\n', + out.getvalue().lower() + ) call_command("migrate", "migrations", "0001", verbosity=0) out = six.StringIO() # Giving the explicit app_label tests for selective `show_migration_list` in the command - call_command("migrate", "migrations", list=True, stdout=out, verbosity=0) - self.assertIn("migrations", out.getvalue().lower()) - self.assertIn("[x] 0001_initial", out.getvalue().lower()) - self.assertIn("[ ] 0002_second", out.getvalue().lower()) + call_command("migrate", "migrations", list=True, stdout=out, verbosity=0, no_color=True) + self.assertEqual( + 'migrations\n' + ' [x] 0001_initial\n' + ' [ ] 0002_second\n', + out.getvalue().lower() + ) + # Cleanup by unmigrating everything call_command("migrate", "migrations", "zero", verbosity=0) @@ -88,19 +96,26 @@ class MigrateTests(MigrationTestBase): Tests --list output of showmigrations command """ out = six.StringIO() - call_command("showmigrations", format='list', stdout=out, verbosity=0) - self.assertIn("migrations", out.getvalue().lower()) - self.assertIn("[ ] 0001_initial", out.getvalue().lower()) - self.assertIn("[ ] 0002_second", out.getvalue().lower()) + with mock.patch('django.core.management.color.supports_color', lambda *args: True): + call_command("showmigrations", format='list', stdout=out, verbosity=0, no_color=False) + self.assertEqual( + '\x1b[1mmigrations\n\x1b[0m' + ' [ ] 0001_initial\n' + ' [ ] 0002_second\n', + out.getvalue().lower() + ) call_command("migrate", "migrations", "0001", verbosity=0) out = six.StringIO() # Giving the explicit app_label tests for selective `show_list` in the command - call_command("showmigrations", "migrations", format='list', stdout=out, verbosity=0) - self.assertIn("migrations", out.getvalue().lower()) - self.assertIn("[x] 0001_initial", out.getvalue().lower()) - self.assertIn("[ ] 0002_second", out.getvalue().lower()) + call_command("showmigrations", "migrations", format='list', stdout=out, verbosity=0, no_color=True) + self.assertEqual( + 'migrations\n' + ' [x] 0001_initial\n' + ' [ ] 0002_second\n', + out.getvalue().lower() + ) # Cleanup by unmigrating everything call_command("migrate", "migrations", "zero", verbosity=0)