diff options
Diffstat (limited to 'tests')
70 files changed, 252 insertions, 292 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index e37e8a4256..868d04196f 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -12,6 +12,7 @@ import subprocess import sys import tempfile import unittest +from io import StringIO import django from django import conf, get_version @@ -27,7 +28,6 @@ from django.test import ( ) from django.utils._os import npath, upath from django.utils.encoding import force_text -from django.utils.six import StringIO custom_templates_dir = os.path.join(os.path.dirname(upath(__file__)), 'custom_templates') diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index b8d35b6d81..ffce2c0f34 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -1,5 +1,6 @@ import os import tempfile +from io import StringIO from wsgiref.util import FileWrapper from django import forms @@ -17,7 +18,6 @@ from django.forms.models import BaseModelFormSet from django.http import HttpResponse, StreamingHttpResponse from django.utils.html import format_html from django.utils.safestring import mark_safe -from django.utils.six import StringIO from .forms import MediaActionForm from .models import ( diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index fb404e5fd2..81b7e1f6a4 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -3,6 +3,7 @@ import json import os import re import unittest +from urllib.parse import parse_qsl, urljoin, urlparse from django.contrib.admin import AdminSite, ModelAdmin from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME @@ -36,7 +37,6 @@ from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_bytes, force_text, iri_to_uri from django.utils.html import escape from django.utils.http import urlencode -from django.utils.six.moves.urllib.parse import parse_qsl, urljoin, urlparse from . import customadmin from .admin import CityAdmin, site, site2 diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py index afbc7c20b2..bc501fc94e 100644 --- a/tests/aggregation_regress/tests.py +++ b/tests/aggregation_regress/tests.py @@ -12,7 +12,6 @@ from django.db.models import ( ) from django.test import TestCase, skipUnlessAnyDBFeature, skipUnlessDBFeature from django.test.utils import Approximate -from django.utils import six from .models import ( Alfa, Author, Book, Bravo, Charlie, Clues, Entries, HardbackBook, ItemTag, @@ -103,7 +102,7 @@ class AggregationTests(TestCase): s3.books.add(cls.b3, cls.b4, cls.b6) def assertObjectAttrs(self, obj, **kwargs): - for attr, value in six.iteritems(kwargs): + for attr, value in kwargs.items(): self.assertEqual(getattr(obj, attr), value) def test_annotation_with_value(self): diff --git a/tests/auth_tests/test_deprecated_views.py b/tests/auth_tests/test_deprecated_views.py index d084f4dcef..d5088b9d8a 100644 --- a/tests/auth_tests/test_deprecated_views.py +++ b/tests/auth_tests/test_deprecated_views.py @@ -1,6 +1,7 @@ import datetime import itertools import re +from urllib.parse import ParseResult, urlparse from django.conf import settings from django.contrib.auth import SESSION_KEY @@ -14,7 +15,6 @@ from django.test import TestCase, override_settings from django.test.utils import ignore_warnings, patch_logger from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_text -from django.utils.six.moves.urllib.parse import ParseResult, urlparse from .models import CustomUser, UUIDUser from .settings import AUTH_TEMPLATES diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 9335b75dba..4fd1563f84 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -1,5 +1,7 @@ +import builtins import sys from datetime import date +from io import StringIO from django.apps import apps from django.contrib.auth import management @@ -13,7 +15,6 @@ from django.core.management import call_command from django.core.management.base import CommandError from django.db import migrations from django.test import TestCase, mock, override_settings -from django.utils import six from django.utils.encoding import force_str from django.utils.translation import ugettext_lazy as _ @@ -49,14 +50,14 @@ def mock_inputs(inputs): return response old_getpass = createsuperuser.getpass - old_input = createsuperuser.input + old_input = builtins.input createsuperuser.getpass = mock_getpass - createsuperuser.input = mock_input + builtins.input = mock_input try: test_func(*args) finally: createsuperuser.getpass = old_getpass - createsuperuser.input = old_input + builtins.input = old_input return wrapped return inner @@ -105,8 +106,8 @@ class ChangepasswordManagementCommandTestCase(TestCase): def setUp(self): self.user = User.objects.create_user(username='joe', password='qwerty') - self.stdout = six.StringIO() - self.stderr = six.StringIO() + self.stdout = StringIO() + self.stderr = StringIO() def tearDown(self): self.stdout.close() @@ -168,7 +169,7 @@ class MultiDBChangepasswordManagementCommandTestCase(TestCase): user = User.objects.db_manager('other').create_user(username='joe', password='qwerty') self.assertTrue(user.check_password('qwerty')) - out = six.StringIO() + out = StringIO() call_command('changepassword', username='joe', database='other', stdout=out) command_output = out.getvalue().strip() @@ -188,7 +189,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): def test_basic_usage(self): "Check the operation of the createsuperuser management command" # We can use the management command to create a superuser - new_io = six.StringIO() + new_io = StringIO() call_command( "createsuperuser", interactive=False, @@ -212,7 +213,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): username_field = User._meta.get_field('username') old_verbose_name = username_field.verbose_name username_field.verbose_name = _('u\u017eivatel') - new_io = six.StringIO() + new_io = StringIO() try: call_command( "createsuperuser", @@ -228,7 +229,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): def test_verbosity_zero(self): # We can suppress output on the management command - new_io = six.StringIO() + new_io = StringIO() call_command( "createsuperuser", interactive=False, @@ -244,7 +245,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): self.assertFalse(u.has_usable_password()) def test_email_in_username(self): - new_io = six.StringIO() + new_io = StringIO() call_command( "createsuperuser", interactive=False, @@ -262,7 +263,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): # We can use the management command to create a superuser # We skip validation because the temporary substitution of the # swappable User model messes with validation. - new_io = six.StringIO() + new_io = StringIO() call_command( "createsuperuser", interactive=False, @@ -284,7 +285,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): # We can use the management command to create a superuser # We skip validation because the temporary substitution of the # swappable User model messes with validation. - new_io = six.StringIO() + new_io = StringIO() with self.assertRaises(CommandError): call_command( "createsuperuser", @@ -306,7 +307,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): 'password': 'nopasswd', }) def createsuperuser(): - new_io = six.StringIO() + new_io = StringIO() call_command( "createsuperuser", interactive=True, @@ -333,7 +334,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): def isatty(self): return False - out = six.StringIO() + out = StringIO() call_command( "createsuperuser", stdin=FakeStdin(), @@ -355,8 +356,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): call_command( command, stdin=sentinel, - stdout=six.StringIO(), - stderr=six.StringIO(), + stdout=StringIO(), + stderr=StringIO(), interactive=False, verbosity=0, username='janet', @@ -367,8 +368,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): command = createsuperuser.Command() call_command( command, - stdout=six.StringIO(), - stderr=six.StringIO(), + stdout=StringIO(), + stderr=StringIO(), interactive=False, verbosity=0, username='joe', @@ -378,7 +379,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): @override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithFK') def test_fields_with_fk(self): - new_io = six.StringIO() + new_io = StringIO() group = Group.objects.create(name='mygroup') email = Email.objects.create(email='mymail@gmail.com') call_command( @@ -408,7 +409,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): @override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithFK') def test_fields_with_fk_interactive(self): - new_io = six.StringIO() + new_io = StringIO() group = Group.objects.create(name='mygroup') email = Email.objects.create(email='mymail@gmail.com') @@ -438,7 +439,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): """ Creation should fail if the password fails validation. """ - new_io = six.StringIO() + new_io = StringIO() # Returns '1234567890' the first two times it is called, then # 'password' subsequently. @@ -472,7 +473,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): """ Creation should fail if the user enters mismatched passwords. """ - new_io = six.StringIO() + new_io = StringIO() # The first two passwords do not match, but the second two do match and # are valid. @@ -505,7 +506,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): """ Creation should fail if the user enters blank passwords. """ - new_io = six.StringIO() + new_io = StringIO() # The first two passwords are empty strings, but the second two are # valid. @@ -542,7 +543,7 @@ class MultiDBCreatesuperuserTestCase(TestCase): """ changepassword --database should operate on the specified DB. """ - new_io = six.StringIO() + new_io = StringIO() call_command( 'createsuperuser', interactive=False, diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py index f250800921..dd87a5bf00 100644 --- a/tests/auth_tests/test_views.py +++ b/tests/auth_tests/test_views.py @@ -3,6 +3,7 @@ import itertools import os import re from importlib import import_module +from urllib.parse import ParseResult, urlparse from django.apps import apps from django.conf import settings @@ -28,7 +29,6 @@ from django.urls import NoReverseMatch, reverse, reverse_lazy from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_text from django.utils.http import urlquote -from django.utils.six.moves.urllib.parse import ParseResult, urlparse from django.utils.translation import LANGUAGE_SESSION_KEY from .client import PasswordResetConfirmClient diff --git a/tests/backends/tests.py b/tests/backends/tests.py index a7939ed8be..89afb20760 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -23,7 +23,6 @@ from django.test import ( SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings, skipIfDBFeature, skipUnlessDBFeature, ) -from django.utils.six.moves import range from .models import ( Article, Item, Object, ObjectReference, Person, Post, RawData, Reporter, diff --git a/tests/base/models.py b/tests/base/models.py index fb91522717..b179878704 100644 --- a/tests/base/models.py +++ b/tests/base/models.py @@ -1,5 +1,4 @@ from django.db import models -from django.utils import six # The models definitions below used to crash. Generating models dynamically @@ -11,5 +10,5 @@ class CustomBaseModel(models.base.ModelBase): pass -class MyModel(six.with_metaclass(CustomBaseModel, models.Model)): - """Model subclass with a custom base using six.with_metaclass.""" +class MyModel(models.Model, metaclass=CustomBaseModel): + """Model subclass with a custom base using metaclass.""" diff --git a/tests/cache/tests.py b/tests/cache/tests.py index caeb8a47df..3bf39e2476 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -3,6 +3,7 @@ import copy import io import os +import pickle import re import shutil import tempfile @@ -33,7 +34,7 @@ from django.test import ( ignore_warnings, mock, override_settings, ) from django.test.signals import setting_changed -from django.utils import six, timezone, translation +from django.utils import timezone, translation from django.utils.cache import ( get_cache_key, learn_cache_key, patch_cache_control, patch_response_headers, patch_vary_headers, @@ -44,11 +45,6 @@ from django.views.decorators.cache import cache_page from .models import Poll, expensive_calculation -try: # Use the same idiom as in cache backends - from django.utils.six.moves import cPickle as pickle -except ImportError: - import pickle - # functions/classes for complex data type tests def f(): @@ -978,7 +974,7 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase): self._perform_cull_test(caches['zero_cull'], 50, 18) def test_second_call_doesnt_crash(self): - out = six.StringIO() + out = io.StringIO() management.call_command('createcachetable', stdout=out) self.assertEqual(out.getvalue(), "Cache table 'test cache table' already exists.\n" * len(settings.CACHES)) @@ -988,7 +984,7 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase): LOCATION='createcachetable_dry_run_mode' )) def test_createcachetable_dry_run_mode(self): - out = six.StringIO() + out = io.StringIO() management.call_command('createcachetable', dry_run=True, stdout=out) output = out.getvalue() self.assertTrue(output.startswith("CREATE TABLE")) @@ -999,7 +995,7 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase): specifying the table name). """ self.drop_table() - out = six.StringIO() + out = io.StringIO() management.call_command( 'createcachetable', 'test cache table', diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index 0e82c10b45..30e1353dc0 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -1,4 +1,5 @@ import sys +from io import StringIO from django.apps import apps from django.core import checks @@ -12,7 +13,6 @@ from django.test.utils import ( isolate_apps, override_settings, override_system_checks, ) from django.utils.encoding import force_text -from django.utils.six import StringIO from .models import SimpleModel, my_check diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py index a46c9f3365..c91c265eaf 100644 --- a/tests/contenttypes_tests/tests.py +++ b/tests/contenttypes_tests/tests.py @@ -390,10 +390,7 @@ class UpdateContentTypesTests(TestCase): # A related object is needed to show that a custom collector with # can_fast_delete=False is needed. ModelWithNullFKToSite.objects.create(post=post) - with mock.patch( - 'django.contrib.contenttypes.management.commands.remove_stale_contenttypes.input', - return_value='yes' - ): + with mock.patch('builtins.input', return_value='yes'): with captured_stdout() as stdout: call_command('remove_stale_contenttypes', verbosity=2, stdout=stdout) self.assertEqual(Post.objects.count(), 0) @@ -409,10 +406,7 @@ class UpdateContentTypesTests(TestCase): interactive mode of remove_stale_contenttypes (the default) should delete stale contenttypes even if there aren't any dependent objects. """ - with mock.patch( - 'django.contrib.contenttypes.management.commands.remove_stale_contenttypes.input', - return_value='yes' - ): + with mock.patch('builtins.input', return_value='yes'): with captured_stdout() as stdout: call_command('remove_stale_contenttypes', verbosity=2) self.assertIn("Deleting stale content type", stdout.getvalue()) diff --git a/tests/db_typecasts/tests.py b/tests/db_typecasts/tests.py index fa9eab164d..56d37c112d 100644 --- a/tests/db_typecasts/tests.py +++ b/tests/db_typecasts/tests.py @@ -4,7 +4,6 @@ import datetime import unittest from django.db.backends import utils as typecasts -from django.utils import six TEST_CASES = { 'typecast_date': ( @@ -53,7 +52,7 @@ TEST_CASES = { class DBTypeCasts(unittest.TestCase): def test_typeCasts(self): - for k, v in six.iteritems(TEST_CASES): + for k, v in TEST_CASES.items(): for inpt, expected in v: got = getattr(typecasts, k)(inpt) self.assertEqual( diff --git a/tests/delete/tests.py b/tests/delete/tests.py index 640dfabf4b..5abae7622e 100644 --- a/tests/delete/tests.py +++ b/tests/delete/tests.py @@ -3,7 +3,6 @@ from math import ceil from django.db import IntegrityError, connection, models from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature -from django.utils.six.moves import range from .models import ( MR, A, Avatar, Base, Child, HiddenUser, HiddenUserProfile, M, M2MFrom, diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py index 34056b663b..5c2361f7a0 100644 --- a/tests/deprecation/tests.py +++ b/tests/deprecation/tests.py @@ -2,7 +2,6 @@ import warnings from django.test import SimpleTestCase from django.test.utils import reset_warning_registry -from django.utils import six from django.utils.deprecation import ( DeprecationInstanceCheck, RemovedInNextVersionWarning, RenameMethodsBase, ) @@ -29,7 +28,7 @@ class RenameMethodsTests(SimpleTestCase): with warnings.catch_warnings(record=True) as recorded: warnings.simplefilter('always') - class Manager(six.with_metaclass(RenameManagerMethods)): + class Manager(metaclass=RenameManagerMethods): def old(self): pass self.assertEqual(len(recorded), 1) @@ -43,7 +42,7 @@ class RenameMethodsTests(SimpleTestCase): with warnings.catch_warnings(record=True) as recorded: warnings.simplefilter('ignore') - class Manager(six.with_metaclass(RenameManagerMethods)): + class Manager(metaclass=RenameManagerMethods): def new(self): pass warnings.simplefilter('always') @@ -62,7 +61,7 @@ class RenameMethodsTests(SimpleTestCase): with warnings.catch_warnings(record=True) as recorded: warnings.simplefilter('ignore') - class Manager(six.with_metaclass(RenameManagerMethods)): + class Manager(metaclass=RenameManagerMethods): def old(self): pass warnings.simplefilter('always') @@ -82,7 +81,7 @@ class RenameMethodsTests(SimpleTestCase): with warnings.catch_warnings(record=True) as recorded: warnings.simplefilter('ignore') - class Renamed(six.with_metaclass(RenameManagerMethods)): + class Renamed(metaclass=RenameManagerMethods): def new(self): pass @@ -112,7 +111,7 @@ class RenameMethodsTests(SimpleTestCase): with warnings.catch_warnings(record=True) as recorded: warnings.simplefilter('ignore') - class Deprecated(six.with_metaclass(RenameManagerMethods)): + class Deprecated(metaclass=RenameManagerMethods): def old(self): pass @@ -137,7 +136,7 @@ class RenameMethodsTests(SimpleTestCase): with warnings.catch_warnings(record=True) as recorded: warnings.simplefilter('ignore') - class Renamed(six.with_metaclass(RenameManagerMethods)): + class Renamed(metaclass=RenameManagerMethods): def new(self): pass @@ -168,7 +167,7 @@ class RenameMethodsTests(SimpleTestCase): class DeprecationInstanceCheckTest(SimpleTestCase): def test_warning(self): - class Manager(six.with_metaclass(DeprecationInstanceCheck)): + class Manager(metaclass=DeprecationInstanceCheck): alternative = 'fake.path.Foo' deprecation_warning = RemovedInNextVersionWarning diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index d02b6e2dbc..5aee127c8c 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -7,6 +7,8 @@ import threading import time import unittest from datetime import datetime, timedelta +from io import StringIO +from urllib.request import urlopen from django.core.cache import cache from django.core.exceptions import SuspiciousFileOperation, SuspiciousOperation @@ -21,9 +23,8 @@ from django.test import ( ) from django.test.utils import requires_tz_support from django.urls import NoReverseMatch, reverse_lazy -from django.utils import six, timezone +from django.utils import timezone from django.utils._os import upath -from django.utils.six.moves.urllib.request import urlopen from .models import Storage, temp_storage, temp_storage_location @@ -301,7 +302,7 @@ class FileStorageTests(SimpleTestCase): self.assertFalse(file.closed) self.assertFalse(file.file.closed) - file = InMemoryUploadedFile(six.StringIO('1'), '', 'test', 'text/plain', 1, 'utf8') + file = InMemoryUploadedFile(StringIO('1'), '', 'test', 'text/plain', 1, 'utf8') with file: self.assertFalse(file.closed) self.storage.save('path/to/test.file', file) @@ -578,7 +579,7 @@ class DiscardingFalseContentStorageTests(FileStorageTests): When Storage.save() wraps a file-like object in File, it should include the name argument so that bool(file) evaluates to True (#26495). """ - output = six.StringIO('content') + output = StringIO('content') self.storage.save('tests/stringio', output) self.assertTrue(self.storage.exists('tests/stringio')) @@ -788,7 +789,7 @@ class FileFieldStorageTests(TestCase): def test_stringio(self): # Test passing StringIO instance as content argument to save - output = six.StringIO() + output = StringIO() output.write('content') output.seek(0) diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index f9cecf96a2..c7315ae142 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -7,7 +7,7 @@ import shutil import sys import tempfile as sys_tempfile import unittest -from io import BytesIO +from io import BytesIO, StringIO from django.core.files import temp as tempfile from django.core.files.uploadedfile import SimpleUploadedFile @@ -15,7 +15,6 @@ 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 StringIO from . import uploadhandler from .models import FileModel diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index df5067e223..51d8eef51b 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -3,6 +3,7 @@ import sys import tempfile import unittest import warnings +from io import StringIO from django.apps import apps from django.contrib.sites.models import Site @@ -15,7 +16,6 @@ from django.db import IntegrityError, connection from django.test import ( TestCase, TransactionTestCase, mock, skipUnlessDBFeature, ) -from django.utils import six from django.utils.encoding import force_text from .models import ( @@ -52,7 +52,7 @@ class DumpDataAssertMixin(object): def _dumpdata_assert(self, args, output, format='json', filename=None, natural_foreign_keys=False, natural_primary_keys=False, use_base_manager=False, exclude_list=[], primary_keys=''): - new_io = six.StringIO() + new_io = StringIO() if filename: filename = os.path.join(tempfile.gettempdir(), filename) management.call_command('dumpdata', *args, **{'format': format, @@ -445,7 +445,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): def test_dumpdata_with_uuid_pks(self): m1 = PrimaryKeyUUIDModel.objects.create() m2 = PrimaryKeyUUIDModel.objects.create() - output = six.StringIO() + output = StringIO() management.call_command( 'dumpdata', 'fixtures.PrimaryKeyUUIDModel', '--pks', ', '.join([str(m1.id), str(m2.id)]), stdout=output, @@ -471,7 +471,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): stdout is a tty, and verbosity > 0. """ management.call_command('loaddata', 'fixture1.json', verbosity=0) - new_io = six.StringIO() + new_io = StringIO() new_io.isatty = lambda: True with NamedTemporaryFile() as file: options = { @@ -485,7 +485,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): # Test no progress bar when verbosity = 0 options['verbosity'] = 0 - new_io = six.StringIO() + new_io = StringIO() new_io.isatty = lambda: True options.update({'stdout': new_io, 'stderr': new_io}) management.call_command('dumpdata', 'fixtures', **options) @@ -583,7 +583,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): ]) def test_loaddata_verbosity_three(self): - output = six.StringIO() + output = StringIO() management.call_command('loaddata', 'fixture1.json', verbosity=3, stdout=output, stderr=output) command_output = force_text(output.getvalue()) self.assertIn( @@ -689,7 +689,7 @@ class NonExistentFixtureTests(TestCase): """ def test_loaddata_not_existent_fixture_file(self): - stdout_output = six.StringIO() + stdout_output = StringIO() with self.assertRaisesMessage(CommandError, "No fixture named 'this_fixture_doesnt_exist' found."): management.call_command('loaddata', 'this_fixture_doesnt_exist', stdout=stdout_output) diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py index 7ea9e6cc3e..a3ac7f5977 100644 --- a/tests/fixtures_regress/tests.py +++ b/tests/fixtures_regress/tests.py @@ -3,6 +3,7 @@ import json import os import re import warnings +from io import StringIO from django.core import management, serializers from django.core.exceptions import ImproperlyConfigured @@ -14,7 +15,6 @@ from django.test import ( skipUnlessDBFeature, ) from django.utils._os import upath -from django.utils.six import StringIO from .models import ( Absolute, Animal, Article, Book, Child, Circle1, Circle2, Circle3, diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py index bc8219772c..4498ce7111 100644 --- a/tests/gis_tests/gdal_tests/test_geom.py +++ b/tests/gis_tests/gdal_tests/test_geom.py @@ -1,19 +1,13 @@ import json +import pickle import unittest from binascii import b2a_hex from unittest import skipUnless from django.contrib.gis.gdal import HAS_GDAL -from django.utils.six.moves import range from ..test_data import TestDataMixin -try: - from django.utils.six.moves import cPickle as pickle -except ImportError: - import pickle - - if HAS_GDAL: from django.contrib.gis.gdal import ( CoordTransform, GDALException, OGRGeometry, OGRGeomType, OGRIndexError, diff --git a/tests/gis_tests/gdal_tests/test_raster.py b/tests/gis_tests/gdal_tests/test_raster.py index 8649e9f231..1a2753c717 100644 --- a/tests/gis_tests/gdal_tests/test_raster.py +++ b/tests/gis_tests/gdal_tests/test_raster.py @@ -49,7 +49,6 @@ from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.gdal.error import GDALException from django.contrib.gis.shortcuts import numpy from django.test import SimpleTestCase -from django.utils import six from django.utils._os import upath from ..data.rasters.textrasters import JSON_RASTER @@ -505,7 +504,7 @@ class GDALBandTests(SimpleTestCase): self.assertEqual(result, block) # Set data from memoryview - bandmem.data(six.memoryview(packed_block), (1, 1), (2, 2)) + bandmem.data(memoryview(packed_block), (1, 1), (2, 2)) result = bandmem.data(offset=(1, 1), size=(2, 2)) if numpy: numpy.testing.assert_equal(result, numpy.array(block).reshape(2, 2)) diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py index 4324364c0d..bfb84c6800 100644 --- a/tests/gis_tests/geoapp/tests.py +++ b/tests/gis_tests/geoapp/tests.py @@ -1,4 +1,5 @@ import tempfile +from io import StringIO from django.contrib.gis import gdal from django.contrib.gis.db.models import Extent, MakeLine, Union, functions @@ -9,7 +10,6 @@ from django.contrib.gis.geos import ( from django.core.management import call_command from django.db import connection from django.test import TestCase, skipUnlessDBFeature -from django.utils import six from ..utils import no_oracle, oracle, postgis, skipUnlessGISLookup, spatialite from .models import ( @@ -184,7 +184,7 @@ class GeoModelTest(TestCase): """ Test a dumpdata/loaddata cycle with geographic data. """ - out = six.StringIO() + out = StringIO() original_data = list(City.objects.all().order_by('name')) call_command('dumpdata', 'geoapp.City', stdout=out) result = out.getvalue() diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 7877e1f2d6..f7024e790e 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -1,5 +1,6 @@ import ctypes import json +import pickle import random from binascii import a2b_hex, b2a_hex from io import BytesIO @@ -18,7 +19,6 @@ from django.template import Context from django.template.engine import Engine from django.test import SimpleTestCase, mock from django.utils.encoding import force_bytes -from django.utils.six.moves import range from ..test_data import TestDataMixin @@ -1100,10 +1100,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin): def test_pickle(self): "Testing pickling and unpickling support." - # Using both pickle and cPickle -- just 'cause. - from django.utils.six.moves import cPickle - import pickle - # Creating a list of test geometries for pickling, # and setting the SRID on some of them. def get_geoms(lst, srid=None): @@ -1114,11 +1110,10 @@ class GEOSTest(SimpleTestCase, TestDataMixin): tgeoms.extend(get_geoms(self.geometries.multipolygons, 3857)) for geom in tgeoms: - s1, s2 = cPickle.dumps(geom), pickle.dumps(geom) - g1, g2 = cPickle.loads(s1), pickle.loads(s2) - for tmpg in (g1, g2): - self.assertEqual(geom, tmpg) - self.assertEqual(geom.srid, tmpg.srid) + s1 = pickle.dumps(geom) + g1 = pickle.loads(s1) + self.assertEqual(geom, g1) + self.assertEqual(geom.srid, g1.srid) def test_prepared(self): "Testing PreparedGeometry support." diff --git a/tests/gis_tests/inspectapp/tests.py b/tests/gis_tests/inspectapp/tests.py index b451603e7c..43cf2c2d66 100644 --- a/tests/gis_tests/inspectapp/tests.py +++ b/tests/gis_tests/inspectapp/tests.py @@ -1,12 +1,12 @@ import os import re +from io import StringIO from django.contrib.gis.gdal import HAS_GDAL from django.core.management import call_command from django.db import connection, connections from django.test import TestCase, skipUnlessDBFeature from django.test.utils import modify_settings -from django.utils.six import StringIO from ..test_data import TEST_DATA from ..utils import postgis diff --git a/tests/gis_tests/test_data.py b/tests/gis_tests/test_data.py index 7092bd27b1..9e31b5a599 100644 --- a/tests/gis_tests/test_data.py +++ b/tests/gis_tests/test_data.py @@ -5,7 +5,6 @@ for the GEOS and GDAL tests. import json import os -from django.utils import six from django.utils._os import upath from django.utils.functional import cached_property @@ -22,7 +21,7 @@ def tuplize(seq): def strconvert(d): "Converts all keys in dictionary to str type." - return {str(k): v for k, v in six.iteritems(d)} + return {str(k): v for k, v in d.items()} def get_ds_file(name, ext): diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index b8d359de41..a4ea614175 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -16,7 +16,6 @@ from django.http import ( StreamingHttpResponse, parse_cookie, ) from django.test import SimpleTestCase -from django.utils import six from django.utils._os import upath from django.utils.encoding import force_str from django.utils.functional import lazystr @@ -56,10 +55,10 @@ class QueryDictTests(SimpleTestCase): q = QueryDict() self.assertEqual(q.getlist('foo'), []) self.assertNotIn('foo', q) - self.assertEqual(list(six.iteritems(q)), []) - self.assertEqual(list(six.iterlists(q)), []) - self.assertEqual(list(six.iterkeys(q)), []) - self.assertEqual(list(six.itervalues(q)), []) + self.assertEqual(list(q.items()), []) + self.assertEqual(list(q.lists()), []) + self.assertEqual(list(q.keys()), []) + self.assertEqual(list(q.values()), []) self.assertEqual(len(q), 0) self.assertEqual(q.urlencode(), '') @@ -86,10 +85,10 @@ class QueryDictTests(SimpleTestCase): self.assertIn('foo', q) self.assertNotIn('bar', q) - self.assertEqual(list(six.iteritems(q)), [('foo', 'bar')]) - self.assertEqual(list(six.iterlists(q)), [('foo', ['bar'])]) - self.assertEqual(list(six.iterkeys(q)), ['foo']) - self.assertEqual(list(six.itervalues(q)), ['bar']) + self.assertEqual(list(q.items()), [('foo', 'bar')]) + self.assertEqual(list(q.lists()), [('foo', ['bar'])]) + self.assertEqual(list(q.keys()), ['foo']) + self.assertEqual(list(q.values()), ['bar']) self.assertEqual(len(q), 1) with self.assertRaises(AttributeError): @@ -146,14 +145,10 @@ class QueryDictTests(SimpleTestCase): self.assertEqual(q['foo'], 'another') self.assertIn('foo', q) - self.assertListEqual(sorted(six.iteritems(q)), - [('foo', 'another'), ('name', 'john')]) - self.assertListEqual(sorted(six.iterlists(q)), - [('foo', ['bar', 'baz', 'another']), ('name', ['john'])]) - self.assertListEqual(sorted(six.iterkeys(q)), - ['foo', 'name']) - self.assertListEqual(sorted(six.itervalues(q)), - ['another', 'john']) + self.assertListEqual(sorted(q.items()), [('foo', 'another'), ('name', 'john')]) + self.assertListEqual(sorted(q.lists()), [('foo', ['bar', 'baz', 'another']), ('name', ['john'])]) + self.assertListEqual(sorted(q.keys()), ['foo', 'name']) + self.assertListEqual(sorted(q.values()), ['another', 'john']) q.update({'foo': 'hello'}) self.assertEqual(q['foo'], 'hello') @@ -193,10 +188,10 @@ class QueryDictTests(SimpleTestCase): self.assertIn('vote', q) self.assertNotIn('foo', q) - self.assertEqual(list(six.iteritems(q)), [('vote', 'no')]) - self.assertEqual(list(six.iterlists(q)), [('vote', ['yes', 'no'])]) - self.assertEqual(list(six.iterkeys(q)), ['vote']) - self.assertEqual(list(six.itervalues(q)), ['no']) + self.assertEqual(list(q.items()), [('vote', 'no')]) + self.assertEqual(list(q.lists()), [('vote', ['yes', 'no'])]) + self.assertEqual(list(q.keys()), ['vote']) + self.assertEqual(list(q.values()), ['no']) self.assertEqual(len(q), 1) with self.assertRaises(AttributeError): @@ -234,11 +229,11 @@ class QueryDictTests(SimpleTestCase): """#13572 - QueryDict with a non-default encoding""" q = QueryDict(str('cur=%A4'), encoding='iso-8859-15') self.assertEqual(q.encoding, 'iso-8859-15') - self.assertEqual(list(six.iteritems(q)), [('cur', '€')]) + self.assertEqual(list(q.items()), [('cur', '€')]) self.assertEqual(q.urlencode(), 'cur=%A4') q = q.copy() self.assertEqual(q.encoding, 'iso-8859-15') - self.assertEqual(list(six.iteritems(q)), [('cur', '€')]) + self.assertEqual(list(q.items()), [('cur', '€')]) self.assertEqual(q.urlencode(), 'cur=%A4') self.assertEqual(copy.copy(q).encoding, 'iso-8859-15') self.assertEqual(copy.deepcopy(q).encoding, 'iso-8859-15') diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py index 3f3bf773bf..159b6d91ec 100644 --- a/tests/i18n/test_compilation.py +++ b/tests/i18n/test_compilation.py @@ -2,6 +2,7 @@ import gettext as gettext_module import os import stat import unittest +from io import StringIO from subprocess import Popen from django.core.management import ( @@ -14,7 +15,6 @@ from django.test import SimpleTestCase, mock, override_settings from django.test.utils import captured_stderr, captured_stdout from django.utils import translation from django.utils.encoding import force_text -from django.utils.six import StringIO from django.utils.translation import ugettext from .utils import RunInTmpDirMixin, copytree diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index b8342865a9..aaa2a4e8b5 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -4,6 +4,7 @@ import re import shutil import time import warnings +from io import StringIO from unittest import skipUnless from admin_scripts.tests import AdminScriptTestCase @@ -17,7 +18,6 @@ from django.core.management.utils import find_command from django.test import SimpleTestCase, mock, override_settings from django.test.utils import captured_stderr, captured_stdout from django.utils.encoding import force_text -from django.utils.six import StringIO from django.utils.translation import TranslatorCommentWarning from .utils import POFileAssertionMixin, RunInTmpDirMixin, copytree diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 8f17735929..ef26233342 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -1,11 +1,11 @@ import re +from io import StringIO from unittest import skipUnless from django.core.management import call_command from django.db import connection from django.test import TestCase, mock, skipUnlessDBFeature from django.utils.encoding import force_text -from django.utils.six import StringIO from .models import ColumnTypes diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 134cc71808..a91bcd66bf 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -1,5 +1,6 @@ import logging from contextlib import contextmanager +from io import StringIO from admin_scripts.tests import AdminScriptTestCase @@ -10,7 +11,6 @@ from django.core.management import color from django.db import connection from django.test import RequestFactory, SimpleTestCase, override_settings from django.test.utils import LoggingCaptureMixin, patch_logger -from django.utils import six from django.utils.log import ( DEFAULT_LOGGING, AdminEmailHandler, CallbackFilter, RequireDebugFalse, RequireDebugTrue, ServerFormatter, @@ -513,7 +513,7 @@ class LogFormattersTests(SimpleTestCase): @contextmanager def patch_django_server_logger(): old_stream = logger.handlers[0].stream - new_stream = six.StringIO() + new_stream = StringIO() logger.handlers[0].stream = new_stream yield new_stream logger.handlers[0].stream = old_stream diff --git a/tests/m2m_through_regress/tests.py b/tests/m2m_through_regress/tests.py index a1739f2960..64be4252bd 100644 --- a/tests/m2m_through_regress/tests.py +++ b/tests/m2m_through_regress/tests.py @@ -1,7 +1,8 @@ +from io import StringIO + from django.contrib.auth.models import User from django.core import management from django.test import TestCase -from django.utils.six import StringIO from .models import ( Car, CarDriver, Driver, Group, Membership, Person, UserMembership, diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 7c2cd8342a..77ea87fe7d 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -12,6 +12,7 @@ from email import message_from_binary_file, message_from_bytes from email.header import Header from email.mime.text import MIMEText from email.utils import parseaddr +from io import StringIO from smtplib import SMTP, SMTPAuthenticationError, SMTPException from ssl import SSLError @@ -26,7 +27,6 @@ from django.test import SimpleTestCase, override_settings from django.test.utils import requires_tz_support from django.utils._os import upath from django.utils.encoding import force_bytes, force_text -from django.utils.six import StringIO from django.utils.translation import ugettext_lazy diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index 3c0d3d81ea..8749a9ee50 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -1,7 +1,9 @@ import gzip import random import re +import struct from io import BytesIO +from urllib.parse import quote from django.conf import settings from django.core import mail @@ -19,11 +21,10 @@ from django.middleware.http import ConditionalGetMiddleware from django.test import ( RequestFactory, SimpleTestCase, ignore_warnings, override_settings, ) -from django.utils import six from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_str -from django.utils.six.moves import range -from django.utils.six.moves.urllib.parse import quote + +int2byte = struct.Struct(">B").pack @override_settings(ROOT_URLCONF='middleware.urls') @@ -732,7 +733,7 @@ class GZipMiddlewareTest(SimpleTestCase): """ short_string = b"This string is too short to be worth compressing." compressible_string = b'a' * 500 - incompressible_string = b''.join(six.int2byte(random.randint(0, 255)) for _ in range(500)) + incompressible_string = b''.join(int2byte(random.randint(0, 255)) for _ in range(500)) sequence = [b'a' * 500, b'b' * 200, b'a' * 300] sequence_unicode = ['a' * 500, 'é' * 200, 'a' * 300] diff --git a/tests/migrate_signals/tests.py b/tests/migrate_signals/tests.py index 84b6608f46..97f449e805 100644 --- a/tests/migrate_signals/tests.py +++ b/tests/migrate_signals/tests.py @@ -1,9 +1,10 @@ +from io import StringIO + from django.apps import apps from django.core import management from django.db import migrations from django.db.models import signals from django.test import TransactionTestCase, override_settings -from django.utils import six APP_CONFIG = apps.get_app_config('migrate_signals') SIGNAL_ARGS = ['app_config', 'verbosity', 'interactive', 'using', 'plan', 'apps'] @@ -70,7 +71,7 @@ class MigrateSignalTests(TransactionTestCase): post_migrate_receiver = Receiver(signals.post_migrate) management.call_command( 'migrate', database=MIGRATE_DATABASE, verbosity=MIGRATE_VERBOSITY, - interactive=MIGRATE_INTERACTIVE, stdout=six.StringIO(), + interactive=MIGRATE_INTERACTIVE, stdout=StringIO(), ) for receiver in [pre_migrate_receiver, post_migrate_receiver]: @@ -91,7 +92,7 @@ class MigrateSignalTests(TransactionTestCase): """ pre_migrate_receiver = Receiver(signals.pre_migrate) post_migrate_receiver = Receiver(signals.post_migrate) - stdout = six.StringIO() + stdout = StringIO() management.call_command( 'migrate', database=MIGRATE_DATABASE, verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE, stdout=stdout, diff --git a/tests/migrations/models.py b/tests/migrations/models.py index dea320c033..9a34edf349 100644 --- a/tests/migrations/models.py +++ b/tests/migrations/models.py @@ -1,13 +1,12 @@ from django.apps.registry import Apps from django.db import models -from django.utils import six class CustomModelBase(models.base.ModelBase): pass -class ModelWithCustomBase(six.with_metaclass(CustomModelBase, models.Model)): +class ModelWithCustomBase(models.Model, metaclass=CustomModelBase): pass diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index ca6b42044f..e6de83212e 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -15,7 +15,6 @@ from django.db.migrations.exceptions import ( ) from django.db.migrations.recorder import MigrationRecorder from django.test import mock, override_settings -from django.utils import six from django.utils.encoding import force_text from .models import UnicodeModel, UnserializableModel @@ -63,7 +62,7 @@ class MigrateTests(MigrationTestBase): 'migrations.migrations_test_apps.migrated_app', ]) def test_migrate_with_system_checks(self): - out = six.StringIO() + out = io.StringIO() call_command('migrate', skip_checks=False, no_color=True, stdout=out) self.assertIn('Apply all migrations: migrated_app', out.getvalue()) @@ -125,7 +124,7 @@ class MigrateTests(MigrationTestBase): with self.assertRaises(DatabaseError): call_command("migrate", "migrations", "0001", verbosity=0) # Run initial migration with an explicit --fake-initial - out = six.StringIO() + out = io.StringIO() with mock.patch('django.core.management.color.supports_color', lambda *args: False): call_command("migrate", "migrations", "0001", fake_initial=True, stdout=out, verbosity=1) call_command("migrate", "migrations", "0001", fake_initial=True, verbosity=0, database="other") @@ -177,7 +176,7 @@ class MigrateTests(MigrationTestBase): """ call_command("migrate", "migrations", "0002", verbosity=0) call_command("migrate", "migrations", "zero", fake=True, verbosity=0) - out = six.StringIO() + out = io.StringIO() with mock.patch('django.core.management.color.supports_color', lambda *args: False): call_command("migrate", "migrations", "0002", fake_initial=True, stdout=out, verbosity=1) value = out.getvalue().lower() @@ -202,7 +201,7 @@ class MigrateTests(MigrationTestBase): showmigrations --list displays migrations and whether or not they're applied. """ - out = six.StringIO() + out = io.StringIO() with mock.patch('django.core.management.color.supports_color', lambda *args: True): call_command("showmigrations", format='list', stdout=out, verbosity=0, no_color=False) self.assertEqual( @@ -214,7 +213,7 @@ class MigrateTests(MigrationTestBase): call_command("migrate", "migrations", "0001", verbosity=0) - out = six.StringIO() + out = io.StringIO() # Giving the explicit app_label tests for selective `show_list` in the command call_command("showmigrations", "migrations", format='list', stdout=out, verbosity=0, no_color=True) self.assertEqual( @@ -231,7 +230,7 @@ class MigrateTests(MigrationTestBase): """ Tests --plan output of showmigrations command """ - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out) self.assertEqual( "[ ] migrations.0001_initial\n" @@ -240,7 +239,7 @@ class MigrateTests(MigrationTestBase): out.getvalue().lower() ) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out, verbosity=2) self.assertEqual( "[ ] migrations.0001_initial\n" @@ -250,7 +249,7 @@ class MigrateTests(MigrationTestBase): ) call_command("migrate", "migrations", "0003", verbosity=0) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out) self.assertEqual( "[x] migrations.0001_initial\n" @@ -259,7 +258,7 @@ class MigrateTests(MigrationTestBase): out.getvalue().lower() ) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out, verbosity=2) self.assertEqual( "[x] migrations.0001_initial\n" @@ -276,11 +275,11 @@ class MigrateTests(MigrationTestBase): """ Tests --plan output of showmigrations command without migrations """ - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out) self.assertEqual("", out.getvalue().lower()) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out, verbosity=2) self.assertEqual("", out.getvalue().lower()) @@ -289,7 +288,7 @@ class MigrateTests(MigrationTestBase): """ Tests --plan output of showmigrations command with squashed migrations. """ - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out) self.assertEqual( "[ ] migrations.1_auto\n" @@ -300,7 +299,7 @@ class MigrateTests(MigrationTestBase): out.getvalue().lower() ) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out, verbosity=2) self.assertEqual( "[ ] migrations.1_auto\n" @@ -313,7 +312,7 @@ class MigrateTests(MigrationTestBase): call_command("migrate", "migrations", "3_squashed_5", verbosity=0) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out) self.assertEqual( "[x] migrations.1_auto\n" @@ -324,7 +323,7 @@ class MigrateTests(MigrationTestBase): out.getvalue().lower() ) - out = six.StringIO() + out = io.StringIO() call_command("showmigrations", format='plan', stdout=out, verbosity=2) self.assertEqual( "[x] migrations.1_auto\n" @@ -345,7 +344,7 @@ class MigrateTests(MigrationTestBase): `showmigrations --plan app_label` output with a single app_label. """ # Single app with no dependencies on other apps. - out = six.StringIO() + out = io.StringIO() call_command('showmigrations', 'mutate_state_b', format='plan', stdout=out) self.assertEqual( '[ ] mutate_state_b.0001_initial\n' @@ -353,7 +352,7 @@ class MigrateTests(MigrationTestBase): out.getvalue() ) # Single app with dependencies. - out = six.StringIO() + out = io.StringIO() call_command('showmigrations', 'author_app', format='plan', stdout=out) self.assertEqual( '[ ] author_app.0001_initial\n' @@ -363,7 +362,7 @@ class MigrateTests(MigrationTestBase): ) # Some migrations already applied. call_command('migrate', 'author_app', '0001', verbosity=0) - out = six.StringIO() + out = io.StringIO() call_command('showmigrations', 'author_app', format='plan', stdout=out) self.assertEqual( '[X] author_app.0001_initial\n' @@ -385,7 +384,7 @@ class MigrateTests(MigrationTestBase): """ # Multiple apps: author_app depends on book_app; mutate_state_b doesn't # depend on other apps. - out = six.StringIO() + out = io.StringIO() call_command('showmigrations', 'mutate_state_b', 'author_app', format='plan', stdout=out) self.assertEqual( '[ ] author_app.0001_initial\n' @@ -397,7 +396,7 @@ class MigrateTests(MigrationTestBase): ) # Multiple apps: args order shouldn't matter (the same result is # expected as above). - out = six.StringIO() + out = io.StringIO() call_command('showmigrations', 'author_app', 'mutate_state_b', format='plan', stdout=out) self.assertEqual( '[ ] author_app.0001_initial\n' @@ -431,7 +430,7 @@ class MigrateTests(MigrationTestBase): """ sqlmigrate outputs forward looking SQL. """ - out = six.StringIO() + out = io.StringIO() call_command("sqlmigrate", "migrations", "0001", stdout=out) output = out.getvalue().lower() @@ -472,7 +471,7 @@ class MigrateTests(MigrationTestBase): # Cannot generate the reverse SQL unless we've applied the migration. call_command("migrate", "migrations", verbosity=0) - out = six.StringIO() + out = io.StringIO() call_command("sqlmigrate", "migrations", "0001", stdout=out, backwards=True) output = out.getvalue().lower() @@ -514,7 +513,7 @@ class MigrateTests(MigrationTestBase): """ Transaction wrappers aren't shown for non-atomic migrations. """ - out = six.StringIO() + out = io.StringIO() call_command("sqlmigrate", "migrations", "0001", stdout=out) output = out.getvalue().lower() queries = [q.strip() for q in output.splitlines()] @@ -541,7 +540,7 @@ class MigrateTests(MigrationTestBase): "B" was not included in the ProjectState that is used to detect soft-applied migrations (#22823). """ - call_command("migrate", "migrated_unapplied_app", stdout=six.StringIO()) + call_command("migrate", "migrated_unapplied_app", stdout=io.StringIO()) # unmigrated_app.SillyModel has a foreign key to 'migrations.Tribble', # but that model is only defined in a migration, so the global app @@ -570,7 +569,7 @@ class MigrateTests(MigrationTestBase): replaced migrations as run. """ recorder = MigrationRecorder(connection) - out = six.StringIO() + out = io.StringIO() call_command("migrate", "migrations", verbosity=0) call_command("showmigrations", "migrations", stdout=out, no_color=True) self.assertEqual( @@ -594,7 +593,7 @@ class MigrateTests(MigrationTestBase): recorder = MigrationRecorder(connection) recorder.record_applied("migrations", "0001_initial") recorder.record_applied("migrations", "0002_second") - out = six.StringIO() + out = io.StringIO() call_command("migrate", "migrations", verbosity=0) call_command("showmigrations", "migrations", stdout=out, no_color=True) self.assertEqual( @@ -683,7 +682,7 @@ class MakeMigrationsTests(MigrationTestBase): empty_connections = ConnectionHandler({'default': {}}) with mock.patch('django.core.management.commands.makemigrations.connections', new=empty_connections): # with no apps - out = six.StringIO() + out = io.StringIO() call_command('makemigrations', stdout=out) self.assertIn('No changes detected', out.getvalue()) # with an app @@ -767,7 +766,7 @@ class MakeMigrationsTests(MigrationTestBase): """ makemigrations exits if in merge mode with no conflicts. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations"): call_command("makemigrations", merge=True, stdout=out) self.assertIn("No conflicts detected to merge.", out.getvalue()) @@ -776,7 +775,7 @@ class MakeMigrationsTests(MigrationTestBase): """ makemigrations exits if a non-existent app is specified. """ - err = six.StringIO() + err = io.StringIO() with self.assertRaises(SystemExit): call_command("makemigrations", "this_app_does_not_exist", stderr=err) self.assertIn("'this_app_does_not_exist' could not be found.", err.getvalue()) @@ -824,7 +823,7 @@ class MakeMigrationsTests(MigrationTestBase): """ makemigrations exits when there are no changes and no apps are specified. """ - out = six.StringIO() + out = io.StringIO() call_command("makemigrations", stdout=out) self.assertIn("No changes detected", out.getvalue()) @@ -832,7 +831,7 @@ class MakeMigrationsTests(MigrationTestBase): """ makemigrations exits when there are no changes to an app. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_no_changes"): call_command("makemigrations", "migrations", stdout=out) self.assertIn("No changes detected in app 'migrations'", out.getvalue()) @@ -842,7 +841,7 @@ class MakeMigrationsTests(MigrationTestBase): makemigrations should detect initial is needed on empty migration modules if no app provided. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_empty"): call_command("makemigrations", stdout=out) self.assertIn("0001_initial.py", out.getvalue()) @@ -851,7 +850,7 @@ class MakeMigrationsTests(MigrationTestBase): """ makemigrations announces the migration at the default verbosity level. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(): call_command("makemigrations", "migrations", stdout=out) self.assertIn("Migrations for 'migrations'", out.getvalue()) @@ -873,7 +872,7 @@ class MakeMigrationsTests(MigrationTestBase): makemigrations enters and exits interactive mode properly. """ # Monkeypatch interactive questioner to auto reject - with mock.patch('django.db.migrations.questioner.input', mock.Mock(return_value='N')): + with mock.patch('builtins.input', mock.Mock(return_value='N')): with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command("makemigrations", "migrations", name="merge", merge=True, interactive=True, verbosity=0) merge_file = os.path.join(migration_dir, '0003_merge.py') @@ -884,8 +883,8 @@ class MakeMigrationsTests(MigrationTestBase): makemigrations enters interactive mode and merges properly. """ # Monkeypatch interactive questioner to auto accept - with mock.patch('django.db.migrations.questioner.input', mock.Mock(return_value='y')): - out = six.StringIO() + with mock.patch('builtins.input', mock.Mock(return_value='y')): + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command("makemigrations", "migrations", name="merge", merge=True, interactive=True, stdout=out) merge_file = os.path.join(migration_dir, '0003_merge.py') @@ -895,8 +894,8 @@ class MakeMigrationsTests(MigrationTestBase): @mock.patch('django.db.migrations.utils.datetime') def test_makemigrations_default_merge_name(self, mock_datetime): mock_datetime.datetime.now.return_value = datetime.datetime(2016, 1, 2, 3, 4) - with mock.patch('django.db.migrations.questioner.input', mock.Mock(return_value='y')): - out = six.StringIO() + with mock.patch('builtins.input', mock.Mock(return_value='y')): + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command("makemigrations", "migrations", merge=True, interactive=True, stdout=out) merge_file = os.path.join(migration_dir, '0003_merge_20160102_0304.py') @@ -915,7 +914,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() with self.assertRaises(SystemExit): with self.temporary_migration_module(module="migrations.test_migrations_no_default"): call_command("makemigrations", "migrations", interactive=False, stdout=out) @@ -933,7 +932,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations"): call_command("makemigrations", "migrations", interactive=False, stdout=out) self.assertIn("Alter field slug on author", out.getvalue()) @@ -949,7 +948,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_no_default"): call_command("makemigrations", "migrations", interactive=False, stdout=out) self.assertIn("Delete model SillyModel", out.getvalue()) @@ -966,7 +965,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_no_default"): call_command("makemigrations", "migrations", interactive=False, stdout=out) self.assertIn("Remove field silly_field from sillymodel", out.getvalue()) @@ -976,7 +975,7 @@ class MakeMigrationsTests(MigrationTestBase): """ makemigrations properly merges the conflicting migrations with --noinput. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command("makemigrations", "migrations", name="merge", merge=True, interactive=False, stdout=out) merge_file = os.path.join(migration_dir, '0003_merge.py') @@ -992,7 +991,7 @@ class MakeMigrationsTests(MigrationTestBase): makemigrations respects --dry-run option when fixing migration conflicts (#24427). """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command( "makemigrations", "migrations", name="merge", dry_run=True, @@ -1011,7 +1010,7 @@ class MakeMigrationsTests(MigrationTestBase): `makemigrations --merge --dry-run` writes the merge migration file to stdout with `verbosity == 3` (#24427). """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command( "makemigrations", "migrations", name="merge", dry_run=True, @@ -1045,7 +1044,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_no_default"): call_command("makemigrations", "migrations", dry_run=True, stdout=out) # Output the expected changes directly, without asking for defaults @@ -1063,7 +1062,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_no_default"): call_command("makemigrations", "migrations", dry_run=True, stdout=out, verbosity=3) @@ -1091,7 +1090,7 @@ class MakeMigrationsTests(MigrationTestBase): class Meta: app_label = "migrations" - out = six.StringIO() + out = io.StringIO() migration_module = "migrations.test_migrations_path_doesnt_exist.foo.bar" with self.temporary_migration_module(module=migration_module) as migration_dir: call_command("makemigrations", "migrations", stdout=out) @@ -1110,8 +1109,8 @@ class MakeMigrationsTests(MigrationTestBase): --noinput is specified. """ # Monkeypatch interactive questioner to auto reject - out = six.StringIO() - with mock.patch('django.db.migrations.questioner.input', mock.Mock(return_value='N')): + out = io.StringIO() + with mock.patch('builtins.input', mock.Mock(return_value='N')): with self.temporary_migration_module(module="migrations.test_migrations_conflict") as migration_dir: call_command("makemigrations", "migrations", name="merge", merge=True, stdout=out) merge_file = os.path.join(migration_dir, '0003_merge.py') @@ -1141,8 +1140,8 @@ class MakeMigrationsTests(MigrationTestBase): it has conflicting migrations. """ # Monkeypatch interactive questioner to auto accept - with mock.patch('django.db.migrations.questioner.input', mock.Mock(return_value='y')): - out = six.StringIO() + with mock.patch('builtins.input', mock.Mock(return_value='y')): + out = io.StringIO() with self.temporary_migration_module(app_label="migrated_app") as migration_dir: call_command("makemigrations", "migrated_app", name="merge", merge=True, interactive=True, stdout=out) merge_file = os.path.join(migration_dir, '0003_merge.py') @@ -1159,8 +1158,8 @@ class MakeMigrationsTests(MigrationTestBase): don't belong to a given app. """ # Monkeypatch interactive questioner to auto accept - with mock.patch('django.db.migrations.questioner.input', mock.Mock(return_value='N')): - out = six.StringIO() + with mock.patch('builtins.input', mock.Mock(return_value='N')): + out = io.StringIO() with mock.patch('django.core.management.color.supports_color', lambda *args: False): call_command( "makemigrations", "conflicting_app_with_dependencies", @@ -1232,7 +1231,7 @@ class MakeMigrationsTests(MigrationTestBase): they are outside of the current tree, in which case the absolute path should be shown. """ - out = six.StringIO() + out = io.StringIO() apps.register_model('migrations', UnicodeModel) with self.temporary_migration_module() as migration_dir: call_command("makemigrations", "migrations", stdout=out) @@ -1245,7 +1244,7 @@ class MakeMigrationsTests(MigrationTestBase): Windows if Django is installed on a different drive than where the migration files are created. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module() as migration_dir: with mock.patch('os.path.relpath', side_effect=ValueError): call_command('makemigrations', 'migrations', stdout=out) @@ -1263,7 +1262,7 @@ class MakeMigrationsTests(MigrationTestBase): with self.assertRaisesMessage(InconsistentMigrationHistory, msg): call_command("makemigrations") - @mock.patch('django.db.migrations.questioner.input', return_value='1') + @mock.patch('builtins.input', return_value='1') @mock.patch('django.db.migrations.questioner.sys.stdin', mock.MagicMock(encoding=sys.getdefaultencoding())) def test_makemigrations_auto_now_add_interactive(self, *args): """ @@ -1278,8 +1277,8 @@ class MakeMigrationsTests(MigrationTestBase): app_label = 'migrations' # Monkeypatch interactive questioner to auto accept - with mock.patch('django.db.migrations.questioner.sys.stdout', new_callable=six.StringIO) as prompt_stdout: - out = six.StringIO() + with mock.patch('django.db.migrations.questioner.sys.stdout', new_callable=io.StringIO) as prompt_stdout: + out = io.StringIO() with self.temporary_migration_module(module='migrations.test_auto_now_add'): call_command('makemigrations', 'migrations', interactive=True, stdout=out) output = out.getvalue() @@ -1316,7 +1315,7 @@ class SquashMigrationsTests(MigrationTestBase): """ squashmigrations optimizes operations. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations"): call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, stdout=out) self.assertIn("Optimized from 8 operations to 3 operations.", out.getvalue()) @@ -1325,7 +1324,7 @@ class SquashMigrationsTests(MigrationTestBase): """ squashmigrations --no-optimize doesn't optimize operations. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations"): call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, no_optimize=True, stdout=out) @@ -1335,7 +1334,7 @@ class SquashMigrationsTests(MigrationTestBase): """ squashmigrations accepts a starting migration. """ - out = six.StringIO() + out = io.StringIO() with self.temporary_migration_module(module="migrations.test_migrations_no_changes") as migration_dir: call_command("squashmigrations", "migrations", "0002", "0003", interactive=False, verbosity=1, stdout=out) diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 59fd8eece5..fb16b441d1 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -8,6 +8,7 @@ import sys import tokenize import unittest import uuid +from io import StringIO import custom_migration_operations.more_operations import custom_migration_operations.operations @@ -20,7 +21,7 @@ from django.db.migrations.writer import ( MigrationWriter, OperationWriter, SettingsReference, ) from django.test import SimpleTestCase, ignore_warnings, mock -from django.utils import datetime_safe, six +from django.utils import datetime_safe from django.utils._os import upath from django.utils.deconstruct import deconstructible from django.utils.encoding import force_str @@ -561,7 +562,7 @@ class WriterTests(SimpleTestCase): self.assertIn("Migration", result) # In order to preserve compatibility with Python 3.2 unicode literals # prefix shouldn't be added to strings. - tokens = tokenize.generate_tokens(six.StringIO(str(output)).readline) + tokens = tokenize.generate_tokens(StringIO(str(output)).readline) for token_type, token_source, (srow, scol), __, line in tokens: if token_type == tokenize.STRING: self.assertFalse( diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index 019301d5e2..4830fb9ed2 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -12,7 +12,6 @@ from django.db.models.fields.files import ImageField, ImageFieldFile from django.db.models.fields.related import ( ForeignKey, ForeignObject, ManyToManyField, OneToOneField, ) -from django.utils import six try: from PIL import Image @@ -51,7 +50,7 @@ class Whiz(models.Model): c = models.IntegerField(choices=CHOICES, null=True) -class Counter(six.Iterator): +class Counter: def __init__(self): self.n = 1 diff --git a/tests/model_fields/test_binaryfield.py b/tests/model_fields/test_binaryfield.py index 641dc17287..9d97d1118f 100644 --- a/tests/model_fields/test_binaryfield.py +++ b/tests/model_fields/test_binaryfield.py @@ -1,6 +1,5 @@ from django.core.exceptions import ValidationError from django.test import TestCase -from django.utils import six from .models import DataModel @@ -9,7 +8,7 @@ class BinaryFieldTests(TestCase): binary_data = b'\x00\x46\xFE' def test_set_and_retrieve(self): - data_set = (self.binary_data, six.memoryview(self.binary_data)) + data_set = (self.binary_data, memoryview(self.binary_data)) for bdata in data_set: dm = DataModel(data=bdata) dm.save() diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index 0914fc2587..f85ae8e1fd 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -16,7 +16,6 @@ from django.core.exceptions import ValidationError from django.core.files.storage import FileSystemStorage from django.db import models from django.utils._os import upath -from django.utils.six.moves import range temp_storage_dir = tempfile.mkdtemp() temp_storage = FileSystemStorage(temp_storage_dir) diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 27143e97f4..adb90d6d14 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -17,7 +17,6 @@ from django.forms.models import ( ) from django.template import Context, Template from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature -from django.utils import six from django.utils._os import upath from .models import ( @@ -2954,7 +2953,7 @@ class CustomMetaclass(ModelFormMetaclass): return new -class CustomMetaclassForm(six.with_metaclass(CustomMetaclass, forms.ModelForm)): +class CustomMetaclassForm(forms.ModelForm, metaclass=CustomMetaclass): pass diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 7e936216b7..3487894fd9 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -1,5 +1,6 @@ import datetime import pickle +from io import StringIO from operator import attrgetter from django.contrib.auth.models import User @@ -9,7 +10,6 @@ from django.db import DEFAULT_DB_ALIAS, connections, router, transaction from django.db.models import signals from django.db.utils import ConnectionRouter from django.test import SimpleTestCase, TestCase, override_settings -from django.utils.six import StringIO from .models import Book, Person, Pet, Review, UserProfile from .routers import AuthRouter, TestRouter, WriteRouter diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py index cc3a0efbc2..2e2e2d37db 100644 --- a/tests/pagination/tests.py +++ b/tests/pagination/tests.py @@ -6,7 +6,6 @@ from django.core.paginator import ( UnorderedObjectListWarning, ) from django.test import TestCase -from django.utils import six from .custom import ValidAdjacentNumsPaginator from .models import Article @@ -240,7 +239,7 @@ class PaginationTests(unittest.TestCase): """ Paginator.page_range should be an iterator. """ - self.assertIsInstance(Paginator([1, 2, 3], 2).page_range, type(six.moves.range(0))) + self.assertIsInstance(Paginator([1, 2, 3], 2).page_range, type(range(0))) class ModelPaginationTests(TestCase): diff --git a/tests/queries/tests.py b/tests/queries/tests.py index ed323be154..1f9094e49f 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -11,7 +11,6 @@ from django.db.models.sql.constants import LOUTER from django.db.models.sql.where import NothingNode, WhereNode from django.test import TestCase, skipUnlessDBFeature from django.test.utils import CaptureQueriesContext -from django.utils.six.moves import range from .models import ( FK1, Annotation, Article, Author, BaseA, Book, CategoryItem, diff --git a/tests/requests/tests.py b/tests/requests/tests.py index 09b08540f4..54fe797728 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -1,7 +1,9 @@ import time from datetime import datetime, timedelta +from http import cookies from io import BytesIO from itertools import chain +from urllib.parse import urlencode as original_urlencode from django.core.exceptions import SuspiciousOperation from django.core.handlers.wsgi import LimitedStream, WSGIRequest @@ -14,8 +16,6 @@ from django.test.client import FakePayload from django.test.utils import freeze_time, str_prefix from django.utils.encoding import force_str from django.utils.http import cookie_date, urlencode -from django.utils.six.moves import http_cookies -from django.utils.six.moves.urllib.parse import urlencode as original_urlencode from django.utils.timezone import utc @@ -262,7 +262,7 @@ class RequestsTests(SimpleTestCase): example_cookie = response.cookies['example'] # A compat cookie may be in use -- check that it has worked # both as an output string, and using the cookie attributes - self.assertIn('; %s' % http_cookies.Morsel._reserved['httponly'], str(example_cookie)) + self.assertIn('; %s' % cookies.Morsel._reserved['httponly'], str(example_cookie)) self.assertTrue(example_cookie['httponly']) def test_unicode_cookie(self): diff --git a/tests/serializers/test_data.py b/tests/serializers/test_data.py index 2e9527f982..966df682b2 100644 --- a/tests/serializers/test_data.py +++ b/tests/serializers/test_data.py @@ -13,7 +13,6 @@ import uuid from django.core import serializers from django.db import connection, models from django.test import TestCase -from django.utils import six from .models import ( Anchor, AutoNowDateTimeData, BigIntegerData, BinaryData, BooleanData, @@ -197,7 +196,7 @@ uuid_obj = uuid.uuid4() test_data = [ # Format: (data type, PK value, Model Class, data) - (data_obj, 1, BinaryData, six.memoryview(b"\x05\xFD\x00")), + (data_obj, 1, BinaryData, memoryview(b"\x05\xFD\x00")), (data_obj, 2, BinaryData, None), (data_obj, 5, BooleanData, True), (data_obj, 6, BooleanData, False), diff --git a/tests/serializers/test_yaml.py b/tests/serializers/test_yaml.py index f3988d7ff1..542c28fb2e 100644 --- a/tests/serializers/test_yaml.py +++ b/tests/serializers/test_yaml.py @@ -1,10 +1,10 @@ import importlib import unittest +from io import StringIO from django.core import management, serializers from django.core.serializers.base import DeserializationError from django.test import SimpleTestCase, TestCase, TransactionTestCase -from django.utils.six import StringIO from .models import Author from .tests import SerializersTestBase, SerializersTransactionTestBase diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py index 656bc4b4db..5c30d66082 100644 --- a/tests/serializers/tests.py +++ b/tests/serializers/tests.py @@ -1,4 +1,5 @@ from datetime import datetime +from io import StringIO from django.core import serializers from django.core.serializers import SerializerDoesNotExist @@ -10,7 +11,6 @@ from django.test import ( ) from django.test.utils import Approximate from django.utils.functional import curry -from django.utils.six import StringIO from .models import ( Actor, Article, Author, AuthorProfile, BaseModel, Category, ComplexModel, diff --git a/tests/servers/tests.py b/tests/servers/tests.py index ee0d8629cf..8f7e3253e7 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -5,12 +5,12 @@ import contextlib import errno import os import socket +from urllib.error import HTTPError +from urllib.request import urlopen from django.test import LiveServerTestCase, override_settings from django.utils._os import upath from django.utils.http import urlencode -from django.utils.six.moves.urllib.error import HTTPError -from django.utils.six.moves.urllib.request import urlopen from .models import Person diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py index ae57f1d919..29de5782d9 100644 --- a/tests/sessions_tests/tests.py +++ b/tests/sessions_tests/tests.py @@ -6,6 +6,7 @@ import sys import tempfile import unittest from datetime import timedelta +from http import cookies from django.conf import settings from django.contrib.sessions.backends.base import UpdateError @@ -31,9 +32,8 @@ from django.test import ( RequestFactory, TestCase, ignore_warnings, override_settings, ) from django.test.utils import patch_logger -from django.utils import six, timezone +from django.utils import timezone from django.utils.encoding import force_text -from django.utils.six.moves import http_cookies from .models import SessionStore as CustomDatabaseSession @@ -122,7 +122,7 @@ class SessionTestsMixin(object): self.session['x'] = 1 self.session.modified = False self.session.accessed = False - i = six.iterkeys(self.session) + i = iter(self.session.keys()) self.assertTrue(hasattr(i, '__iter__')) self.assertTrue(self.session.accessed) self.assertFalse(self.session.modified) @@ -132,7 +132,7 @@ class SessionTestsMixin(object): self.session['x'] = 1 self.session.modified = False self.session.accessed = False - i = six.itervalues(self.session) + i = iter(self.session.values()) self.assertTrue(hasattr(i, '__iter__')) self.assertTrue(self.session.accessed) self.assertFalse(self.session.modified) @@ -142,7 +142,7 @@ class SessionTestsMixin(object): self.session['x'] = 1 self.session.modified = False self.session.accessed = False - i = six.iteritems(self.session) + i = iter(self.session.items()) self.assertTrue(hasattr(i, '__iter__')) self.assertTrue(self.session.accessed) self.assertFalse(self.session.modified) @@ -661,7 +661,7 @@ class SessionMiddlewareTests(TestCase): self.assertTrue( response.cookies[settings.SESSION_COOKIE_NAME]['httponly']) self.assertIn( - http_cookies.Morsel._reserved['httponly'], + cookies.Morsel._reserved['httponly'], str(response.cookies[settings.SESSION_COOKIE_NAME]) ) @@ -679,7 +679,7 @@ class SessionMiddlewareTests(TestCase): response = middleware.process_response(request, response) self.assertFalse(response.cookies[settings.SESSION_COOKIE_NAME]['httponly']) - self.assertNotIn(http_cookies.Morsel._reserved['httponly'], + self.assertNotIn(cookies.Morsel._reserved['httponly'], str(response.cookies[settings.SESSION_COOKIE_NAME])) def test_session_save_on_500(self): diff --git a/tests/sitemaps_tests/test_utils.py b/tests/sitemaps_tests/test_utils.py index ba1eadd5d1..dc4d6511f3 100644 --- a/tests/sitemaps_tests/test_utils.py +++ b/tests/sitemaps_tests/test_utils.py @@ -1,9 +1,10 @@ +from urllib.parse import urlencode + from django.contrib.sitemaps import ( SitemapNotFound, _get_sitemap_full_url, ping_google, ) from django.core.exceptions import ImproperlyConfigured from django.test import mock, modify_settings, override_settings -from django.utils.six.moves.urllib.parse import urlencode from .base import SitemapTestsBase diff --git a/tests/staticfiles_tests/test_forms.py b/tests/staticfiles_tests/test_forms.py index e3d4772662..4666520bc1 100644 --- a/tests/staticfiles_tests/test_forms.py +++ b/tests/staticfiles_tests/test_forms.py @@ -1,8 +1,9 @@ +from urllib.parse import urljoin + from django.contrib.staticfiles import storage from django.contrib.staticfiles.templatetags.staticfiles import static from django.forms import Media from django.test import SimpleTestCase, override_settings -from django.utils.six.moves.urllib.parse import urljoin class StaticTestStorage(storage.StaticFilesStorage): diff --git a/tests/staticfiles_tests/test_liveserver.py b/tests/staticfiles_tests/test_liveserver.py index 1714ae8b1b..b3727bea12 100644 --- a/tests/staticfiles_tests/test_liveserver.py +++ b/tests/staticfiles_tests/test_liveserver.py @@ -6,12 +6,12 @@ django.test.LiveServerTestCase. import contextlib import os +from urllib.request import urlopen from django.contrib.staticfiles.testing import StaticLiveServerTestCase from django.core.exceptions import ImproperlyConfigured from django.test import modify_settings, override_settings from django.utils._os import upath -from django.utils.six.moves.urllib.request import urlopen TEST_ROOT = os.path.dirname(upath(__file__)) TEST_SETTINGS = { diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 7d17f2abe1..310c152d06 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -4,6 +4,7 @@ import os import shutil import tempfile import unittest +from io import StringIO from admin_scripts.tests import AdminScriptTestCase @@ -14,7 +15,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command from django.test import mock, override_settings from django.test.utils import extend_sys_path -from django.utils import six, timezone +from django.utils import timezone from django.utils._os import symlinks_supported from django.utils.encoding import force_text from django.utils.functional import empty @@ -38,7 +39,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase): Test ``findstatic`` management command. """ def _get_file(self, filepath): - path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=six.StringIO()) + path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=StringIO()) with codecs.open(force_text(path), "r", "utf-8") as f: return f.read() @@ -46,7 +47,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase): """ findstatic returns all candidate files if run without --first and -v1. """ - result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=six.StringIO()) + result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=StringIO()) lines = [l.strip() for l in result.split('\n')] self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line self.assertIn('project', force_text(lines[1])) @@ -56,7 +57,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase): """ findstatic returns all candidate files if run without --first and -v0. """ - result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=six.StringIO()) + result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=StringIO()) lines = [l.strip() for l in result.split('\n')] self.assertEqual(len(lines), 2) self.assertIn('project', force_text(lines[0])) @@ -67,7 +68,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase): findstatic returns all candidate files if run without --first and -v2. Also, test that findstatic returns the searched locations with -v2. """ - result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=six.StringIO()) + result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=StringIO()) lines = [l.strip() for l in result.split('\n')] self.assertIn('project', force_text(lines[1])) self.assertIn('apps', force_text(lines[2])) @@ -89,7 +90,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase): class TestConfiguration(StaticFilesTestCase): def test_location_empty(self): msg = 'without having set the STATIC_ROOT setting to a filesystem path' - err = six.StringIO() + err = StringIO() for root in ['', None]: with override_settings(STATIC_ROOT=root): with self.assertRaisesMessage(ImproperlyConfigured, msg): @@ -188,10 +189,9 @@ class TestInteractiveMessages(CollectionTestCase): return _input def test_warning_when_clearing_staticdir(self): - stdout = six.StringIO() + stdout = StringIO() self.run_collectstatic() - with mock.patch('django.contrib.staticfiles.management.commands.collectstatic.input', - side_effect=self.mock_input(stdout)): + with mock.patch('builtins.input', side_effect=self.mock_input(stdout)): call_command('collectstatic', interactive=True, clear=True, stdout=stdout) output = force_text(stdout.getvalue()) @@ -199,17 +199,16 @@ class TestInteractiveMessages(CollectionTestCase): self.assertIn(self.delete_warning_msg, output) def test_warning_when_overwriting_files_in_staticdir(self): - stdout = six.StringIO() + stdout = StringIO() self.run_collectstatic() - with mock.patch('django.contrib.staticfiles.management.commands.collectstatic.input', - side_effect=self.mock_input(stdout)): + with mock.patch('builtins.input', side_effect=self.mock_input(stdout)): call_command('collectstatic', interactive=True, stdout=stdout) output = force_text(stdout.getvalue()) self.assertIn(self.overwrite_warning_msg, output) self.assertNotIn(self.delete_warning_msg, output) def test_no_warning_when_staticdir_does_not_exist(self): - stdout = six.StringIO() + stdout = StringIO() shutil.rmtree(settings.STATIC_ROOT) call_command('collectstatic', interactive=True, stdout=stdout) output = force_text(stdout.getvalue()) @@ -218,7 +217,7 @@ class TestInteractiveMessages(CollectionTestCase): self.assertIn(self.files_copied_msg, output) def test_no_warning_for_empty_staticdir(self): - stdout = six.StringIO() + stdout = StringIO() static_dir = tempfile.mkdtemp(prefix='collectstatic_empty_staticdir_test') with override_settings(STATIC_ROOT=static_dir): call_command('collectstatic', interactive=True, stdout=stdout) @@ -347,7 +346,7 @@ class TestCollectionOverwriteWarning(CollectionTestCase): the command at highest verbosity, which is why we can't just call e.g. BaseCollectionTestCase.run_collectstatic() """ - out = six.StringIO() + out = StringIO() call_command('collectstatic', interactive=False, verbosity=3, stdout=out, **kwargs) return force_text(out.getvalue()) @@ -407,7 +406,7 @@ class TestCollectionNeverCopyStorage(CollectionTestCase): NeverCopyRemoteStorage.get_modified_time() returns a datetime in the future to simulate an unmodified file. """ - stdout = six.StringIO() + stdout = StringIO() self.run_collectstatic(stdout=stdout, verbosity=2) output = force_text(stdout.getvalue()) self.assertIn("Skipping 'test.txt' (not modified)", output) diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index 6333be7549..e299feea78 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -3,6 +3,7 @@ import shutil import sys import tempfile import unittest +from io import StringIO from django.conf import settings from django.contrib.staticfiles import finders, storage @@ -11,7 +12,6 @@ from django.contrib.staticfiles.management.commands.collectstatic import \ from django.core.cache.backends.base import BaseCache from django.core.management import call_command from django.test import override_settings -from django.utils import six from django.utils.encoding import force_text from .cases import CollectionTestCase @@ -172,7 +172,7 @@ class TestHashedFiles(object): ) def test_import_loop(self): finders.get_finder.cache_clear() - err = six.StringIO() + err = StringIO() with self.assertRaisesMessage(RuntimeError, 'Max post-process passes exceeded'): call_command('collectstatic', interactive=False, verbosity=0, stderr=err) self.assertEqual("Post-processing 'All' failed!\n\n", err.getvalue()) @@ -225,7 +225,7 @@ class TestHashedFiles(object): post_processing indicates the origin of the error when it fails. """ finders.get_finder.cache_clear() - err = six.StringIO() + err = StringIO() with self.assertRaises(Exception): call_command('collectstatic', interactive=False, verbosity=0, stderr=err) self.assertEqual("Post-processing 'faulty.css' failed!\n\n", err.getvalue()) @@ -429,7 +429,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): with self.assertRaisesMessage(ValueError, err_msg): self.hashed_file_path(missing_file_name) - content = six.StringIO() + content = StringIO() content.write('Found') configured_storage.save(missing_file_name, content) # File exists on disk @@ -566,7 +566,7 @@ class TestCollectionHashedFilesCache(CollectionTestCase): def test_file_change_after_collectstatic(self): finders.get_finder.cache_clear() - err = six.StringIO() + err = StringIO() call_command('collectstatic', interactive=False, verbosity=0, stderr=err) with open(self.testimage_path, 'w+b') as f: f.write(b"new content of png file to change it's hash") diff --git a/tests/swappable_models/tests.py b/tests/swappable_models/tests.py index b67aece8c0..e9d15db015 100644 --- a/tests/swappable_models/tests.py +++ b/tests/swappable_models/tests.py @@ -1,10 +1,11 @@ -from swappable_models.models import Article +from io import StringIO from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.core import management from django.test import TestCase, override_settings -from django.utils.six import StringIO + +from .models import Article class SwappableModelTests(TestCase): diff --git a/tests/template_tests/syntax_tests/test_static.py b/tests/template_tests/syntax_tests/test_static.py index deb0ce6c78..345f943caf 100644 --- a/tests/template_tests/syntax_tests/test_static.py +++ b/tests/template_tests/syntax_tests/test_static.py @@ -1,6 +1,7 @@ +from urllib.parse import urljoin + from django.conf import settings from django.test import SimpleTestCase, override_settings -from django.utils.six.moves.urllib.parse import urljoin from ..utils import setup diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py index 363e7094ce..485f49a82d 100644 --- a/tests/template_tests/templatetags/custom.py +++ b/tests/template_tests/templatetags/custom.py @@ -2,7 +2,6 @@ import operator from django import template from django.template.defaultfilters import stringfilter -from django.utils import six from django.utils.html import escape, format_html register = template.Library() @@ -114,7 +113,7 @@ simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dic def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs): """Expected simple_unlimited_args_kwargs __doc__""" # Sort the dictionary by key to guarantee the order for testing. - sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0)) + sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0)) return "simple_unlimited_args_kwargs - Expected result: %s / %s" % ( ', '.join(str(arg) for arg in [one, two] + list(args)), ', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg) diff --git a/tests/template_tests/templatetags/inclusion.py b/tests/template_tests/templatetags/inclusion.py index 745dd7ffae..60f654ec00 100644 --- a/tests/template_tests/templatetags/inclusion.py +++ b/tests/template_tests/templatetags/inclusion.py @@ -1,7 +1,6 @@ import operator from django.template import Engine, Library -from django.utils import six engine = Engine(app_dirs=True) register = Library() @@ -215,7 +214,7 @@ inclusion_tag_use_l10n.anything = "Expected inclusion_tag_use_l10n __dict__" def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs): """Expected inclusion_unlimited_args_kwargs __doc__""" # Sort the dictionary by key to guarantee the order for testing. - sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0)) + sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0)) return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % ( ', '.join(str(arg) for arg in [one, two] + list(args)), ', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg) diff --git a/tests/test_client/views.py b/tests/test_client/views.py index af30c4283d..e9a28449ec 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -1,3 +1,4 @@ +from urllib.parse import urlencode from xml.dom.minidom import parseString from django.contrib.auth.decorators import login_required, permission_required @@ -13,7 +14,6 @@ from django.shortcuts import render from django.template import Context, Template from django.test import Client from django.utils.decorators import method_decorator -from django.utils.six.moves.urllib.parse import urlencode def get_view(request): diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py index ce60c0398c..854cdc3bc0 100644 --- a/tests/test_client_regress/views.py +++ b/tests/test_client_regress/views.py @@ -1,4 +1,5 @@ import json +from urllib.parse import urlencode from django.conf import settings from django.contrib.auth.decorators import login_required @@ -8,7 +9,6 @@ from django.shortcuts import render from django.template.loader import render_to_string from django.test import Client from django.test.client import CONTENT_TYPE_RE -from django.utils.six.moves.urllib.parse import urlencode class CustomTestException(Exception): diff --git a/tests/test_runner/test_debug_sql.py b/tests/test_runner/test_debug_sql.py index c6b9b01dbc..1b36fbc876 100644 --- a/tests/test_runner/test_debug_sql.py +++ b/tests/test_runner/test_debug_sql.py @@ -1,10 +1,10 @@ import sys import unittest +from io import StringIO from django.db import connection from django.test import TestCase from django.test.runner import DiscoverRunner -from django.utils import six from .models import Person @@ -33,7 +33,7 @@ class TestDebugSQL(unittest.TestCase): suite.addTest(self.ErrorTest()) suite.addTest(self.PassingTest()) old_config = runner.setup_databases() - stream = six.StringIO() + stream = StringIO() resultclass = runner.get_resultclass() runner.test_runner( verbosity=verbosity, diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 4d29f1a491..f8eda7ed39 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -1,5 +1,6 @@ import sys import unittest +from io import StringIO from django.conf.urls import url from django.contrib.staticfiles.finders import get_finder, get_finders @@ -18,7 +19,6 @@ from django.test.utils import ( setup_test_environment, ) from django.urls import NoReverseMatch, reverse -from django.utils import six from django.utils._os import abspathu from .models import Car, Person, PossessedCar @@ -117,7 +117,7 @@ class SkippingClassTestCase(SimpleTestCase): test_suite.addTest(SkippedTestsSubclass('test_will_be_skipped')) except unittest.SkipTest: self.fail("SkipTest should not be raised at this stage") - result = unittest.TextTestRunner(stream=six.StringIO()).run(test_suite) + result = unittest.TextTestRunner(stream=StringIO()).run(test_suite) self.assertEqual(result.testsRun, 3) self.assertEqual(len(result.skipped), 2) self.assertEqual(result.skipped[0][1], 'Database has feature(s) __class__') diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index 7f7c8228e8..e5a67f745e 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -23,7 +23,7 @@ from django.test import ( ) from django.test.utils import requires_tz_support from django.urls import reverse -from django.utils import six, timezone +from django.utils import timezone from django.utils.timezone import timedelta from .forms import ( @@ -888,8 +888,8 @@ class TemplateTests(SimpleTestCase): } } - for k1, dt in six.iteritems(datetimes): - for k2, tpl in six.iteritems(templates): + for k1, dt in datetimes.items(): + for k2, tpl in templates.items(): ctx = Context({'dt': dt, 'ICT': ICT}) actual = tpl.render(ctx) expected = results[k1][k2] @@ -901,8 +901,8 @@ class TemplateTests(SimpleTestCase): results['ict']['notag'] = t('ict', 'eat', 'utc', 'ict') with self.settings(USE_TZ=False): - for k1, dt in six.iteritems(datetimes): - for k2, tpl in six.iteritems(templates): + for k1, dt in datetimes.items(): + for k2, tpl in templates.items(): ctx = Context({'dt': dt, 'ICT': ICT}) actual = tpl.render(ctx) expected = results[k1][k2] diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index 4e4f5dc911..cfc4f5fb2e 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -1,4 +1,5 @@ import os +from io import StringIO from admin_scripts.tests import AdminScriptTestCase @@ -11,7 +12,6 @@ from django.test import SimpleTestCase, mock, override_settings from django.test.utils import captured_stderr, extend_sys_path from django.utils import translation from django.utils._os import upath -from django.utils.six import StringIO from .management.commands import dance diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index 5d42af62c8..4036df8dd8 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -4,13 +4,14 @@ import shutil import tempfile from importlib import import_module +import _thread + from django import conf from django.contrib import admin from django.test import SimpleTestCase, mock, override_settings from django.test.utils import extend_sys_path from django.utils import autoreload from django.utils._os import npath -from django.utils.six.moves import _thread from django.utils.translation import trans_real LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale') diff --git a/tests/utils_tests/test_baseconv.py b/tests/utils_tests/test_baseconv.py index 538189bbe6..948b991ad3 100644 --- a/tests/utils_tests/test_baseconv.py +++ b/tests/utils_tests/test_baseconv.py @@ -3,7 +3,6 @@ from unittest import TestCase from django.utils.baseconv import ( BaseConverter, base2, base16, base36, base56, base62, base64, ) -from django.utils.six.moves import range class TestBaseConv(TestCase): diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py index f917a2ae4e..df7020eac5 100644 --- a/tests/utils_tests/test_datastructures.py +++ b/tests/utils_tests/test_datastructures.py @@ -5,7 +5,6 @@ Tests for stuff in django.utils.datastructures. import copy from django.test import SimpleTestCase -from django.utils import six from django.utils.datastructures import ( DictWrapper, ImmutableList, MultiValueDict, MultiValueDictKeyError, OrderedSet, @@ -40,12 +39,12 @@ class MultiValueDictTests(SimpleTestCase): self.assertEqual(d.get('name'), 'Simon') self.assertEqual(d.getlist('name'), ['Adrian', 'Simon']) self.assertEqual( - sorted(six.iteritems(d)), + sorted(d.items()), [('name', 'Simon'), ('position', 'Developer')] ) self.assertEqual( - sorted(six.iterlists(d)), + sorted(d.lists()), [('name', ['Adrian', 'Simon']), ('position', ['Developer'])] ) @@ -60,8 +59,7 @@ class MultiValueDictTests(SimpleTestCase): d.setlist('lastname', ['Holovaty', 'Willison']) self.assertEqual(d.getlist('lastname'), ['Holovaty', 'Willison']) - self.assertEqual(sorted(six.itervalues(d)), - ['Developer', 'Simon', 'Willison']) + self.assertEqual(sorted(d.values()), ['Developer', 'Simon', 'Willison']) def test_appendlist(self): d = MultiValueDict() @@ -95,8 +93,8 @@ class MultiValueDictTests(SimpleTestCase): 'pm': ['Rory'], }) d = mvd.dict() - self.assertEqual(sorted(six.iterkeys(d)), sorted(six.iterkeys(mvd))) - for key in six.iterkeys(mvd): + self.assertEqual(sorted(d.keys()), sorted(mvd.keys())) + for key in mvd.keys(): self.assertEqual(d[key], mvd[key]) self.assertEqual({}, MultiValueDict().dict()) diff --git a/tests/utils_tests/test_lazyobject.py b/tests/utils_tests/test_lazyobject.py index 8c9b997b3c..513123ea00 100644 --- a/tests/utils_tests/test_lazyobject.py +++ b/tests/utils_tests/test_lazyobject.py @@ -4,7 +4,6 @@ import sys import warnings from unittest import TestCase -from django.utils import six from django.utils.functional import LazyObject, SimpleLazyObject, empty from .models import Category, CategoryInfo @@ -300,7 +299,7 @@ class SimpleLazyObjectTestCase(LazyObjectTestCase): obj = self.lazy_wrap(42) # __repr__ contains __repr__ of setup function and does not evaluate # the SimpleLazyObject - six.assertRegex(self, repr(obj), '^<SimpleLazyObject:') + self.assertRegex(repr(obj), '^<SimpleLazyObject:') self.assertIs(obj._wrapped, empty) # make sure evaluation hasn't been triggered self.assertEqual(obj, 42) # evaluate the lazy object diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 1d8397c5ef..7a9cea826b 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -4,6 +4,7 @@ import os import re import sys import tempfile +from io import StringIO from django.conf.urls import url from django.core import mail @@ -13,7 +14,6 @@ from django.template import TemplateDoesNotExist from django.test import RequestFactory, SimpleTestCase, override_settings from django.test.utils import LoggingCaptureMixin, patch_logger from django.urls import reverse -from django.utils import six from django.utils.encoding import force_bytes, force_text from django.utils.functional import SimpleLazyObject from django.views.debug import ( @@ -513,7 +513,7 @@ class ExceptionReporterTests(SimpleTestCase): html = reporter.get_traceback_html() self.assertInHTML(value, html) # FILES - fp = six.StringIO('filecontent') + fp = StringIO('filecontent') request = self.rf.post('/test_view/', data={'name': 'filename', 'items': fp}) reporter = ExceptionReporter(request, None, None, None) html = reporter.get_traceback_html() @@ -628,7 +628,7 @@ class PlainTextReportTests(SimpleTestCase): text = reporter.get_traceback_text() self.assertIn("items = 'Oops'", text) # FILES - fp = six.StringIO('filecontent') + fp = StringIO('filecontent') request = self.rf.post('/test_view/', data={'name': 'filename', 'items': fp}) reporter = ExceptionReporter(request, None, None, None) text = reporter.get_traceback_text() |