diff --git a/tests/modeltests/invalid_models/tests.py b/tests/modeltests/invalid_models/tests.py index 9d7adb045c..e1fc68743e 100644 --- a/tests/modeltests/invalid_models/tests.py +++ b/tests/modeltests/invalid_models/tests.py @@ -1,11 +1,11 @@ import copy import sys -from io import BytesIO from django.core.management.validation import get_validation_errors from django.db.models.loading import cache, load_app from django.utils import unittest +from django.utils.six import StringIO class InvalidModelTestCase(unittest.TestCase): @@ -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 = BytesIO() + self.stdout = StringIO() sys.stdout = self.stdout # This test adds dummy applications to the app cache. These diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index ab93341699..41be31ccd7 100644 --- a/tests/regressiontests/fixtures_regress/tests.py +++ b/tests/regressiontests/fixtures_regress/tests.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, unicode_literals import os import re -from io import BytesIO from django.core import management from django.core.management.base import CommandError @@ -14,6 +13,7 @@ from django.db.models import signals from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature) from django.test.utils import override_settings +from django.utils.six import StringIO from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget, Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3, @@ -276,7 +276,7 @@ class TestFixtures(TestCase): ) animal.save() - stdout = BytesIO() + stdout = StringIO() management.call_command( 'dumpdata', 'fixtures_regress.animal', @@ -305,7 +305,7 @@ class TestFixtures(TestCase): """ Regression for #11428 - Proxy models aren't included when you dumpdata """ - stdout = BytesIO() + stdout = StringIO() # Create an instance of the concrete class widget = Widget.objects.create(name='grommet') management.call_command( @@ -380,7 +380,7 @@ class TestFixtures(TestCase): ) def test_loaddata_not_existant_fixture_file(self): - stdout_output = BytesIO() + stdout_output = StringIO() management.call_command( 'loaddata', 'this_fixture_doesnt_exist', @@ -465,7 +465,7 @@ class NaturalKeyFixtureTests(TestCase): commit=False ) - stdout = BytesIO() + stdout = StringIO() management.call_command( 'dumpdata', 'fixtures_regress.book', diff --git a/tests/regressiontests/m2m_through_regress/tests.py b/tests/regressiontests/m2m_through_regress/tests.py index 73a13654e7..458c194f89 100644 --- a/tests/regressiontests/m2m_through_regress/tests.py +++ b/tests/regressiontests/m2m_through_regress/tests.py @@ -1,10 +1,9 @@ from __future__ import absolute_import -from io import BytesIO - from django.core import management from django.contrib.auth.models import User from django.test import TestCase +from django.utils.six import StringIO from .models import (Person, Group, Membership, UserMembership, Car, Driver, CarDriver) @@ -70,11 +69,11 @@ class M2MThroughTestCase(TestCase): pks = {"p_pk": p.pk, "g_pk": g.pk, "m_pk": m.pk} - out = BytesIO() + out = StringIO() 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 = BytesIO() + out = StringIO() management.call_command("dumpdata", "m2m_through_regress", format="xml", indent=2, stdout=out) self.assertEqual(out.getvalue().strip(), """ @@ -142,6 +141,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 = BytesIO() + out = StringIO() 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/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 19951f100b..d68f211535 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -7,7 +7,6 @@ import posixpath import shutil import sys import tempfile -from io import BytesIO from django.template import loader, Context from django.conf import settings @@ -194,7 +193,7 @@ class TestFindStatic(CollectionTestCase, TestDefaults): Test ``findstatic`` management command. """ def _get_file(self, filepath): - out = BytesIO() + out = six.StringIO() call_command('findstatic', filepath, all=False, verbosity=0, stdout=out) out.seek(0) lines = [l.strip() for l in out.readlines()] @@ -206,7 +205,7 @@ class TestFindStatic(CollectionTestCase, TestDefaults): """ Test that findstatic returns all candidate files if run without --first. """ - out = BytesIO() + out = six.StringIO() call_command('findstatic', 'test/file.txt', verbosity=0, stdout=out) out.seek(0) lines = [l.strip() for l in out.readlines()]