diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2013-09-06 21:03:46 +0200 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2013-09-06 21:03:46 +0200 |
| commit | 85359ec9a4514087e2cc666b77eb635aacba5073 (patch) | |
| tree | dadff0704a02dc3f0cb1aaa2351265f3a07adadf /tests/utils_tests/test_encoding.py | |
| parent | cc957cb16cfdad7e6c9e97dc885fc415abbf5eaa (diff) | |
| parent | 2326dedde81c59950d2b1e0653a837e1d7019acd (diff) | |
Merge branch 't20812'
Diffstat (limited to 'tests/utils_tests/test_encoding.py')
| -rw-r--r-- | tests/utils_tests/test_encoding.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py index 5730eca6d5..81a4c4f5da 100644 --- a/tests/utils_tests/test_encoding.py +++ b/tests/utils_tests/test_encoding.py @@ -4,10 +4,25 @@ from __future__ import unicode_literals import unittest import datetime -from django.utils.encoding import force_bytes, filepath_to_uri +from django.utils import six +from django.utils.encoding import force_bytes, force_text, filepath_to_uri class TestEncodingUtils(unittest.TestCase): + def test_force_text_exception(self): + """ + Check that broken __unicode__/__str__ actually raises an error. + """ + class MyString(object): + def __str__(self): + return b'\xc3\xb6\xc3\xa4\xc3\xbc' + + __unicode__ = __str__ + + # str(s) raises a TypeError on python 3 if the result is not a text type. + # python 2 fails when it tries converting from str to unicode (via ASCII). + exception = TypeError if six.PY3 else UnicodeError + self.assertRaises(exception, force_text, MyString()) def test_force_bytes_exception(self): """ |
