Skip to content

Commit 96f41fd

Browse files
Use imported views to expose python 2.6 bug. Refs encode#943
1 parent 4d22a65 commit 96f41fd

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

rest_framework/tests/description.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -- coding: utf-8 --
2+
3+
# Apparently there is a python 2.6 issue where docstrings of imported view classes
4+
# do not retain their encoding information even if a module has a proper
5+
# encoding declaration at the top of its source file. Therefore for tests
6+
# to catch unicode related errors, a mock view has to be declared in a separate
7+
# module.
8+
9+
from rest_framework.views import APIView
10+
11+
12+
# test strings snatched from http://www.columbia.edu/~fdc/utf8/,
13+
# http://winrus.com/utf8-jap.htm and memory
14+
UTF8_TEST_DOCSTRING = (
15+
'zażółć gęślą jaźń'
16+
'Sîne klâwen durh die wolken sint geslagen'
17+
'Τη γλώσσα μου έδωσαν ελληνική'
18+
'யாமறிந்த மொழிகளிலே தமிழ்மொழி'
19+
'На берегу пустынных волн'
20+
'てすと'
21+
'アイウエオカキクケコサシスセソタチツテ'
22+
)
23+
24+
25+
class ViewWithNonASCIICharactersInDocstring(APIView):
26+
__doc__ = UTF8_TEST_DOCSTRING

rest_framework/tests/test_description.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
from __future__ import unicode_literals
44
from django.test import TestCase
5-
from rest_framework.views import APIView
65
from rest_framework.compat import apply_markdown, smart_text
6+
from rest_framework.views import APIView
7+
from rest_framework.tests.description import ViewWithNonASCIICharactersInDocstring
8+
from rest_framework.tests.description import UTF8_TEST_DOCSTRING
79
from rest_framework.utils.formatting import get_view_name, get_view_description
810

911
# We check that docstrings get nicely un-indented.
@@ -49,28 +51,6 @@
4951
<h2 id="hash-style-header">hash style header</h2>"""
5052

5153

52-
# test strings snatched from http://www.columbia.edu/~fdc/utf8/,
53-
# http://winrus.com/utf8-jap.htm and memory
54-
UTF8_TEST_DOCSTRING = (
55-
'zażółć gęślą jaźń'
56-
'Sîne klâwen durh die wolken sint geslagen'
57-
'Τη γλώσσα μου έδωσαν ελληνική'
58-
'யாமறிந்த மொழிகளிலே தமிழ்மொழி'
59-
'На берегу пустынных волн'
60-
'てすと'
61-
'アイウエオカキクケコサシスセソタチツテ'
62-
)
63-
64-
65-
# Apparently there is an issue where docstrings of imported view classes
66-
# do not retain their encoding information even if a module has a proper
67-
# encoding declaration at the top of its source file. Therefore for tests
68-
# to catch unicode related errors, a mock view has to be declared in a separate
69-
# module.
70-
class ViewWithNonASCIICharactersInDocstring(APIView):
71-
__doc__ = UTF8_TEST_DOCSTRING
72-
73-
7454
class TestViewNamesAndDescriptions(TestCase):
7555
def test_view_name_uses_class_name(self):
7656
"""

0 commit comments

Comments
 (0)