summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-01-19 08:35:16 +0100
committerCarlton Gibson <carlton@noumenal.es>2021-02-10 10:20:54 +0100
commitec0ff406311de88f4e2a135d784363424fe602aa (patch)
treec1659b85ea145704a1b733d40a6a9a45e9332d0f /tests
parent9c6ba876928fd20194ac3238dc06aeae66d7bd50 (diff)
downloaddjango-ec0ff406311de88f4e2a135d784363424fe602aa.tar.gz
Fixed #32355 -- Dropped support for Python 3.6 and 3.7
Diffstat (limited to 'tests')
-rw-r--r--tests/dbshell/test_sqlite.py2
-rw-r--r--tests/handlers/tests.py3
-rw-r--r--tests/managers_regress/tests.py4
-rw-r--r--tests/model_inheritance/tests.py3
-rwxr-xr-xtests/runtests.py16
-rw-r--r--tests/test_runner/test_discover_runner.py6
-rw-r--r--tests/test_runner/test_parallel.py6
-rw-r--r--tests/user_commands/management/commands/subparser_dest.py4
-rw-r--r--tests/user_commands/tests.py18
-rw-r--r--tests/utils_tests/test_autoreload.py8
-rw-r--r--tests/utils_tests/test_http.py67
11 files changed, 21 insertions, 116 deletions
diff --git a/tests/dbshell/test_sqlite.py b/tests/dbshell/test_sqlite.py
index 570230f62d..ea4bdd62e1 100644
--- a/tests/dbshell/test_sqlite.py
+++ b/tests/dbshell/test_sqlite.py
@@ -13,7 +13,7 @@ class SqliteDbshellCommandTestCase(SimpleTestCase):
def test_path_name(self):
self.assertEqual(
self.settings_to_cmd_args_env({'NAME': Path('test.db.sqlite3')}),
- (['sqlite3', 'test.db.sqlite3'], None),
+ (['sqlite3', Path('test.db.sqlite3')], None),
)
def test_parameters(self):
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index 1d445cd38c..dd727cde32 100644
--- a/tests/handlers/tests.py
+++ b/tests/handlers/tests.py
@@ -5,7 +5,6 @@ from django.db import close_old_connections, connection
from django.test import (
RequestFactory, SimpleTestCase, TransactionTestCase, override_settings,
)
-from django.utils.version import PY37
class HandlerTests(SimpleTestCase):
@@ -183,7 +182,7 @@ class HandlerRequestTests(SimpleTestCase):
def test_invalid_urls(self):
response = self.client.get('~%A9helloworld')
self.assertEqual(response.status_code, 404)
- self.assertEqual(response.context['request_path'], '/~%25A9helloworld' if PY37 else '/%7E%25A9helloworld')
+ self.assertEqual(response.context['request_path'], '/~%25A9helloworld')
response = self.client.get('d%aao%aaw%aan%aal%aao%aaa%aad%aa/')
self.assertEqual(response.context['request_path'], '/d%25AAo%25AAw%25AAn%25AAl%25AAo%25AAa%25AAd%25AA')
diff --git a/tests/managers_regress/tests.py b/tests/managers_regress/tests.py
index 421e30ca45..c18cd8adda 100644
--- a/tests/managers_regress/tests.py
+++ b/tests/managers_regress/tests.py
@@ -1,10 +1,7 @@
-from unittest import skipUnless
-
from django.db import models
from django.template import Context, Template
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.utils import isolate_apps
-from django.utils.version import PY37
from .models import (
AbstractBase1, AbstractBase2, AbstractBase3, Child1, Child2, Child3,
@@ -287,6 +284,5 @@ class TestManagerInheritance(SimpleTestCase):
self.assertEqual(TestModel._meta.managers, (TestModel.custom_manager,))
self.assertEqual(TestModel._meta.managers_map, {'custom_manager': TestModel.custom_manager})
- @skipUnless(PY37, '__class_getitem__() was added in Python 3.7')
def test_manager_class_getitem(self):
self.assertIs(models.Manager[Child1], models.Manager)
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py
index 60edaa3d99..1ab0e15eee 100644
--- a/tests/model_inheritance/tests.py
+++ b/tests/model_inheritance/tests.py
@@ -1,11 +1,9 @@
from operator import attrgetter
-from unittest import skipUnless
from django.core.exceptions import FieldError, ValidationError
from django.db import connection, models
from django.test import SimpleTestCase, TestCase
from django.test.utils import CaptureQueriesContext, isolate_apps
-from django.utils.version import PY37
from .models import (
Base, Chef, CommonInfo, GrandChild, GrandParent, ItalianRestaurant,
@@ -219,7 +217,6 @@ class ModelInheritanceTests(TestCase):
self.assertSequenceEqual(qs, [p2, p1])
self.assertIn(expected_order_by_sql, str(qs.query))
- @skipUnless(PY37, '__class_getitem__() was added in Python 3.7')
def test_queryset_class_getitem(self):
self.assertIs(models.QuerySet[Post], models.QuerySet)
self.assertIs(models.QuerySet[Post, Post], models.QuerySet)
diff --git a/tests/runtests.py b/tests/runtests.py
index 4cd16809c4..afdf68c21b 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -28,7 +28,6 @@ else:
RemovedInDjango41Warning, RemovedInDjango50Warning,
)
from django.utils.log import DEFAULT_LOGGING
- from django.utils.version import PY37
try:
import MySQLdb
@@ -521,14 +520,13 @@ if __name__ == "__main__":
'--timing', action='store_true',
help='Output timings, including database set up and total run time.',
)
- if PY37:
- parser.add_argument(
- '-k', dest='test_name_patterns', action='append',
- help=(
- 'Only run test methods and classes matching test name pattern. '
- 'Same as unittest -k option. Can be used multiple times.'
- ),
- )
+ parser.add_argument(
+ '-k', dest='test_name_patterns', action='append',
+ help=(
+ 'Only run test methods and classes matching test name pattern. '
+ 'Same as unittest -k option. Can be used multiple times.'
+ ),
+ )
options = parser.parse_args()
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
index 183e283d08..ee95f9da72 100644
--- a/tests/test_runner/test_discover_runner.py
+++ b/tests/test_runner/test_discover_runner.py
@@ -1,9 +1,7 @@
import os
from argparse import ArgumentParser
from contextlib import contextmanager
-from unittest import (
- TestSuite, TextTestRunner, defaultTestLoader, mock, skipUnless,
-)
+from unittest import TestSuite, TextTestRunner, defaultTestLoader, mock
from django.db import connections
from django.test import SimpleTestCase
@@ -11,7 +9,6 @@ from django.test.runner import DiscoverRunner
from django.test.utils import (
NullTimeKeeper, TimeKeeper, captured_stderr, captured_stdout,
)
-from django.utils.version import PY37
@contextmanager
@@ -83,7 +80,6 @@ class DiscoverRunnerTests(SimpleTestCase):
self.assertEqual(count, 1)
- @skipUnless(PY37, 'unittest -k option requires Python 3.7 and later')
def test_name_patterns(self):
all_test_1 = [
'DjangoCase1.test_1', 'DjangoCase2.test_1',
diff --git a/tests/test_runner/test_parallel.py b/tests/test_runner/test_parallel.py
index c1a89bd0f0..70959012b5 100644
--- a/tests/test_runner/test_parallel.py
+++ b/tests/test_runner/test_parallel.py
@@ -2,7 +2,6 @@ import unittest
from django.test import SimpleTestCase
from django.test.runner import RemoteTestResult
-from django.utils.version import PY37
try:
import tblib
@@ -80,8 +79,7 @@ class RemoteTestResultTest(SimpleTestCase):
event = events[1]
self.assertEqual(event[0], 'addSubTest')
self.assertEqual(str(event[2]), 'dummy_test (test_runner.test_parallel.SampleFailingSubtest) (index=0)')
- trailing_comma = '' if PY37 else ','
- self.assertEqual(repr(event[3][1]), "AssertionError('0 != 1'%s)" % trailing_comma)
+ self.assertEqual(repr(event[3][1]), "AssertionError('0 != 1')")
event = events[2]
- self.assertEqual(repr(event[3][1]), "AssertionError('2 != 1'%s)" % trailing_comma)
+ self.assertEqual(repr(event[3][1]), "AssertionError('2 != 1')")
diff --git a/tests/user_commands/management/commands/subparser_dest.py b/tests/user_commands/management/commands/subparser_dest.py
index ffea7efac7..000078911d 100644
--- a/tests/user_commands/management/commands/subparser_dest.py
+++ b/tests/user_commands/management/commands/subparser_dest.py
@@ -1,11 +1,9 @@
from django.core.management.base import BaseCommand
-from django.utils.version import PY37
class Command(BaseCommand):
def add_arguments(self, parser):
- kwargs = {'required': True} if PY37 else {}
- subparsers = parser.add_subparsers(dest='subcommand', **kwargs)
+ subparsers = parser.add_subparsers(dest='subcommand', required=True)
parser_foo = subparsers.add_parser('foo')
parser_foo.add_argument('--bar')
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index 9262e2717a..05415717c6 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -17,7 +17,6 @@ from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, extend_sys_path, ignore_warnings
from django.utils import translation
from django.utils.deprecation import RemovedInDjango41Warning
-from django.utils.version import PY37
from .management.commands import dance
@@ -337,20 +336,9 @@ class CommandTests(SimpleTestCase):
msg = "Error: invalid choice: 'test' (choose from 'foo')"
with self.assertRaisesMessage(CommandError, msg):
management.call_command('subparser', 'test', 12)
- if PY37:
- # "required" option requires Python 3.7 and later.
- msg = 'Error: the following arguments are required: subcommand'
- with self.assertRaisesMessage(CommandError, msg):
- management.call_command('subparser_dest', subcommand='foo', bar=12)
- else:
- msg = (
- 'Unknown option(s) for subparser_dest command: subcommand. '
- 'Valid options are: bar, force_color, help, no_color, '
- 'pythonpath, settings, skip_checks, stderr, stdout, '
- 'traceback, verbosity, version.'
- )
- with self.assertRaisesMessage(TypeError, msg):
- management.call_command('subparser_dest', subcommand='foo', bar=12)
+ msg = 'Error: the following arguments are required: subcommand'
+ with self.assertRaisesMessage(CommandError, msg):
+ management.call_command('subparser_dest', subcommand='foo', bar=12)
def test_create_parser_kwargs(self):
"""BaseCommand.create_parser() passes kwargs to CommandParser."""
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index 86c510eace..3cb901af7d 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -195,10 +195,10 @@ class TestChildArguments(SimpleTestCase):
with tempfile.TemporaryDirectory() as tmpdir:
exe_path = Path(tmpdir) / 'django-admin.exe'
exe_path.touch()
- with mock.patch('sys.argv', [str(exe_path.with_suffix('')), 'runserver']):
+ with mock.patch('sys.argv', [exe_path.with_suffix(''), 'runserver']):
self.assertEqual(
autoreload.get_child_arguments(),
- [str(exe_path), 'runserver']
+ [exe_path, 'runserver']
)
@mock.patch('sys.warnoptions', [])
@@ -206,10 +206,10 @@ class TestChildArguments(SimpleTestCase):
with tempfile.TemporaryDirectory() as tmpdir:
script_path = Path(tmpdir) / 'django-admin-script.py'
script_path.touch()
- with mock.patch('sys.argv', [str(script_path.with_name('django-admin')), 'runserver']):
+ with mock.patch('sys.argv', [script_path.with_name('django-admin'), 'runserver']):
self.assertEqual(
autoreload.get_child_arguments(),
- [sys.executable, str(script_path), 'runserver']
+ [sys.executable, script_path, 'runserver']
)
@mock.patch('sys.argv', ['does-not-exist', 'runserver'])
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py
index 4c11f91116..675a6e186e 100644
--- a/tests/utils_tests/test_http.py
+++ b/tests/utils_tests/test_http.py
@@ -7,7 +7,7 @@ from django.test import SimpleTestCase
from django.utils.datastructures import MultiValueDict
from django.utils.http import (
base36_to_int, escape_leading_slashes, http_date, int_to_base36,
- is_same_domain, parse_etags, parse_http_date, parse_qsl, quote_etag,
+ is_same_domain, parse_etags, parse_http_date, quote_etag,
url_has_allowed_host_and_scheme, urlencode, urlsafe_base64_decode,
urlsafe_base64_encode,
)
@@ -331,68 +331,3 @@ class EscapeLeadingSlashesTests(unittest.TestCase):
for url, expected in tests:
with self.subTest(url=url):
self.assertEqual(escape_leading_slashes(url), expected)
-
-
-# TODO: Remove when dropping support for PY37. Backport of unit tests for
-# urllib.parse.parse_qsl() from Python 3.8. Copyright (C) 2020 Python Software
-# Foundation (see LICENSE.python).
-class ParseQSLBackportTests(unittest.TestCase):
- def test_parse_qsl(self):
- tests = [
- ('', []),
- ('&', []),
- ('&&', []),
- ('=', [('', '')]),
- ('=a', [('', 'a')]),
- ('a', [('a', '')]),
- ('a=', [('a', '')]),
- ('&a=b', [('a', 'b')]),
- ('a=a+b&b=b+c', [('a', 'a b'), ('b', 'b c')]),
- ('a=1&a=2', [('a', '1'), ('a', '2')]),
- (b'', []),
- (b'&', []),
- (b'&&', []),
- (b'=', [(b'', b'')]),
- (b'=a', [(b'', b'a')]),
- (b'a', [(b'a', b'')]),
- (b'a=', [(b'a', b'')]),
- (b'&a=b', [(b'a', b'b')]),
- (b'a=a+b&b=b+c', [(b'a', b'a b'), (b'b', b'b c')]),
- (b'a=1&a=2', [(b'a', b'1'), (b'a', b'2')]),
- (';', []),
- (';;', []),
- (';a=b', [('a', 'b')]),
- ('a=a+b;b=b+c', [('a', 'a b'), ('b', 'b c')]),
- ('a=1;a=2', [('a', '1'), ('a', '2')]),
- (b';', []),
- (b';;', []),
- (b';a=b', [(b'a', b'b')]),
- (b'a=a+b;b=b+c', [(b'a', b'a b'), (b'b', b'b c')]),
- (b'a=1;a=2', [(b'a', b'1'), (b'a', b'2')]),
- ]
- for original, expected in tests:
- with self.subTest(original):
- result = parse_qsl(original, keep_blank_values=True)
- self.assertEqual(result, expected, 'Error parsing %r' % original)
- expect_without_blanks = [v for v in expected if len(v[1])]
- result = parse_qsl(original, keep_blank_values=False)
- self.assertEqual(result, expect_without_blanks, 'Error parsing %r' % original)
-
- def test_parse_qsl_encoding(self):
- result = parse_qsl('key=\u0141%E9', encoding='latin-1')
- self.assertEqual(result, [('key', '\u0141\xE9')])
- result = parse_qsl('key=\u0141%C3%A9', encoding='utf-8')
- self.assertEqual(result, [('key', '\u0141\xE9')])
- result = parse_qsl('key=\u0141%C3%A9', encoding='ascii')
- self.assertEqual(result, [('key', '\u0141\ufffd\ufffd')])
- result = parse_qsl('key=\u0141%E9-', encoding='ascii')
- self.assertEqual(result, [('key', '\u0141\ufffd-')])
- result = parse_qsl('key=\u0141%E9-', encoding='ascii', errors='ignore')
- self.assertEqual(result, [('key', '\u0141-')])
-
- def test_parse_qsl_max_num_fields(self):
- with self.assertRaises(ValueError):
- parse_qsl('&'.join(['a=a'] * 11), max_num_fields=10)
- with self.assertRaises(ValueError):
- parse_qsl(';'.join(['a=a'] * 11), max_num_fields=10)
- parse_qsl('&'.join(['a=a'] * 10), max_num_fields=10)