diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py index 1efa035e8a..b332348425 100644 --- a/tests/modeltests/fixtures/tests.py +++ b/tests/modeltests/fixtures/tests.py @@ -1,11 +1,10 @@ from __future__ import absolute_import -import StringIO - from django.contrib.sites.models import Site from django.core import management from django.db import connection, IntegrityError from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature +from django.utils.six import StringIO from .models import Article, Book, Spy, Tag, Visa @@ -26,7 +25,7 @@ class FixtureLoadingTests(TestCase): def _dumpdata_assert(self, args, output, format='json', natural_keys=False, use_base_manager=False, exclude_list=[]): - new_io = StringIO.StringIO() + new_io = StringIO() management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io, 'stderr':new_io, @@ -43,7 +42,7 @@ class FixtureLoadingTests(TestCase): ]) def test_loading_and_dumping(self): - new_io = StringIO.StringIO() + new_io = StringIO() Site.objects.all().delete() # Load fixture 1. Single JSON file, with two objects. @@ -293,7 +292,7 @@ class FixtureLoadingTests(TestCase): class FixtureTransactionTests(TransactionTestCase): def _dumpdata_assert(self, args, output, format='json'): - new_io = StringIO.StringIO() + new_io = StringIO() management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io}) command_output = new_io.getvalue().strip() self.assertEqual(command_output, output) diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py index 9177227539..ec3cc132db 100644 --- a/tests/modeltests/serializers/tests.py +++ b/tests/modeltests/serializers/tests.py @@ -4,13 +4,13 @@ from __future__ import absolute_import, unicode_literals import json from datetime import datetime from xml.dom import minidom -from StringIO import StringIO from django.conf import settings from django.core import serializers from django.db import transaction, connection from django.test import TestCase, TransactionTestCase, Approximate from django.utils import six +from django.utils.six import StringIO from django.utils import unittest from .models import (Category, Author, Article, AuthorProfile, Actor, Movie, diff --git a/tests/modeltests/user_commands/tests.py b/tests/modeltests/user_commands/tests.py index 509f13f62f..d25911c09f 100644 --- a/tests/modeltests/user_commands/tests.py +++ b/tests/modeltests/user_commands/tests.py @@ -1,10 +1,10 @@ import sys -from StringIO import StringIO from django.core import management from django.core.management.base import CommandError from django.test import TestCase from django.utils import translation +from django.utils.six import StringIO class CommandTests(TestCase): diff --git a/tests/regressiontests/bash_completion/tests.py b/tests/regressiontests/bash_completion/tests.py index e4b3bb58f3..ed8cedf1ab 100644 --- a/tests/regressiontests/bash_completion/tests.py +++ b/tests/regressiontests/bash_completion/tests.py @@ -3,11 +3,11 @@ A series of tests to establish that the command-line bash completion works. """ import os import sys -import StringIO from django.conf import settings from django.core.management import ManagementUtility from django.utils import unittest +from django.utils.six import StringIO class BashCompletionTests(unittest.TestCase): @@ -20,7 +20,7 @@ class BashCompletionTests(unittest.TestCase): def setUp(self): self.old_DJANGO_AUTO_COMPLETE = os.environ.get('DJANGO_AUTO_COMPLETE') os.environ['DJANGO_AUTO_COMPLETE'] = '1' - self.output = StringIO.StringIO() + self.output = StringIO() self.old_stdout = sys.stdout sys.stdout = self.output diff --git a/tests/regressiontests/builtin_server/tests.py b/tests/regressiontests/builtin_server/tests.py index aeb5d9febf..4a3b44176b 100644 --- a/tests/regressiontests/builtin_server/tests.py +++ b/tests/regressiontests/builtin_server/tests.py @@ -1,6 +1,5 @@ -from StringIO import StringIO - from django.core.servers.basehttp import ServerHandler +from django.utils.six import StringIO from django.utils.unittest import TestCase # diff --git a/tests/regressiontests/createsuperuser/tests.py b/tests/regressiontests/createsuperuser/tests.py index 1c1bb0ed38..7303b1f2e7 100644 --- a/tests/regressiontests/createsuperuser/tests.py +++ b/tests/regressiontests/createsuperuser/tests.py @@ -1,9 +1,8 @@ -from StringIO import StringIO - from django.contrib.auth import models from django.contrib.auth.management.commands import changepassword from django.core.management import call_command from django.test import TestCase +from django.utils.six import StringIO class MultiDBChangepasswordManagementCommandTestCase(TestCase): diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py index 9fe3ca15a7..d2362d7197 100644 --- a/tests/regressiontests/file_uploads/tests.py +++ b/tests/regressiontests/file_uploads/tests.py @@ -7,12 +7,12 @@ import hashlib import json import os import shutil -from StringIO import StringIO from django.core.files import temp as tempfile from django.core.files.uploadedfile import SimpleUploadedFile from django.http.multipartparser import MultiPartParser from django.test import TestCase, client +from django.utils.six import StringIO from django.utils import unittest from . import uploadhandler diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index cd6d50893a..29d9e277ff 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -3,10 +3,10 @@ import os import re import shutil -from StringIO import StringIO from django.core import management from django.test import TestCase +from django.utils.six import StringIO LOCALE='de' diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py index 29435b8375..aae7bc5cc7 100644 --- a/tests/regressiontests/inspectdb/tests.py +++ b/tests/regressiontests/inspectdb/tests.py @@ -1,7 +1,6 @@ -from StringIO import StringIO - from django.core.management import call_command from django.test import TestCase, skipUnlessDBFeature +from django.utils.six import StringIO class InspectDBTestCase(TestCase): diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py index 2215f56523..0d0af19427 100644 --- a/tests/regressiontests/mail/tests.py +++ b/tests/regressiontests/mail/tests.py @@ -7,7 +7,6 @@ import os import shutil import smtpd import sys -from StringIO import StringIO import tempfile import threading @@ -18,6 +17,7 @@ from django.core.mail.backends import console, dummy, locmem, filebased, smtp from django.core.mail.message import BadHeaderError from django.test import TestCase from django.test.utils import override_settings +from django.utils.six import StringIO from django.utils.translation import ugettext_lazy diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py index ead34f46db..08a385e6cf 100644 --- a/tests/regressiontests/middleware/tests.py +++ b/tests/regressiontests/middleware/tests.py @@ -3,7 +3,6 @@ import gzip import re import random -import StringIO from django.conf import settings from django.core import mail @@ -16,6 +15,7 @@ from django.middleware.gzip import GZipMiddleware from django.test import TestCase, RequestFactory from django.test.utils import override_settings from django.utils.six.moves import xrange +from django.utils.six import StringIO class CommonMiddlewareTest(TestCase): def setUp(self): @@ -526,7 +526,7 @@ class GZipMiddlewareTest(TestCase): @staticmethod def decompress(gzipped_string): - return gzip.GzipFile(mode='rb', fileobj=StringIO.StringIO(gzipped_string)).read() + return gzip.GzipFile(mode='rb', fileobj=StringIO(gzipped_string)).read() def test_compress_response(self): """ diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py index 595c5edb3b..08632fd4ce 100644 --- a/tests/regressiontests/multiple_database/tests.py +++ b/tests/regressiontests/multiple_database/tests.py @@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals import datetime import pickle -from StringIO import StringIO from django.conf import settings from django.contrib.auth.models import User @@ -11,6 +10,7 @@ from django.core import management from django.db import connections, router, DEFAULT_DB_ALIAS from django.db.models import signals from django.test import TestCase +from django.utils.six import StringIO from .models import Book, Person, Pet, Review, UserProfile diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index 146dca2b7b..f192459246 100644 --- a/tests/regressiontests/requests/tests.py +++ b/tests/regressiontests/requests/tests.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals import time import warnings from datetime import datetime, timedelta -from StringIO import StringIO from django.conf import settings from django.core.handlers.wsgi import WSGIRequest, LimitedStream @@ -11,6 +10,7 @@ from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_r from django.test.utils import str_prefix from django.utils import unittest from django.utils.http import cookie_date +from django.utils.six import StringIO from django.utils.timezone import utc diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py index 5c11916308..6b635c8f23 100644 --- a/tests/regressiontests/templates/loaders.py +++ b/tests/regressiontests/templates/loaders.py @@ -12,13 +12,13 @@ if __name__ == '__main__': import sys import pkg_resources import imp -import StringIO import os.path from django.template import TemplateDoesNotExist, Context from django.template.loaders.eggs import Loader as EggLoader from django.template import loader from django.utils import unittest +from django.utils.six import StringIO # Mock classes and objects for pkg_resources functions. @@ -61,8 +61,8 @@ class EggLoaderTest(unittest.TestCase): self.empty_egg = create_egg("egg_empty", {}) self.egg_1 = create_egg("egg_1", { - os.path.normcase('templates/y.html') : StringIO.StringIO("y"), - os.path.normcase('templates/x.txt') : StringIO.StringIO("x"), + os.path.normcase('templates/y.html') : StringIO("y"), + os.path.normcase('templates/x.txt') : StringIO("x"), }) self._old_installed_apps = settings.INSTALLED_APPS settings.INSTALLED_APPS = [] diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py index 46479ebe8b..f43a855a59 100644 --- a/tests/regressiontests/test_utils/tests.py +++ b/tests/regressiontests/test_utils/tests.py @@ -493,7 +493,7 @@ __test__ = {"API_TEST": r""" # Standard doctests do fairly >>> import json >>> from django.utils.xmlutils import SimplerXMLGenerator ->>> from StringIO import StringIO +>>> from django.utils.six import StringIO >>> def produce_long(): ... return 42L