Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #26731 -- Allowed bytestring output with management commands on Python 2 #6755

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion django/core/management/base.py
Expand Up @@ -91,7 +91,7 @@ def style_func(self, style_func):
else:
self._style_func = lambda x: x

def __init__(self, out, style_func=None, ending='\n'):
def __init__(self, out, style_func=None, ending=str('\n')):
self._out = out
self.style_func = None
self.ending = ending
Expand Down
18 changes: 17 additions & 1 deletion tests/user_commands/tests.py
@@ -1,17 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
import unittest

from admin_scripts.tests import AdminScriptTestCase

from django.apps import apps
from django.core import management
from django.core.management import BaseCommand, CommandError, find_commands
from django.core.management.base import OutputWrapper
from django.core.management.utils import find_command, popen_wrapper
from django.db import connection
from django.test import SimpleTestCase, mock, override_settings
from django.test.utils import captured_stderr, extend_sys_path
from django.utils import translation
from django.utils._os import upath
from django.utils.six import StringIO
from django.utils.six import PY2, StringIO

from .management.commands import dance

Expand Down Expand Up @@ -194,3 +199,14 @@ class UtilsTests(SimpleTestCase):
def test_no_existent_external_program(self):
with self.assertRaises(CommandError):
popen_wrapper(['a_42_command_that_doesnt_exist_42'])

@unittest.skipUnless(PY2, "Python 2 only.")
def test_outputwrapper_bytestring(self):
"""
OutputWrapper should accept bytestrings on Python 2.
"""
bytestring = '£'.encode('utf-8')
out = StringIO()
ow = OutputWrapper(out)
ow.write(bytestring)
self.assertEqual(out.getvalue(), bytestring + b'\n')