1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #35667 -- Cached Django file prefixes for warnings.

This commit is contained in:
Adam Johnson
2025-09-12 09:35:01 +01:00
committed by GitHub
parent 41bc48ac1e
commit 7b26b64a63
3 changed files with 38 additions and 5 deletions

View File

@@ -1,7 +1,32 @@
import os
import warnings
import django
from django.test import SimpleTestCase
from django.utils.deprecation import RemovedAfterNextVersionWarning, RenameMethodsBase
from django.utils.deprecation import (
RemovedAfterNextVersionWarning,
RenameMethodsBase,
django_file_prefixes,
)
class DjangoFilePrefixesTests(SimpleTestCase):
def setUp(self):
django_file_prefixes.cache_clear()
def test_no_file(self):
orig_file = django.__file__
try:
del django.__file__
self.assertEqual(django_file_prefixes(), ())
finally:
django.__file__ = orig_file
def test_with_file(self):
prefixes = django_file_prefixes()
self.assertIsInstance(prefixes, tuple)
self.assertEqual(len(prefixes), 1)
self.assertTrue(prefixes[0].endswith(f"{os.path.sep}django"))
class RenameManagerMethods(RenameMethodsBase):