diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-01-17 22:09:56 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-20 14:07:28 +0100 |
| commit | f5772de69679efb54129ac1cbca3579b512778af (patch) | |
| tree | ab215760e2e77124bbb8970b0913c2a99ae68743 /tests | |
| parent | 61dae11df52fae71fc3050974ac459f362c9dfd7 (diff) | |
Fixed #36005 -- Dropped support for Python 3.10 and 3.11.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mail/tests.py | 2 | ||||
| -rw-r--r-- | tests/model_enums/tests.py | 9 | ||||
| -rw-r--r-- | tests/model_fields/test_filefield.py | 8 | ||||
| -rwxr-xr-x | tests/runtests.py | 19 | ||||
| -rw-r--r-- | tests/test_runner/test_debug_sql.py | 13 | ||||
| -rw-r--r-- | tests/test_runner/test_discover_runner.py | 3 | ||||
| -rw-r--r-- | tests/test_runner/test_parallel.py | 13 | ||||
| -rw-r--r-- | tests/test_runner/tests.py | 15 | ||||
| -rw-r--r-- | tests/test_utils/tests.py | 15 | ||||
| -rw-r--r-- | tests/utils_tests/test_dateparse.py | 7 | ||||
| -rw-r--r-- | tests/utils_tests/test_functional.py | 14 | ||||
| -rw-r--r-- | tests/view_tests/tests/test_debug.py | 5 |
12 files changed, 34 insertions, 89 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 12cbc8e874..2bc1364bed 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -184,7 +184,7 @@ class MailTests(MailTestsMixin, SimpleTestCase): """Line length check should encode the payload supporting `surrogateescape`. Following https://github.com/python/cpython/issues/76511, newer - versions of Python (3.11.9, 3.12.3 and 3.13) ensure that a message's + versions of Python (3.12.3 and 3.13) ensure that a message's payload is encoded with the provided charset and `surrogateescape` is used as the error handling strategy. diff --git a/tests/model_enums/tests.py b/tests/model_enums/tests.py index e60df7c24b..e485a83d8a 100644 --- a/tests/model_enums/tests.py +++ b/tests/model_enums/tests.py @@ -8,7 +8,6 @@ from django.template import Context, Template from django.test import SimpleTestCase from django.utils.functional import Promise from django.utils.translation import gettext_lazy as _ -from django.utils.version import PY311 class Suit(models.IntegerChoices): @@ -200,13 +199,7 @@ class ChoicesTests(SimpleTestCase): def test_do_not_call_in_templates_nonmember(self): self.assertNotIn("do_not_call_in_templates", Suit.__members__) - if PY311: - self.assertIs(Suit.do_not_call_in_templates, True) - else: - # Using @property on an enum does not behave as expected. - self.assertTrue(Suit.do_not_call_in_templates) - self.assertIsNot(Suit.do_not_call_in_templates, True) - self.assertIsInstance(Suit.do_not_call_in_templates, property) + self.assertIs(Suit.do_not_call_in_templates, True) class Separator(bytes, models.Choices): diff --git a/tests/model_fields/test_filefield.py b/tests/model_fields/test_filefield.py index 478e9edd36..57cc7365da 100644 --- a/tests/model_fields/test_filefield.py +++ b/tests/model_fields/test_filefield.py @@ -12,7 +12,6 @@ from django.core.files.uploadedfile import TemporaryUploadedFile from django.db import IntegrityError, models from django.test import TestCase, override_settings from django.test.utils import isolate_apps -from django.utils.version import PY311 from .models import Document @@ -80,10 +79,9 @@ class FileFieldTests(TestCase): with self.assertRaisesMessage(FieldError, msg) as cm: d.save() - if PY311: - self.assertEqual( - cm.exception.__notes__, ["Pass a 'name' argument to ContentFile."] - ) + self.assertEqual( + cm.exception.__notes__, ["Pass a 'name' argument to ContentFile."] + ) def test_delete_content_file(self): file = ContentFile(b"", name="foo") diff --git a/tests/runtests.py b/tests/runtests.py index adf9e1bc29..e9052ca4a9 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -34,7 +34,7 @@ else: ) from django.utils.functional import classproperty from django.utils.log import DEFAULT_LOGGING - from django.utils.version import PY312, PYPY + from django.utils.version import PYPY try: @@ -691,15 +691,14 @@ if __name__ == "__main__": "Same as unittest -k option. Can be used multiple times." ), ) - if PY312: - parser.add_argument( - "--durations", - dest="durations", - type=int, - default=None, - metavar="N", - help="Show the N slowest test cases (N=0 for all).", - ) + parser.add_argument( + "--durations", + dest="durations", + type=int, + default=None, + metavar="N", + help="Show the N slowest test cases (N=0 for all).", + ) options = parser.parse_args() diff --git a/tests/test_runner/test_debug_sql.py b/tests/test_runner/test_debug_sql.py index e7e8d14fbd..27fc4001c2 100644 --- a/tests/test_runner/test_debug_sql.py +++ b/tests/test_runner/test_debug_sql.py @@ -4,7 +4,6 @@ from io import StringIO from django.db import connection from django.test import TestCase from django.test.runner import DiscoverRunner -from django.utils.version import PY311 from .models import Person @@ -114,17 +113,15 @@ class TestDebugSQL(unittest.TestCase): ), ] - # Python 3.11 uses fully qualified test name in the output. - method_name = ".runTest" if PY311 else "" test_class_path = "test_runner.test_debug_sql.TestDebugSQL" verbose_expected_outputs = [ - f"runTest ({test_class_path}.FailingTest{method_name}) ... FAIL", - f"runTest ({test_class_path}.ErrorTest{method_name}) ... ERROR", - f"runTest ({test_class_path}.PassingTest{method_name}) ... ok", + f"runTest ({test_class_path}.FailingTest.runTest) ... FAIL", + f"runTest ({test_class_path}.ErrorTest.runTest) ... ERROR", + f"runTest ({test_class_path}.PassingTest.runTest) ... ok", # If there are errors/failures in subtests but not in test itself, # the status is not written. That behavior comes from Python. - f"runTest ({test_class_path}.FailingSubTest{method_name}) ...", - f"runTest ({test_class_path}.ErrorSubTest{method_name}) ...", + f"runTest ({test_class_path}.FailingSubTest.runTest) ...", + f"runTest ({test_class_path}.ErrorSubTest.runTest) ...", ( """SELECT COUNT(*) AS "__count"\n""" """FROM "test_runner_person"\nWHERE """ diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index 4f13cceeff..4c4a22397b 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -16,7 +16,6 @@ from django.test.utils import ( captured_stderr, captured_stdout, ) -from django.utils.version import PY312 @contextmanager @@ -768,7 +767,6 @@ class DiscoverRunnerTests(SimpleTestCase): failures = runner.suite_result(suite, result) self.assertEqual(failures, expected_failures) - @unittest.skipUnless(PY312, "unittest --durations option requires Python 3.12") def test_durations(self): with captured_stderr() as stderr, captured_stdout(): runner = DiscoverRunner(durations=10) @@ -776,7 +774,6 @@ class DiscoverRunnerTests(SimpleTestCase): runner.run_suite(suite) self.assertIn("Slowest test durations", stderr.getvalue()) - @unittest.skipUnless(PY312, "unittest --durations option requires Python 3.12") def test_durations_debug_sql(self): with captured_stderr() as stderr, captured_stdout(): runner = DiscoverRunner(durations=10, debug_sql=True) diff --git a/tests/test_runner/test_parallel.py b/tests/test_runner/test_parallel.py index 5026bc36c5..3af0fbf2f9 100644 --- a/tests/test_runner/test_parallel.py +++ b/tests/test_runner/test_parallel.py @@ -7,7 +7,6 @@ from unittest.suite import TestSuite, _ErrorHolder from django.test import SimpleTestCase from django.test.runner import ParallelTestSuite, RemoteTestResult -from django.utils.version import PY311, PY312 try: import tblib.pickling_support @@ -193,27 +192,21 @@ class RemoteTestResultTest(SimpleTestCase): subtest_test.run(result=result) events = result.events - # addDurations added in Python 3.12. - if PY312: - self.assertEqual(len(events), 5) - else: - self.assertEqual(len(events), 4) + self.assertEqual(len(events), 5) self.assertIs(result.wasSuccessful(), False) event = events[1] self.assertEqual(event[0], "addSubTest") self.assertEqual( str(event[2]), - "dummy_test (test_runner.test_parallel.SampleFailingSubtest%s) (index=0)" - # Python 3.11 uses fully qualified test name in the output. - % (".dummy_test" if PY311 else ""), + "dummy_test (test_runner.test_parallel.SampleFailingSubtest.dummy_test) " + "(index=0)", ) self.assertEqual(repr(event[3][1]), "AssertionError('0 != 1')") event = events[2] self.assertEqual(repr(event[3][1]), "AssertionError('2 != 1')") - @unittest.skipUnless(PY312, "unittest --durations option requires Python 3.12") def test_add_duration(self): result = RemoteTestResult() result.addDuration(None, 2.3) diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index fba8dd3b6f..d66ece4005 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -15,7 +15,7 @@ from django import db from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command -from django.core.management.base import CommandError, SystemCheckError +from django.core.management.base import SystemCheckError from django.test import SimpleTestCase, TransactionTestCase, skipUnlessDBFeature from django.test.runner import ( DiscoverRunner, @@ -32,7 +32,6 @@ from django.test.utils import ( get_unique_databases_and_mirrors, iter_test_cases, ) -from django.utils.version import PY312 from .models import B, Person, Through @@ -479,7 +478,6 @@ class ManageCommandTests(unittest.TestCase): ) self.assertIn("Total run took", stderr.getvalue()) - @unittest.skipUnless(PY312, "unittest --durations option requires Python 3.12") def test_durations(self): with captured_stderr() as stderr: call_command( @@ -490,17 +488,6 @@ class ManageCommandTests(unittest.TestCase): ) self.assertIn("durations=10", stderr.getvalue()) - @unittest.skipIf(PY312, "unittest --durations option requires Python 3.12") - def test_durations_lt_py312(self): - msg = "Error: unrecognized arguments: --durations=10" - with self.assertRaises(CommandError, msg=msg): - call_command( - "test", - "--durations=10", - "sites", - testrunner="test_runner.tests.MockTestRunner", - ) - # Isolate from the real environment. @mock.patch.dict(os.environ, {}, clear=True) diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 359cf07402..16692500e3 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -49,7 +49,6 @@ from django.test.utils import ( ) from django.urls import NoReverseMatch, path, reverse, reverse_lazy from django.utils.html import VOID_ELEMENTS -from django.utils.version import PY311 from .models import Car, Person, PossessedCar from .views import empty_response @@ -103,11 +102,9 @@ class SkippingTestCase(SimpleTestCase): SkipTestCase("test_foo").test_foo, ValueError, "skipUnlessDBFeature cannot be used on test_foo (test_utils.tests." - "SkippingTestCase.test_skip_unless_db_feature.<locals>.SkipTestCase%s) " - "as SkippingTestCase.test_skip_unless_db_feature.<locals>.SkipTestCase " - "doesn't allow queries against the 'default' database." - # Python 3.11 uses fully qualified test name in the output. - % (".test_foo" if PY311 else ""), + "SkippingTestCase.test_skip_unless_db_feature.<locals>.SkipTestCase." + "test_foo) as SkippingTestCase.test_skip_unless_db_feature.<locals>." + "SkipTestCase doesn't allow queries against the 'default' database.", ) def test_skip_if_db_feature(self): @@ -150,11 +147,9 @@ class SkippingTestCase(SimpleTestCase): SkipTestCase("test_foo").test_foo, ValueError, "skipIfDBFeature cannot be used on test_foo (test_utils.tests." - "SkippingTestCase.test_skip_if_db_feature.<locals>.SkipTestCase%s) " + "SkippingTestCase.test_skip_if_db_feature.<locals>.SkipTestCase.test_foo) " "as SkippingTestCase.test_skip_if_db_feature.<locals>.SkipTestCase " - "doesn't allow queries against the 'default' database." - # Python 3.11 uses fully qualified test name in the output. - % (".test_foo" if PY311 else ""), + "doesn't allow queries against the 'default' database.", ) diff --git a/tests/utils_tests/test_dateparse.py b/tests/utils_tests/test_dateparse.py index 12611e12c2..a01942bfd0 100644 --- a/tests/utils_tests/test_dateparse.py +++ b/tests/utils_tests/test_dateparse.py @@ -8,7 +8,6 @@ from django.utils.dateparse import ( parse_time, ) from django.utils.timezone import get_fixed_timezone -from django.utils.version import PY311 class DateParseTests(unittest.TestCase): @@ -16,8 +15,7 @@ class DateParseTests(unittest.TestCase): # Valid inputs self.assertEqual(parse_date("2012-04-23"), date(2012, 4, 23)) self.assertEqual(parse_date("2012-4-9"), date(2012, 4, 9)) - if PY311: - self.assertEqual(parse_date("20120423"), date(2012, 4, 23)) + self.assertEqual(parse_date("20120423"), date(2012, 4, 23)) # Invalid inputs self.assertIsNone(parse_date("2012423")) with self.assertRaises(ValueError): @@ -26,8 +24,7 @@ class DateParseTests(unittest.TestCase): def test_parse_time(self): # Valid inputs self.assertEqual(parse_time("09:15:00"), time(9, 15)) - if PY311: - self.assertEqual(parse_time("091500"), time(9, 15)) + self.assertEqual(parse_time("091500"), time(9, 15)) self.assertEqual(parse_time("10:10"), time(10, 10)) self.assertEqual(parse_time("10:20:30.400"), time(10, 20, 30, 400000)) self.assertEqual(parse_time("10:20:30,400"), time(10, 20, 30, 400000)) diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index fa23debb4d..8b5c330bcf 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -1,6 +1,5 @@ from django.test import SimpleTestCase from django.utils.functional import cached_property, classproperty, lazy -from django.utils.version import PY312 class FunctionalTests(SimpleTestCase): @@ -133,14 +132,10 @@ class FunctionalTests(SimpleTestCase): "Cannot assign the same cached_property to two different names ('a' and " "'b')." ) - if PY312: - error_type = TypeError - msg = type_msg - else: - error_type = RuntimeError - msg = "Error calling __set_name__" + error_type = TypeError + msg = type_msg - with self.assertRaisesMessage(error_type, msg) as ctx: + with self.assertRaisesMessage(error_type, msg): class ReusedCachedProperty: @cached_property @@ -149,9 +144,6 @@ class FunctionalTests(SimpleTestCase): b = a - if not PY312: - self.assertEqual(str(ctx.exception.__context__), str(TypeError(type_msg))) - def test_cached_property_reuse_same_name(self): """ Reusing a cached_property on different classes under the same name is diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index c65514a170..ba67945d59 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -7,7 +7,7 @@ import tempfile import threading from io import StringIO from pathlib import Path -from unittest import mock, skipIf, skipUnless +from unittest import mock, skipIf from asgiref.sync import async_to_sync, iscoroutinefunction @@ -24,7 +24,6 @@ from django.urls.converters import IntConverter from django.utils.functional import SimpleLazyObject from django.utils.regex_helper import _lazy_re_compile from django.utils.safestring import mark_safe -from django.utils.version import PY311 from django.views.debug import ( CallableSettingWrapper, ExceptionCycleWarning, @@ -695,7 +694,6 @@ class ExceptionReporterTests(SimpleTestCase): text, ) - @skipUnless(PY311, "Exception notes were added in Python 3.11.") def test_exception_with_notes(self): request = self.rf.get("/test_view/") try: @@ -806,7 +804,6 @@ class ExceptionReporterTests(SimpleTestCase): or os.environ.get("PYTHONNODEBUGRANGES", False), "Fine-grained error locations are disabled.", ) - @skipUnless(PY311, "Fine-grained error locations were added in Python 3.11.") def test_highlight_error_position(self): request = self.rf.get("/test_view/") try: |
