test:func
.')
- @unittest.skipIf(six.PY2, "Python 2 doesn't support __qualname__.")
def test_view_index_with_method(self):
"""
Views that are methods are listed correctly.
@@ -89,7 +87,7 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
"""
url = reverse('django-admindocs-views-detail', args=['django.contrib.admin.sites.AdminSite.index'])
response = self.client.get(url)
- self.assertEqual(response.status_code, 200 if six.PY3 else 404)
+ self.assertEqual(response.status_code, 200)
def test_model_index(self):
response = self.client.get(reverse('django-admindocs-models-index'))
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 08fe645535..e37e8a4256 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -27,7 +27,7 @@ from django.test import (
)
from django.utils._os import npath, upath
from django.utils.encoding import force_text
-from django.utils.six import PY2, StringIO
+from django.utils.six import StringIO
custom_templates_dir = os.path.join(os.path.dirname(upath(__file__)), 'custom_templates')
@@ -626,7 +626,6 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
self.assertTrue(os.path.exists(app_path))
self.assertTrue(os.path.exists(os.path.join(app_path, 'api.py')))
- @unittest.skipIf(PY2, "Python 2 doesn't support Unicode package names.")
def test_startapp_unicode_name(self):
"directory: startapp creates the correct directory with unicode characters"
args = ['startapp', 'こんにちは']
@@ -1897,18 +1896,11 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
self.addCleanup(shutil.rmtree, testproject_dir, True)
out, err = self.run_django_admin(args)
- if PY2:
- self.assertOutput(
- err,
- "Error: '%s' is not a valid project name. Please make "
- "sure the name begins with a letter or underscore." % bad_name
- )
- else:
- self.assertOutput(
- err,
- "Error: '%s' is not a valid project name. Please make "
- "sure the name is a valid identifier." % bad_name
- )
+ self.assertOutput(
+ err,
+ "Error: '%s' is not a valid project name. Please make "
+ "sure the name is a valid identifier." % bad_name
+ )
self.assertFalse(os.path.exists(testproject_dir))
def test_simple_project_different_directory(self):
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index bffac69e21..65886b2063 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -8,7 +8,6 @@ from django.db.models import (
)
from django.db.models.functions import Lower
from django.test import TestCase, skipUnlessDBFeature
-from django.utils import six
from .models import (
Author, Book, Company, DepartmentStore, Employee, Publisher, Store, Ticket,
@@ -24,7 +23,7 @@ def cxOracle_py3_bug(func):
"""
from unittest import expectedFailure
from django.db import connection
- return expectedFailure(func) if connection.vendor == 'oracle' and six.PY3 else func
+ return expectedFailure(func) if connection.vendor == 'oracle' else func
class NonAggregateAnnotationTestCase(TestCase):
diff --git a/tests/apps/tests.py b/tests/apps/tests.py
index d2adc681f2..9576420b54 100644
--- a/tests/apps/tests.py
+++ b/tests/apps/tests.py
@@ -1,5 +1,4 @@
import os
-from unittest import skipUnless
from django.apps import AppConfig, apps
from django.apps.registry import Apps
@@ -8,7 +7,6 @@ from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
from django.db import models
from django.test import SimpleTestCase, override_settings
from django.test.utils import extend_sys_path, isolate_apps
-from django.utils import six
from django.utils._os import upath
from .default_config_app.apps import CustomConfig
@@ -371,7 +369,6 @@ class AppConfigTests(SimpleTestCase):
self.assertEqual(ac.path, 'a')
-@skipUnless(six.PY3, "Namespace packages sans __init__.py were added in Python 3.3")
class NamespacePackageAppTests(SimpleTestCase):
# We need nsapp to be top-level so our multiple-paths tests can add another
# location for it (if its inside a normal package with an __init__.py that
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py
index 36b4e8f4e7..c055b58042 100644
--- a/tests/auth_tests/test_forms.py
+++ b/tests/auth_tests/test_forms.py
@@ -1,6 +1,5 @@
import datetime
import re
-from unittest import skipIf
from django import forms
from django.contrib.auth.forms import (
@@ -15,7 +14,7 @@ from django.core import mail
from django.core.mail import EmailMultiAlternatives
from django.forms.fields import CharField, Field, IntegerField
from django.test import SimpleTestCase, TestCase, mock, override_settings
-from django.utils import six, translation
+from django.utils import translation
from django.utils.encoding import force_text
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
@@ -114,14 +113,10 @@ class UserCreationFormTest(TestDataMixin, TestCase):
'password2': 'test123',
}
form = UserCreationForm(data)
- if six.PY3:
- self.assertTrue(form.is_valid())
- u = form.save()
- self.assertEqual(u.username, '宝')
- else:
- self.assertFalse(form.is_valid())
+ self.assertTrue(form.is_valid())
+ u = form.save()
+ self.assertEqual(u.username, '宝')
- @skipIf(six.PY2, "Python 2 doesn't support unicode usernames by default.")
def test_normalize_username(self):
# The normalization happens in AbstractBaseUser.clean() and ModelForm
# validation calls Model.clean().
@@ -137,7 +132,6 @@ class UserCreationFormTest(TestDataMixin, TestCase):
self.assertNotEqual(user.username, ohm_username)
self.assertEqual(user.username, 'testΩ') # U+03A9 GREEK CAPITAL LETTER OMEGA
- @skipIf(six.PY2, "Python 2 doesn't support unicode usernames by default.")
def test_duplicate_normalized_unicode(self):
"""
To prevent almost identical usernames, visually identical but differing
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index eaceafb444..ac57bbd511 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -32,9 +32,6 @@ def mock_inputs(inputs):
class mock_getpass:
@staticmethod
def getpass(prompt=b'Password: ', stream=None):
- if six.PY2:
- # getpass on Windows only supports prompt as bytestring (#19807)
- assert isinstance(prompt, six.binary_type)
if callable(inputs['password']):
return inputs['password']()
return inputs['password']
diff --git a/tests/auth_tests/test_tokens.py b/tests/auth_tests/test_tokens.py
index 7ff3f15f3d..0662ec513e 100644
--- a/tests/auth_tests/test_tokens.py
+++ b/tests/auth_tests/test_tokens.py
@@ -1,11 +1,9 @@
-import unittest
from datetime import date, timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.test import TestCase
-from django.utils.six import PY3
class TokenGeneratorTest(TestCase):
@@ -51,18 +49,6 @@ class TokenGeneratorTest(TestCase):
p2 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1))
self.assertFalse(p2.check_token(user, tk1))
- @unittest.skipIf(PY3, "Unnecessary test with Python 3")
- def test_date_length(self):
- """
- Overly long dates, which are a potential DoS vector, aren't allowed.
- """
- user = User.objects.create_user('ima1337h4x0r', 'test4@example.com', 'p4ssw0rd')
- p0 = PasswordResetTokenGenerator()
-
- # This will put a 14-digit base36 timestamp into the token, which is too large.
- with self.assertRaises(ValueError):
- p0._make_token_with_timestamp(user, 175455491841851871349)
-
def test_check_token_with_nonexistent_token_and_user(self):
user = User.objects.create_user('tokentestuser', 'test2@example.com', 'testpw')
p0 = PasswordResetTokenGenerator()
diff --git a/tests/backends/test_utils.py b/tests/backends/test_utils.py
index 6f59d1b23b..d158e2a5a2 100644
--- a/tests/backends/test_utils.py
+++ b/tests/backends/test_utils.py
@@ -1,7 +1,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.utils import load_backend
from django.test import SimpleTestCase
-from django.utils import six
class TestLoadBackend(SimpleTestCase):
@@ -10,7 +9,7 @@ class TestLoadBackend(SimpleTestCase):
"'foo' isn't an available database backend.\n"
"Try using 'django.db.backends.XXX', where XXX is one of:\n"
" 'mysql', 'oracle', 'postgresql', 'sqlite3'\n"
- "Error was: No module named %s"
- ) % "foo.base" if six.PY2 else "'foo'"
+ "Error was: No module named 'foo'"
+ )
with self.assertRaisesMessage(ImproperlyConfigured, msg):
load_backend('foo')
diff --git a/tests/base/models.py b/tests/base/models.py
index 077b93fbb8..fb91522717 100644
--- a/tests/base/models.py
+++ b/tests/base/models.py
@@ -13,12 +13,3 @@ class CustomBaseModel(models.base.ModelBase):
class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
"""Model subclass with a custom base using six.with_metaclass."""
-
-
-# This is done to ensure that for Python2 only, defining metaclasses
-# still does not fail to create the model.
-
-if six.PY2:
- class MyPython2Model(models.Model):
- """Model subclass with a custom base using __metaclass__."""
- __metaclass__ = CustomBaseModel
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 5be3db0ef4..caeb8a47df 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -928,11 +928,7 @@ class BaseCacheTests(object):
self.assertEqual(cache.get_or_set('mykey', my_callable()), 'value')
def test_get_or_set_version(self):
- msg = (
- "get_or_set() missing 1 required positional argument: 'default'"
- if six.PY3
- else 'get_or_set() takes at least 3 arguments'
- )
+ msg = "get_or_set() missing 1 required positional argument: 'default'"
cache.get_or_set('brian', 1979, version=2)
with self.assertRaisesMessage(TypeError, msg):
cache.get_or_set('brian')
diff --git a/tests/dbshell/test_postgresql_psycopg2.py b/tests/dbshell/test_postgresql_psycopg2.py
index 4c4a1ae25e..755464b3bb 100644
--- a/tests/dbshell/test_postgresql_psycopg2.py
+++ b/tests/dbshell/test_postgresql_psycopg2.py
@@ -3,7 +3,6 @@ import os
from django.db.backends.postgresql.client import DatabaseClient
from django.test import SimpleTestCase, mock
-from django.utils import six
from django.utils.encoding import force_bytes, force_str
@@ -91,16 +90,12 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
encoding = locale.getpreferredencoding()
username = 'rôle'
password = 'sésame'
- try:
- username_str = force_str(username, encoding)
- password_str = force_str(password, encoding)
- pgpass_bytes = force_bytes(
- 'somehost:444:dbname:%s:%s' % (username, password),
- encoding=encoding,
- )
- except UnicodeEncodeError:
- if six.PY2:
- self.skipTest("Your locale can't run this test.")
+ username_str = force_str(username, encoding)
+ password_str = force_str(password, encoding)
+ pgpass_bytes = force_bytes(
+ 'somehost:444:dbname:%s:%s' % (username, password),
+ encoding=encoding,
+ )
self.assertEqual(
self._run_it({
'database': 'dbname',
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py
index 769c06c904..f9cecf96a2 100644
--- a/tests/file_uploads/tests.py
+++ b/tests/file_uploads/tests.py
@@ -15,7 +15,7 @@ from django.http.multipartparser import MultiPartParser, parse_header
from django.test import SimpleTestCase, TestCase, client, override_settings
from django.utils.encoding import force_bytes
from django.utils.http import urlquote
-from django.utils.six import PY2, StringIO
+from django.utils.six import StringIO
from . import uploadhandler
from .models import FileModel
@@ -102,9 +102,7 @@ class FileUploadTests(TestCase):
self._test_base64_upload("Big data" * 68000) # > 512Kb
def test_big_base64_newlines_upload(self):
- self._test_base64_upload(
- # encodestring is a deprecated alias on Python 3
- "Big data" * 68000, encode=base64.encodestring if PY2 else base64.encodebytes)
+ self._test_base64_upload("Big data" * 68000, encode=base64.encodebytes)
def test_unicode_file_name(self):
tdir = sys_tempfile.mkdtemp()
diff --git a/tests/files/tests.py b/tests/files/tests.py
index 276cbed544..a0ff3d4782 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -181,10 +181,7 @@ class ContentFileTestCase(unittest.TestCase):
retrieved content is of the same type.
"""
self.assertIsInstance(ContentFile(b"content").read(), bytes)
- if six.PY3:
- self.assertIsInstance(ContentFile("español").read(), six.text_type)
- else:
- self.assertIsInstance(ContentFile("español").read(), bytes)
+ self.assertIsInstance(ContentFile("español").read(), six.text_type)
class DimensionClosingBug(unittest.TestCase):
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py
index 3667fcbd4c..7ea9e6cc3e 100644
--- a/tests/fixtures_regress/tests.py
+++ b/tests/fixtures_regress/tests.py
@@ -2,10 +2,8 @@
import json
import os
import re
-import unittest
import warnings
-import django
from django.core import management, serializers
from django.core.exceptions import ImproperlyConfigured
from django.core.serializers.base import DeserializationError
@@ -15,9 +13,8 @@ from django.test import (
TestCase, TransactionTestCase, override_settings, skipIfDBFeature,
skipUnlessDBFeature,
)
-from django.utils import six
from django.utils._os import upath
-from django.utils.six import PY3, StringIO
+from django.utils.six import StringIO
from .models import (
Absolute, Animal, Article, Book, Child, Circle1, Circle2, Circle3,
@@ -32,16 +29,6 @@ from .models import (
_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
-def is_ascii(s):
- return all(ord(c) < 128 for c in s)
-
-
-skipIfNonASCIIPath = unittest.skipIf(
- not is_ascii(django.__file__) and six.PY2,
- 'Python 2 crashes when checking non-ASCII exception messages.'
-)
-
-
class TestFixtures(TestCase):
def animal_pre_save_check(self, signal, sender, instance, **kwargs):
@@ -205,7 +192,6 @@ class TestFixtures(TestCase):
verbosity=0,
)
- @skipIfNonASCIIPath
@override_settings(SERIALIZATION_MODULES={'unkn': 'unexistent.path'})
def test_unimportable_serializer(self):
"""
@@ -350,8 +336,8 @@ class TestFixtures(TestCase):
self.assertEqual(
self.pre_save_checks,
[
- ("Count = 42 (<%s 'int'>)" % ('class' if PY3 else 'type'),
- "Weight = 1.2 (<%s 'float'>)" % ('class' if PY3 else 'type'))
+ ("Count = 42 (Request data not supplied
', html) + def test_reporting_of_nested_exceptions(self): + request = self.rf.get('/test_view/') + try: + try: + raise AttributeError('Top level') + except AttributeError as explicit: + try: + raise ValueError('Second exception') from explicit + except ValueError: + raise IndexError('Final exception') + except Exception: + # Custom exception handler, just pass it into ExceptionReporter + exc_type, exc_value, tb = sys.exc_info() + + explicit_exc = 'The above exception ({0}) was the direct cause of the following exception:' + implicit_exc = 'During handling of the above exception ({0}), another exception occurred:' + + reporter = ExceptionReporter(request, exc_type, exc_value, tb) + html = reporter.get_traceback_html() + # Both messages are twice on page -- one rendered as html, + # one as plain text (for pastebin) + self.assertEqual(2, html.count(explicit_exc.format("Top level"))) + self.assertEqual(2, html.count(implicit_exc.format("Second exception"))) + + text = reporter.get_traceback_text() + self.assertIn(explicit_exc.format("Top level"), text) + self.assertIn(implicit_exc.format("Second exception"), text) + def test_request_and_message(self): "A message can be provided in addition to a request" request = self.rf.get('/test_view/') @@ -426,11 +450,10 @@ class ExceptionReporterTests(SimpleTestCase): self.assertEqual(len(html) // 1024 // 128, 0) # still fit in 128Kb self.assertIn('<trimmed %d bytes string>' % (large + repr_of_str_adds,), html) - @skipIf(six.PY2, 'Bug manifests on PY3 only') def test_unfrozen_importlib(self): """ importlib is not a frozen app, but its loader thinks it's frozen which - results in an ImportError on Python 3. Refs #21443. + results in an ImportError. Refs #21443. """ try: request = self.rf.get('/test_view/') @@ -478,10 +501,7 @@ class ExceptionReporterTests(SimpleTestCase): An exception report can be generated for requests with 'items' in request GET, POST, FILES, or COOKIES QueryDicts. """ - if six.PY3: - value = ''Oops'
u'Oops'
'Oops'