Repository: django/django
File: tests/user_commands/tests.py (Python)

Code before:
    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("prog", "sub")
            self.assertIs(parser.color, False)


class CommandRunTests(AdminScriptTestCase):
    """
    Tests that need to run by simulating the command line, not by call_command.
    """

    def test_script_prefix_set_in_commands(self):
        self.write_settings(
            "settings.py",
            apps=["user_commands"],
            sdict={
                "ROOT_URLCONF": '"user_commands.urls"',
                "FORCE_SCRIPT_NAME": '"/PREFIX/"',
            },
        )
        out, err = self.run_manage(["reverse_url"])
        self.assertNoOutput(err)
        self.assertEqual(out.strip(), "/PREFIX/some/url/")

    def test_disallowed_abbreviated_options(self):
        """
        To avoid conflicts with custom options, commands don't allow
        abbreviated forms of the --setting and --pythonpath options.
        """

Review comment (suggestion):
I'd make all 4 assertions use either assertIs or not.

Code after:
    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):
    """
    Tests that need to run by simulating the command line, not by call_command.
    """

    def test_script_prefix_set_in_commands(self):
        self.write_settings(
            "settings.py",
            apps=["user_commands"],
            sdict={
                "ROOT_URLCONF": '"user_commands.urls"',
                "FORCE_SCRIPT_NAME": '"/PREFIX/"',
            },
        )
        out, err = self.run_manage(["reverse_url"])
        self.assertNoOutput(err)
        self.assertEqual(out.strip(), "/PREFIX/some/url/")

    def test_disallowed_abbreviated_options(self):
        """
        To avoid conflicts with custom options, commands don't allow
        abbreviated forms of the --setting and --pythonpath options.
        """