summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-05-05 19:47:03 +0200
committerClaude Paroz <claude@2xlibre.net>2012-05-05 21:41:44 +0200
commitd7dfab59ead97b35c6f6786784225f377783e376 (patch)
treed357f2b94ef010d60e9ad6602bda5537f1a28b8d /tests
parent1583d402240d88ad2a4acc024d348a21657ccaba (diff)
Replaced cStringIO.StringIO by io.BytesIO.
Also replaced StringIO.StringIO by BytesIO in some other appropriate places. StringIO is not available in Python 3.
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/invalid_models/tests.py4
-rw-r--r--tests/modeltests/model_forms/tests.py13
-rw-r--r--tests/regressiontests/file_storage/tests.py11
-rw-r--r--tests/regressiontests/fixtures_regress/tests.py29
-rw-r--r--tests/regressiontests/i18n/commands/compilation.py11
-rw-r--r--tests/regressiontests/m2m_through_regress/tests.py11
-rw-r--r--tests/regressiontests/serializers_regress/tests.py7
7 files changed, 29 insertions, 57 deletions
diff --git a/tests/modeltests/invalid_models/tests.py b/tests/modeltests/invalid_models/tests.py
index dfc6199624..9d7adb045c 100644
--- a/tests/modeltests/invalid_models/tests.py
+++ b/tests/modeltests/invalid_models/tests.py
@@ -1,6 +1,6 @@
import copy
import sys
-from cStringIO import StringIO
+from io import BytesIO
from django.core.management.validation import get_validation_errors
from django.db.models.loading import cache, load_app
@@ -16,7 +16,7 @@ class InvalidModelTestCase(unittest.TestCase):
# coloring attached (makes matching the results easier). We restore
# sys.stderr afterwards.
self.old_stdout = sys.stdout
- self.stdout = StringIO()
+ self.stdout = BytesIO()
sys.stdout = self.stdout
# This test adds dummy applications to the app cache. These
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index 47902f3a83..fdaae5b852 100644
--- a/tests/modeltests/model_forms/tests.py
+++ b/tests/modeltests/model_forms/tests.py
@@ -1372,19 +1372,6 @@ class OldFormForXTests(TestCase):
self.assertEqual(instance.image.name, 'foo/test4.png')
instance.delete()
- # Test image field when cStringIO is not available
- from django.forms import fields
- from StringIO import StringIO
- old_StringIO = fields.StringIO
- fields.StringIO = StringIO
- try:
- f = ImageFileForm(
- data={'description': u'An image'},
- files={'image': SimpleUploadedFile('test.png', image_data)})
- self.assertEqual(f.is_valid(), True)
- finally:
- fields.StringIO = old_StringIO
-
def test_media_on_modelform(self):
# Similar to a regular Form class you can define custom media to be used on
# the ModelForm.
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index c28b019c84..ce64c5de23 100644
--- a/tests/regressiontests/file_storage/tests.py
+++ b/tests/regressiontests/file_storage/tests.py
@@ -7,10 +7,7 @@ import shutil
import tempfile
import time
from datetime import datetime, timedelta
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
+from io import BytesIO
try:
import threading
@@ -483,7 +480,7 @@ class DimensionClosingBug(unittest.TestCase):
"""
Open files passed into get_image_dimensions() should stay opened.
"""
- empty_io = StringIO()
+ empty_io = BytesIO()
try:
get_image_dimensions(empty_io)
finally:
@@ -557,10 +554,10 @@ class NoNameFileTestCase(unittest.TestCase):
urllib.urlopen()
"""
def test_noname_file_default_name(self):
- self.assertEqual(File(StringIO('A file with no name')).name, None)
+ self.assertEqual(File(BytesIO(b'A file with no name')).name, None)
def test_noname_file_get_size(self):
- self.assertEqual(File(StringIO('A file with no name')).size, 19)
+ self.assertEqual(File(BytesIO(b'A file with no name')).size, 19)
class FileLikeObjectTestCase(LiveServerBase):
"""
diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
index ed8b404788..5c6f758b66 100644
--- a/tests/regressiontests/fixtures_regress/tests.py
+++ b/tests/regressiontests/fixtures_regress/tests.py
@@ -4,10 +4,7 @@ from __future__ import absolute_import
import os
import re
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
+from io import BytesIO
from django.core import management
from django.core.management.base import CommandError
@@ -119,7 +116,7 @@ class TestFixtures(TestCase):
Test for ticket #4371 -- Loading data of an unknown format should fail
Validate that error conditions are caught correctly
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'bad_fixture1.unkn',
@@ -138,7 +135,7 @@ class TestFixtures(TestCase):
using explicit filename.
Validate that error conditions are caught correctly
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'bad_fixture2.xml',
@@ -157,7 +154,7 @@ class TestFixtures(TestCase):
without file extension.
Validate that error conditions are caught correctly
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'bad_fixture2',
@@ -175,7 +172,7 @@ class TestFixtures(TestCase):
Test for ticket #4371 -- Loading a fixture file with no data returns an error.
Validate that error conditions are caught correctly
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'empty',
@@ -194,7 +191,7 @@ class TestFixtures(TestCase):
loading is aborted.
Validate that error conditions are caught correctly
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'empty',
@@ -211,7 +208,7 @@ class TestFixtures(TestCase):
"""
(Regression for #9011 - error message is correct)
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'bad_fixture2',
@@ -317,7 +314,7 @@ class TestFixtures(TestCase):
)
animal.save()
- stdout = StringIO()
+ stdout = BytesIO()
management.call_command(
'dumpdata',
'fixtures_regress.animal',
@@ -346,7 +343,7 @@ class TestFixtures(TestCase):
"""
Regression for #11428 - Proxy models aren't included when you dumpdata
"""
- stdout = StringIO()
+ stdout = BytesIO()
# Create an instance of the concrete class
widget = Widget.objects.create(name='grommet')
management.call_command(
@@ -379,7 +376,7 @@ class TestFixtures(TestCase):
"""
Regression for #3615 - Ensure data with nonexistent child key references raises error
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
'forward_ref_bad_data.json',
@@ -414,7 +411,7 @@ class TestFixtures(TestCase):
"""
Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
"""
- stderr = StringIO()
+ stderr = BytesIO()
management.call_command(
'loaddata',
verbosity=0,
@@ -426,7 +423,7 @@ class TestFixtures(TestCase):
)
def test_loaddata_not_existant_fixture_file(self):
- stdout_output = StringIO()
+ stdout_output = BytesIO()
management.call_command(
'loaddata',
'this_fixture_doesnt_exist',
@@ -511,7 +508,7 @@ class NaturalKeyFixtureTests(TestCase):
commit=False
)
- stdout = StringIO()
+ stdout = BytesIO()
management.call_command(
'dumpdata',
'fixtures_regress.book',
diff --git a/tests/regressiontests/i18n/commands/compilation.py b/tests/regressiontests/i18n/commands/compilation.py
index 1f38910b61..039e463d0b 100644
--- a/tests/regressiontests/i18n/commands/compilation.py
+++ b/tests/regressiontests/i18n/commands/compilation.py
@@ -1,8 +1,5 @@
import os
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
+from io import BytesIO
from django.core.management import CommandError
from django.core.management.commands.compilemessages import compile_messages
@@ -31,7 +28,7 @@ class PoFileTests(MessageCompilationTests):
# We don't use the django.core.management infrastructure (call_command()
# et al) because CommandError's cause exit(1) there. We test the
# underlying compile_messages function instead
- out = StringIO()
+ out = BytesIO()
self.assertRaises(CommandError, compile_messages, out, locale=self.LOCALE)
self.assertFalse(os.path.exists(self.MO_FILE))
@@ -51,7 +48,7 @@ class PoFileContentsTests(MessageCompilationTests):
# We don't use the django.core.management infrastructure (call_command()
# et al) because CommandError's cause exit(1) there. We test the
# underlying compile_messages function instead
- out = StringIO()
+ out = BytesIO()
compile_messages(out, locale=self.LOCALE)
self.assertTrue(os.path.exists(self.MO_FILE))
@@ -70,7 +67,7 @@ class PercentRenderingTests(MessageCompilationTests):
# We don't use the django.core.management infrastructure (call_command()
# et al) because CommandError's cause exit(1) there. We test the
# underlying compile_messages function instead
- out = StringIO()
+ out = BytesIO()
compile_messages(out, locale=self.LOCALE)
with translation.override(self.LOCALE):
t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
diff --git a/tests/regressiontests/m2m_through_regress/tests.py b/tests/regressiontests/m2m_through_regress/tests.py
index 1c188d05c3..73a13654e7 100644
--- a/tests/regressiontests/m2m_through_regress/tests.py
+++ b/tests/regressiontests/m2m_through_regress/tests.py
@@ -1,9 +1,6 @@
from __future__ import absolute_import
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
+from io import BytesIO
from django.core import management
from django.contrib.auth.models import User
@@ -73,11 +70,11 @@ class M2MThroughTestCase(TestCase):
pks = {"p_pk": p.pk, "g_pk": g.pk, "m_pk": m.pk}
- out = StringIO()
+ out = BytesIO()
management.call_command("dumpdata", "m2m_through_regress", format="json", stdout=out)
self.assertEqual(out.getvalue().strip(), """[{"pk": %(m_pk)s, "model": "m2m_through_regress.membership", "fields": {"person": %(p_pk)s, "price": 100, "group": %(g_pk)s}}, {"pk": %(p_pk)s, "model": "m2m_through_regress.person", "fields": {"name": "Bob"}}, {"pk": %(g_pk)s, "model": "m2m_through_regress.group", "fields": {"name": "Roll"}}]""" % pks)
- out = StringIO()
+ out = BytesIO()
management.call_command("dumpdata", "m2m_through_regress", format="xml",
indent=2, stdout=out)
self.assertEqual(out.getvalue().strip(), """
@@ -145,6 +142,6 @@ class ThroughLoadDataTestCase(TestCase):
def test_sequence_creation(self):
"Check that sequences on an m2m_through are created for the through model, not a phantom auto-generated m2m table. Refs #11107"
- out = StringIO()
+ out = BytesIO()
management.call_command("dumpdata", "m2m_through_regress", format="json", stdout=out)
self.assertEqual(out.getvalue().strip(), """[{"pk": 1, "model": "m2m_through_regress.usermembership", "fields": {"price": 100, "group": 1, "user": 1}}, {"pk": 1, "model": "m2m_through_regress.person", "fields": {"name": "Guido"}}, {"pk": 1, "model": "m2m_through_regress.group", "fields": {"name": "Python Core Group"}}]""")
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index 289db05c71..0c0c59f136 100644
--- a/tests/regressiontests/serializers_regress/tests.py
+++ b/tests/regressiontests/serializers_regress/tests.py
@@ -10,10 +10,7 @@ from __future__ import absolute_import
import datetime
import decimal
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
+from io import BytesIO
try:
import yaml
@@ -504,7 +501,7 @@ def streamTest(format, self):
obj.save_base(raw=True)
# Serialize the test database to a stream
- stream = StringIO()
+ stream = BytesIO()
serializers.serialize(format, [obj], indent=2, stream=stream)
# Serialize normally for a comparison