mirror of
https://github.com/django/django.git
synced 2025-11-18 02:56:45 +00:00
Merge 7032a5124a into 1ce6e78dd4
This commit is contained in:
commit
eb18eb4447
5 changed files with 44 additions and 6 deletions
|
|
@ -15,6 +15,7 @@ from django.core import checks
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.management.color import color_style, no_style
|
||||
from django.db import DEFAULT_DB_ALIAS, connections
|
||||
from django.utils.version import PY314, PY315
|
||||
|
||||
ALL_CHECKS = "__all__"
|
||||
|
||||
|
|
@ -57,6 +58,8 @@ class CommandParser(ArgumentParser):
|
|||
):
|
||||
self.missing_args_message = missing_args_message
|
||||
self.called_from_command_line = called_from_command_line
|
||||
if PY314 and not PY315:
|
||||
kwargs.setdefault("suggest_on_error", True)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def parse_args(self, args=None, namespace=None):
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ PY311 = sys.version_info >= (3, 11)
|
|||
PY312 = sys.version_info >= (3, 12)
|
||||
PY313 = sys.version_info >= (3, 13)
|
||||
PY314 = sys.version_info >= (3, 14)
|
||||
PY315 = sys.version_info >= (3, 15)
|
||||
|
||||
|
||||
def get_version(version=None):
|
||||
|
|
|
|||
|
|
@ -228,7 +228,9 @@ Logging
|
|||
Management Commands
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* ...
|
||||
* Management commands now set :class:`~argparse.ArgumentParser`\'s
|
||||
``suggest_on_error`` argument to ``True`` by default on Python 3.14, enabling
|
||||
suggestions for mistyped subcommand names and argument choices.
|
||||
|
||||
Migrations
|
||||
~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ from django.db.migrations.recorder import MigrationRecorder
|
|||
from django.test import LiveServerTestCase, SimpleTestCase, TestCase, override_settings
|
||||
from django.test.utils import captured_stderr, captured_stdout
|
||||
from django.urls import path
|
||||
from django.utils.version import PY313, get_docs_version
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.version import PY313, PY314, get_docs_version
|
||||
from django.views.static import serve
|
||||
|
||||
from . import urls
|
||||
|
|
@ -2446,10 +2447,17 @@ class Discovery(SimpleTestCase):
|
|||
|
||||
class CommandDBOptionChoiceTests(SimpleTestCase):
|
||||
def test_invalid_choice_db_option(self):
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut' "
|
||||
r"\(choose from '?default'?, '?other'?\)"
|
||||
)
|
||||
# Update expected error based on Python version
|
||||
if PY314:
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut', "
|
||||
r"maybe you meant 'default'\? \(choose from default, other\)"
|
||||
)
|
||||
else:
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut' "
|
||||
r"\(choose from '?default'?, '?other'?\)"
|
||||
)
|
||||
args = [
|
||||
"changepassword",
|
||||
"createsuperuser",
|
||||
|
|
|
|||
|
|
@ -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,28 @@ class CommandTests(SimpleTestCase):
|
|||
self.assertIn("Working...", out.getvalue())
|
||||
self.assertIs(mocked_flush.called, True)
|
||||
|
||||
@unittest.skipUnless(PY314, "Requires Python 3.14")
|
||||
def test_suggest_on_error_defaults_true(self):
|
||||
"""
|
||||
CommandParser sets suggest_on_error=True on Python 3.14.
|
||||
"""
|
||||
command = BaseCommand()
|
||||
command._called_from_command_line = True
|
||||
parser = command.create_parser("prog_name", "subcommand")
|
||||
self.assertTrue(parser.suggest_on_error)
|
||||
|
||||
@unittest.skipUnless(PY314, "Requires Python 3.14")
|
||||
def test_suggest_on_error_custom(self):
|
||||
"""
|
||||
Explicit suggest_on_error=False is respected.
|
||||
"""
|
||||
command = BaseCommand()
|
||||
command._called_from_command_line = True
|
||||
parser = command.create_parser(
|
||||
"prog_name", "subcommand", suggest_on_error=False
|
||||
)
|
||||
self.assertFalse(parser.suggest_on_error)
|
||||
|
||||
|
||||
class CommandRunTests(AdminScriptTestCase):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue