summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorzhengkangyang <1872483761@qq.com>2026-06-06 16:17:24 +0800
committerJacob Walls <jacobtylerwalls@gmail.com>2026-06-10 10:17:34 -0400
commitf970a98e464320c09dde8d45009eadfb4d038a57 (patch)
tree23211de1605cff20d774a93ccdbbb5ff4c928c2d /tests/utils_tests
parent17a56cd6e600cfb02972657e8958b5ee2e0f936e (diff)
Fixed #37142 -- Moved django_file_prefixes() to django.utils.warnings.
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_warnings.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/utils_tests/test_warnings.py b/tests/utils_tests/test_warnings.py
new file mode 100644
index 0000000000..0c98e8ebe4
--- /dev/null
+++ b/tests/utils_tests/test_warnings.py
@@ -0,0 +1,34 @@
+import os
+from pathlib import Path
+
+import django
+from django.test import SimpleTestCase
+from django.utils.warnings import django_file_prefixes
+
+
+class DjangoFilePrefixesTests(SimpleTestCase):
+ def setUp(self):
+ django_file_prefixes.cache_clear()
+ self.addCleanup(django_file_prefixes.cache_clear)
+
+ def test_no_file(self):
+ orig_file = django.__file__
+ try:
+ # Depending on the cwd, Python might give a local checkout
+ # precedence over installed Django, producing None.
+ django.__file__ = None
+ self.assertEqual(django_file_prefixes(), ())
+ 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{os.path.sep}"))
+
+ def test_does_not_match_packages_prefixed_with_django(self):
+ other_file = Path(django.__file__).parent.parent / "djangoextra" / "__init__.py"
+ self.assertFalse(str(other_file).startswith(django_file_prefixes()))