Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Used six.StringIO to simulate stdout buffer in tests

  • Loading branch information...
commit 3eb28d011927a657cad1bf4463611a72c6bb1325 1 parent 09c5898
@claudep claudep authored
View
4 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 @@ def setUp(self):
# 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
View
10 tests/regressiontests/fixtures_regress/tests.py
@@ -4,7 +4,6 @@
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.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 @@ def test_dumpdata_uses_default_manager(self):
)
animal.save()
- stdout = BytesIO()
+ stdout = StringIO()
management.call_command(
'dumpdata',
'fixtures_regress.animal',
@@ -305,7 +305,7 @@ def test_proxy_model_included(self):
"""
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 @@ def test_loaddata_no_fixture_specified(self):
)
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 @@ def test_nk_on_serialize(self):
commit=False
)
- stdout = BytesIO()
+ stdout = StringIO()
management.call_command(
'dumpdata',
'fixtures_regress.book',
View
9 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 @@ def test_serialization(self):
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"}}]""")
View
5 tests/regressiontests/staticfiles_tests/tests.py
@@ -7,7 +7,6 @@
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 @@ def test_all_files(self):
"""
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()]
Please sign in to comment.
Something went wrong with that request. Please try again.