[py3] Used compatible imports of StringIO.

This commit is contained in:
Aymeric Augustin 2012-08-07 15:41:54 +02:00
parent 2da3af23aa
commit 396357741b
15 changed files with 22 additions and 26 deletions

View File

@ -1,11 +1,10 @@
from __future__ import absolute_import from __future__ import absolute_import
import StringIO
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core import management from django.core import management
from django.db import connection, IntegrityError from django.db import connection, IntegrityError
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
from django.utils.six import StringIO
from .models import Article, Book, Spy, Tag, Visa 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, def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
use_base_manager=False, exclude_list=[]): use_base_manager=False, exclude_list=[]):
new_io = StringIO.StringIO() new_io = StringIO()
management.call_command('dumpdata', *args, **{'format':format, management.call_command('dumpdata', *args, **{'format':format,
'stdout':new_io, 'stdout':new_io,
'stderr':new_io, 'stderr':new_io,
@ -43,7 +42,7 @@ class FixtureLoadingTests(TestCase):
]) ])
def test_loading_and_dumping(self): def test_loading_and_dumping(self):
new_io = StringIO.StringIO() new_io = StringIO()
Site.objects.all().delete() Site.objects.all().delete()
# Load fixture 1. Single JSON file, with two objects. # Load fixture 1. Single JSON file, with two objects.
@ -293,7 +292,7 @@ class FixtureLoadingTests(TestCase):
class FixtureTransactionTests(TransactionTestCase): class FixtureTransactionTests(TransactionTestCase):
def _dumpdata_assert(self, args, output, format='json'): 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}) management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io})
command_output = new_io.getvalue().strip() command_output = new_io.getvalue().strip()
self.assertEqual(command_output, output) self.assertEqual(command_output, output)

View File

@ -4,13 +4,13 @@ from __future__ import absolute_import, unicode_literals
import json import json
from datetime import datetime from datetime import datetime
from xml.dom import minidom from xml.dom import minidom
from StringIO import StringIO
from django.conf import settings from django.conf import settings
from django.core import serializers from django.core import serializers
from django.db import transaction, connection from django.db import transaction, connection
from django.test import TestCase, TransactionTestCase, Approximate from django.test import TestCase, TransactionTestCase, Approximate
from django.utils import six from django.utils import six
from django.utils.six import StringIO
from django.utils import unittest from django.utils import unittest
from .models import (Category, Author, Article, AuthorProfile, Actor, Movie, from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,

View File

@ -1,10 +1,10 @@
import sys import sys
from StringIO import StringIO
from django.core import management from django.core import management
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.test import TestCase from django.test import TestCase
from django.utils import translation from django.utils import translation
from django.utils.six import StringIO
class CommandTests(TestCase): class CommandTests(TestCase):

View File

@ -3,11 +3,11 @@ A series of tests to establish that the command-line bash completion works.
""" """
import os import os
import sys import sys
import StringIO
from django.conf import settings from django.conf import settings
from django.core.management import ManagementUtility from django.core.management import ManagementUtility
from django.utils import unittest from django.utils import unittest
from django.utils.six import StringIO
class BashCompletionTests(unittest.TestCase): class BashCompletionTests(unittest.TestCase):
@ -20,7 +20,7 @@ class BashCompletionTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.old_DJANGO_AUTO_COMPLETE = os.environ.get('DJANGO_AUTO_COMPLETE') self.old_DJANGO_AUTO_COMPLETE = os.environ.get('DJANGO_AUTO_COMPLETE')
os.environ['DJANGO_AUTO_COMPLETE'] = '1' os.environ['DJANGO_AUTO_COMPLETE'] = '1'
self.output = StringIO.StringIO() self.output = StringIO()
self.old_stdout = sys.stdout self.old_stdout = sys.stdout
sys.stdout = self.output sys.stdout = self.output

View File

@ -1,6 +1,5 @@
from StringIO import StringIO
from django.core.servers.basehttp import ServerHandler from django.core.servers.basehttp import ServerHandler
from django.utils.six import StringIO
from django.utils.unittest import TestCase from django.utils.unittest import TestCase
# #

View File

@ -1,9 +1,8 @@
from StringIO import StringIO
from django.contrib.auth import models from django.contrib.auth import models
from django.contrib.auth.management.commands import changepassword from django.contrib.auth.management.commands import changepassword
from django.core.management import call_command from django.core.management import call_command
from django.test import TestCase from django.test import TestCase
from django.utils.six import StringIO
class MultiDBChangepasswordManagementCommandTestCase(TestCase): class MultiDBChangepasswordManagementCommandTestCase(TestCase):

View File

@ -7,12 +7,12 @@ import hashlib
import json import json
import os import os
import shutil import shutil
from StringIO import StringIO
from django.core.files import temp as tempfile from django.core.files import temp as tempfile
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.http.multipartparser import MultiPartParser from django.http.multipartparser import MultiPartParser
from django.test import TestCase, client from django.test import TestCase, client
from django.utils.six import StringIO
from django.utils import unittest from django.utils import unittest
from . import uploadhandler from . import uploadhandler

View File

@ -3,10 +3,10 @@
import os import os
import re import re
import shutil import shutil
from StringIO import StringIO
from django.core import management from django.core import management
from django.test import TestCase from django.test import TestCase
from django.utils.six import StringIO
LOCALE='de' LOCALE='de'

View File

@ -1,7 +1,6 @@
from StringIO import StringIO
from django.core.management import call_command from django.core.management import call_command
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
from django.utils.six import StringIO
class InspectDBTestCase(TestCase): class InspectDBTestCase(TestCase):

View File

@ -7,7 +7,6 @@ import os
import shutil import shutil
import smtpd import smtpd
import sys import sys
from StringIO import StringIO
import tempfile import tempfile
import threading 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.core.mail.message import BadHeaderError
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.six import StringIO
from django.utils.translation import ugettext_lazy from django.utils.translation import ugettext_lazy

View File

@ -3,7 +3,6 @@
import gzip import gzip
import re import re
import random import random
import StringIO
from django.conf import settings from django.conf import settings
from django.core import mail from django.core import mail
@ -16,6 +15,7 @@ from django.middleware.gzip import GZipMiddleware
from django.test import TestCase, RequestFactory from django.test import TestCase, RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.six.moves import xrange from django.utils.six.moves import xrange
from django.utils.six import StringIO
class CommonMiddlewareTest(TestCase): class CommonMiddlewareTest(TestCase):
def setUp(self): def setUp(self):
@ -526,7 +526,7 @@ class GZipMiddlewareTest(TestCase):
@staticmethod @staticmethod
def decompress(gzipped_string): 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): def test_compress_response(self):
""" """

View File

@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals
import datetime import datetime
import pickle import pickle
from StringIO import StringIO
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User 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 import connections, router, DEFAULT_DB_ALIAS
from django.db.models import signals from django.db.models import signals
from django.test import TestCase from django.test import TestCase
from django.utils.six import StringIO
from .models import Book, Person, Pet, Review, UserProfile from .models import Book, Person, Pet, Review, UserProfile

View File

@ -3,7 +3,6 @@ from __future__ import unicode_literals
import time import time
import warnings import warnings
from datetime import datetime, timedelta from datetime import datetime, timedelta
from StringIO import StringIO
from django.conf import settings from django.conf import settings
from django.core.handlers.wsgi import WSGIRequest, LimitedStream 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.test.utils import str_prefix
from django.utils import unittest from django.utils import unittest
from django.utils.http import cookie_date from django.utils.http import cookie_date
from django.utils.six import StringIO
from django.utils.timezone import utc from django.utils.timezone import utc

View File

@ -12,13 +12,13 @@ if __name__ == '__main__':
import sys import sys
import pkg_resources import pkg_resources
import imp import imp
import StringIO
import os.path import os.path
from django.template import TemplateDoesNotExist, Context from django.template import TemplateDoesNotExist, Context
from django.template.loaders.eggs import Loader as EggLoader from django.template.loaders.eggs import Loader as EggLoader
from django.template import loader from django.template import loader
from django.utils import unittest from django.utils import unittest
from django.utils.six import StringIO
# Mock classes and objects for pkg_resources functions. # Mock classes and objects for pkg_resources functions.
@ -61,8 +61,8 @@ class EggLoaderTest(unittest.TestCase):
self.empty_egg = create_egg("egg_empty", {}) self.empty_egg = create_egg("egg_empty", {})
self.egg_1 = create_egg("egg_1", { self.egg_1 = create_egg("egg_1", {
os.path.normcase('templates/y.html') : StringIO.StringIO("y"), os.path.normcase('templates/y.html') : StringIO("y"),
os.path.normcase('templates/x.txt') : StringIO.StringIO("x"), os.path.normcase('templates/x.txt') : StringIO("x"),
}) })
self._old_installed_apps = settings.INSTALLED_APPS self._old_installed_apps = settings.INSTALLED_APPS
settings.INSTALLED_APPS = [] settings.INSTALLED_APPS = []

View File

@ -493,7 +493,7 @@ __test__ = {"API_TEST": r"""
# Standard doctests do fairly # Standard doctests do fairly
>>> import json >>> import json
>>> from django.utils.xmlutils import SimplerXMLGenerator >>> from django.utils.xmlutils import SimplerXMLGenerator
>>> from StringIO import StringIO >>> from django.utils.six import StringIO
>>> def produce_long(): >>> def produce_long():
... return 42L ... return 42L