Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/check_commit_messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
echo "prefix=[$VERSION]" >> $GITHUB_OUTPUT

- name: Check PR title prefix
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
TITLE="${{ github.event.pull_request.title }}"
PREFIX="${{ steps.vars.outputs.prefix }}"
if [[ "$TITLE" != "$PREFIX"* ]]; then
echo "❌ PR title must start with the required prefix: $PREFIX"
Expand Down
3 changes: 3 additions & 0 deletions django/utils/numberformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def format(
if abs(number) < cutoff:
number = Decimal("0")

if not number.is_finite():
return str(number)

# Format values with more than 200 digits (an arbitrary cutoff) using
# scientific notation to avoid high memory usage in {:f}'.format().
_, digits, exponent = number.as_tuple()
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/databases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ Subclassing the built-in database backends
==========================================

Django comes with built-in database backends. You may subclass an existing
database backends to modify its behavior, features, or configuration.
database backend to modify its behavior, features, or configuration.

Consider, for example, that you need to change a single database feature.
First, you have to create a new directory with a ``base`` module in it. For
Expand Down
73 changes: 28 additions & 45 deletions tests/admin_scripts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
from django.core.management.commands.loaddata import Command as LoaddataCommand
from django.core.management.commands.runserver import Command as RunserverCommand
from django.core.management.commands.testserver import Command as TestserverCommand
from django.core.management.utils import find_formatters
from django.db import ConnectionHandler, connection
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.functional import cached_property
from django.utils.version import PY313, get_docs_version
from django.views.static import serve

Expand All @@ -49,6 +47,8 @@

SYSTEM_CHECK_MSG = "System check identified no issues"

HAS_BLACK = shutil.which("black")


class AdminScriptTestCase(SimpleTestCase):
def setUp(self):
Expand Down Expand Up @@ -112,21 +112,7 @@ def _ext_backend_paths(self):
paths.append(os.path.dirname(backend_dir))
return paths

@cached_property
def path_without_formatters(self):
return os.pathsep.join(
[
path_component
for path_component in os.environ.get("PATH", "").split(os.pathsep)
for formatter_path in find_formatters().values()
if formatter_path
and os.path.commonpath([path_component, formatter_path]) == os.sep
]
)

def run_test(
self, args, settings_file=None, apps=None, umask=-1, discover_formatters=False
):
def run_test(self, args, settings_file=None, apps=None, umask=-1):
base_dir = os.path.dirname(self.test_dir)
# The base dir for Django's tests is one level up.
tests_dir = os.path.dirname(os.path.dirname(__file__))
Expand All @@ -148,8 +134,6 @@ def run_test(
python_path.extend(ext_backend_base_dirs)
test_environ["PYTHONPATH"] = os.pathsep.join(python_path)
test_environ["PYTHONWARNINGS"] = ""
if not discover_formatters:
test_environ["PATH"] = self.path_without_formatters

p = subprocess.run(
[sys.executable, *args],
Expand All @@ -161,19 +145,10 @@ def run_test(
)
return p.stdout, p.stderr

def run_django_admin(
self, args, settings_file=None, umask=-1, discover_formatters=False
):
return self.run_test(
["-m", "django", *args],
settings_file,
umask=umask,
discover_formatters=discover_formatters,
)
def run_django_admin(self, args, settings_file=None, umask=-1):
return self.run_test(["-m", "django", *args], settings_file, umask=umask)

def run_manage(
self, args, settings_file=None, manage_py=None, discover_formatters=False
):
def run_manage(self, args, settings_file=None, manage_py=None):
template_manage_py = (
os.path.join(os.path.dirname(__file__), manage_py)
if manage_py
Expand All @@ -192,11 +167,17 @@ def run_manage(
with open(test_manage_py, "w") as fp:
fp.write(manage_py_contents)

return self.run_test(
["./manage.py", *args],
settings_file,
discover_formatters=discover_formatters,
)
return self.run_test(["./manage.py", *args], settings_file)

def assertInAfterFormatting(self, member, container, msg=None):
if HAS_BLACK:
import black

# Black does not have a stable API, but this is still less fragile
# than attempting to filter out all paths where it is available.
member = black.format_str(member, mode=black.FileMode())

self.assertIn(member, container, msg=msg)

def assertNoOutput(self, stream):
"Utility assertion: assert that the given stream is empty"
Expand Down Expand Up @@ -773,7 +754,7 @@ def test_setup_environ(self):
with open(os.path.join(app_path, "apps.py")) as f:
content = f.read()
self.assertIn("class SettingsTestConfig(AppConfig)", content)
self.assertIn("name = 'settings_test'", content)
self.assertInAfterFormatting("name = 'settings_test'", content)

def test_setup_environ_custom_template(self):
"""
Expand All @@ -798,7 +779,7 @@ def test_startapp_unicode_name(self):
with open(os.path.join(app_path, "apps.py"), encoding="utf8") as f:
content = f.read()
self.assertIn("class こんにちはConfig(AppConfig)", content)
self.assertIn("name = 'こんにちは'", content)
self.assertInAfterFormatting("name = 'こんにちは'", content)

def test_builtin_command(self):
"""
Expand Down Expand Up @@ -1960,7 +1941,7 @@ def setUp(self):
def test_version(self):
"version is handled as a special case"
args = ["version"]
out, err = self.run_manage(args, discover_formatters=True)
out, err = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, get_version())

Expand Down Expand Up @@ -2713,7 +2694,7 @@ def test_custom_project_template_non_python_files_not_formatted(self):
args = ["startproject", "--template", template_path, "customtestproject"]
testproject_dir = os.path.join(self.test_dir, "customtestproject")

_, err = self.run_django_admin(args, discover_formatters=True)
_, err = self.run_django_admin(args)
self.assertNoOutput(err)
with open(
os.path.join(template_path, "additional_dir", "requirements.in")
Expand Down Expand Up @@ -2808,7 +2789,7 @@ def serve_template(request, *args, **kwargs):
f"{self.live_server_url}/user_agent_check/project_template.tgz"
)
args = ["startproject", "--template", template_url, "urltestproject"]
_, err = self.run_django_admin(args, discover_formatters=True)
_, err = self.run_django_admin(args)

self.assertNoOutput(err)
self.assertIn("Django/%s" % get_version(), user_agent)
Expand Down Expand Up @@ -2879,8 +2860,10 @@ def test_custom_project_template_context_variables(self):
test_manage_py = os.path.join(testproject_dir, "manage.py")
with open(test_manage_py) as fp:
content = fp.read()
self.assertIn('project_name = "another_project"', content)
self.assertIn('project_directory = "%s"' % testproject_dir, content)
self.assertInAfterFormatting('project_name = "another_project"', content)
self.assertInAfterFormatting(
'project_directory = "%s"' % testproject_dir, content
)

def test_no_escaping_of_project_variables(self):
"Make sure template context variables are not html escaped"
Expand Down Expand Up @@ -2990,7 +2973,7 @@ def test_custom_project_template_hidden_directory_included(self):
self.assertNoOutput(err)
render_py_path = os.path.join(testproject_dir, ".hidden", "render.py")
with open(render_py_path) as fp:
self.assertIn(
self.assertInAfterFormatting(
f"# The {project_name} should be rendered.",
fp.read(),
)
Expand Down Expand Up @@ -3150,7 +3133,7 @@ def test_template(self):
with open(os.path.join(app_path, "apps.py")) as f:
content = f.read()
self.assertIn("class NewAppConfig(AppConfig)", content)
self.assertIn("name = 'new_app'", content)
self.assertInAfterFormatting("name = 'new_app'", content)

def test_creates_directory_when_custom_app_destination_missing(self):
args = [
Expand Down
6 changes: 6 additions & 0 deletions tests/humanize_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def test_intcomma(self):
"-1234567.1234567",
Decimal("1234567.1234567"),
Decimal("-1234567.1234567"),
Decimal("Infinity"),
Decimal("-Infinity"),
Decimal("NaN"),
None,
"1234567",
"-1234567",
Expand Down Expand Up @@ -193,6 +196,9 @@ def test_intcomma(self):
"-1,234,567.1234567",
"1,234,567.1234567",
"-1,234,567.1234567",
"Infinity",
"-Infinity",
"NaN",
None,
"1,234,567",
"-1,234,567",
Expand Down