diff options
Diffstat (limited to 'tests/user_commands/tests.py')
| -rw-r--r-- | tests/user_commands/tests.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index acc338685e..321bde4ce9 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -1,5 +1,6 @@ import os import sys +import unittest from argparse import ArgumentDefaultsHelpFormatter from io import BytesIO, StringIO, TextIOWrapper from pathlib import Path @@ -24,6 +25,7 @@ from django.db import connection from django.test import SimpleTestCase, override_settings from django.test.utils import captured_stderr, extend_sys_path from django.utils import translation +from django.utils.version import PY314 from .management.commands import dance from .utils import AssertFormatterFailureCaughtContext @@ -454,6 +456,34 @@ class CommandTests(SimpleTestCase): self.assertIn("Working...", out.getvalue()) self.assertIs(mocked_flush.called, True) + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_color_enabled_by_default(self): + with mock.patch.dict(os.environ, {}, clear=True): + command = BaseCommand() + parser = command.create_parser("prog_name", "subcommand") + self.assertTrue(parser.color) + + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_color_disabled_with_django_colors_nocolor(self): + with mock.patch.dict(os.environ, {"DJANGO_COLORS": "nocolor"}): + command = BaseCommand() + parser = command.create_parser("prog_name", "subcommand") + self.assertFalse(parser.color) + + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_force_color_does_not_affect_argparse_color(self): + with mock.patch.dict(os.environ, {}, clear=True): + command = BaseCommand(force_color=True) + parser = command.create_parser("prog_name", "subcommand") + self.assertTrue(parser.color) + + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_no_color_flag_disables_color(self): + with mock.patch.object(sys, "argv", ["manage.py", "mycommand", "--no-color"]): + command = BaseCommand() + parser = command.create_parser("manage.py", "mycommand") + self.assertFalse(parser.color) + class CommandRunTests(AdminScriptTestCase): """ |
