summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Rogaski <mrogaski@pobox.com>2017-08-28 12:40:27 -0400
committerTim Graham <timograham@gmail.com>2017-08-31 07:33:01 -0400
commit80a0016c49331bf0a14ef76e714acbff6c6640bd (patch)
tree3bb54b3aada8e44f5e13874c100b22a4ebac4158 /tests
parent046b8c80ce76ed1d410910aa92f67c405b8a15ba (diff)
[1.11.x] Fixed #28487 -- Fixed runserver crash with non-Unicode system encodings on Python 2 + Windows.
Diffstat (limited to 'tests')
-rw-r--r--tests/utils_tests/test_autoreload.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index 78206135fa..cab48309fb 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -5,13 +5,14 @@ import os
import shutil
import sys
import tempfile
+import unittest
from importlib import import_module
from django import conf
from django.contrib import admin
from django.test import SimpleTestCase, mock, override_settings
from django.test.utils import extend_sys_path
-from django.utils import autoreload
+from django.utils import autoreload, six
from django.utils._os import npath, upath
from django.utils.six.moves import _thread
from django.utils.translation import trans_real
@@ -258,6 +259,13 @@ class ResetTranslationsTests(SimpleTestCase):
class TestRestartWithReloader(SimpleTestCase):
+ def setUp(self):
+ self._orig_environ = os.environ.copy()
+
+ def tearDown(self):
+ os.environ.clear()
+ os.environ.update(self._orig_environ)
+
def test_environment(self):
""""
With Python 2 on Windows, restart_with_reloader() coerces environment
@@ -268,3 +276,24 @@ class TestRestartWithReloader(SimpleTestCase):
os.environ['SPAM'] = 'spam'
with mock.patch.object(sys, 'argv', ['-c', 'pass']):
autoreload.restart_with_reloader()
+
+ @unittest.skipUnless(six.PY2 and sys.platform == 'win32', 'This is a Python 2 + Windows-specific issue.')
+ def test_environment_decoding(self):
+ """The system encoding is used for decoding."""
+ os.environ['SPAM'] = 'spam'
+ os.environ['EGGS'] = b'\xc6u vi komprenas?'
+ with mock.patch('locale.getdefaultlocale') as default_locale:
+ # Latin-3 is the correct mapping.
+ default_locale.return_value = ('eo', 'latin3')
+ with mock.patch.object(sys, 'argv', ['-c', 'pass']):
+ autoreload.restart_with_reloader()
+ # CP1252 interprets latin3's C circumflex as AE ligature.
+ # It's incorrect but doesn't raise an error.
+ default_locale.return_value = ('en_US', 'cp1252')
+ with mock.patch.object(sys, 'argv', ['-c', 'pass']):
+ autoreload.restart_with_reloader()
+ # Interpreting the string as UTF-8 is fatal.
+ with self.assertRaises(UnicodeDecodeError):
+ default_locale.return_value = ('en_US', 'utf-8')
+ with mock.patch.object(sys, 'argv', ['-c', 'pass']):
+ autoreload.restart_with_reloader()