Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix unittests that use OS specific linesep. #330

Closed
wants to merge 2 commits into from

2 participants

Michael Manfre Florian Apolloner
Michael Manfre

Many tests in regressiontests.templates fail on Windows because they are expecting a linux \n.

Florian Apolloner
Owner

This fix won't work if a windows user downloads a release tarball… Closing for now, please see the exisiting tickets for discussion.

Florian Apolloner apollo13 closed this September 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
55  tests/regressiontests/templates/custom.py
... ...
@@ -1,5 +1,6 @@
1 1
 from __future__ import absolute_import, unicode_literals
2 2
 
  3
+import os
3 4
 from django import template
4 5
 from django.utils.unittest import TestCase
5 6
 
@@ -109,50 +110,50 @@ def test_inclusion_tags(self):
109 110
         c = template.Context({'value': 42})
110 111
 
111 112
         t = template.Template('{% load custom %}{% inclusion_no_params %}')
112  
-        self.assertEqual(t.render(c), 'inclusion_no_params - Expected result\n')
  113
+        self.assertEqual(t.render(c), 'inclusion_no_params - Expected result' + os.linesep)
113 114
 
114 115
         t = template.Template('{% load custom %}{% inclusion_one_param 37 %}')
115  
-        self.assertEqual(t.render(c), 'inclusion_one_param - Expected result: 37\n')
  116
+        self.assertEqual(t.render(c), 'inclusion_one_param - Expected result: 37' + os.linesep)
116 117
 
117 118
         t = template.Template('{% load custom %}{% inclusion_explicit_no_context 37 %}')
118  
-        self.assertEqual(t.render(c), 'inclusion_explicit_no_context - Expected result: 37\n')
  119
+        self.assertEqual(t.render(c), 'inclusion_explicit_no_context - Expected result: 37' + os.linesep)
119 120
 
120 121
         t = template.Template('{% load custom %}{% inclusion_no_params_with_context %}')
121  
-        self.assertEqual(t.render(c), 'inclusion_no_params_with_context - Expected result (context value: 42)\n')
  122
+        self.assertEqual(t.render(c), 'inclusion_no_params_with_context - Expected result (context value: 42)' + os.linesep)
122 123
 
123 124
         t = template.Template('{% load custom %}{% inclusion_params_and_context 37 %}')
124  
-        self.assertEqual(t.render(c), 'inclusion_params_and_context - Expected result (context value: 42): 37\n')
  125
+        self.assertEqual(t.render(c), 'inclusion_params_and_context - Expected result (context value: 42): 37' + os.linesep)
125 126
 
126 127
         t = template.Template('{% load custom %}{% inclusion_two_params 37 42 %}')
127  
-        self.assertEqual(t.render(c), 'inclusion_two_params - Expected result: 37, 42\n')
  128
+        self.assertEqual(t.render(c), 'inclusion_two_params - Expected result: 37, 42' + os.linesep)
128 129
 
129 130
         t = template.Template('{% load custom %}{% inclusion_one_default 37 %}')
130  
-        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hi\n')
  131
+        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hi' + os.linesep)
131 132
 
132 133
         t = template.Template('{% load custom %}{% inclusion_one_default 37 two="hello" %}')
133  
-        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hello\n')
  134
+        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hello' + os.linesep)
134 135
 
135 136
         t = template.Template('{% load custom %}{% inclusion_one_default one=99 two="hello" %}')
136  
-        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 99, hello\n')
  137
+        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 99, hello' + os.linesep)
137 138
 
138 139
         self.assertRaisesRegexp(template.TemplateSyntaxError,
139 140
             "'inclusion_one_default' received unexpected keyword argument 'three'",
140 141
             template.Template, '{% load custom %}{% inclusion_one_default 99 two="hello" three="foo" %}')
141 142
 
142 143
         t = template.Template('{% load custom %}{% inclusion_one_default 37 42 %}')
143  
-        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, 42\n')
  144
+        self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, 42' + os.linesep)
144 145
 
145 146
         t = template.Template('{% load custom %}{% inclusion_unlimited_args 37 %}')
146  
-        self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, hi\n')
  147
+        self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, hi' + os.linesep)
147 148
 
148 149
         t = template.Template('{% load custom %}{% inclusion_unlimited_args 37 42 56 89 %}')
149  
-        self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, 42, 56, 89\n')
  150
+        self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, 42, 56, 89' + os.linesep)
150 151
 
151 152
         t = template.Template('{% load custom %}{% inclusion_only_unlimited_args %}')
152  
-        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: \n')
  153
+        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: ' + os.linesep)
153 154
 
154 155
         t = template.Template('{% load custom %}{% inclusion_only_unlimited_args 37 42 56 89 %}')
155  
-        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89\n')
  156
+        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89' + os.linesep)
156 157
 
157 158
         self.assertRaisesRegexp(template.TemplateSyntaxError,
158 159
             "'inclusion_two_params' received too many positional arguments",
@@ -171,7 +172,7 @@ def test_inclusion_tags(self):
171 172
             template.Template, '{% load custom %}{% inclusion_unlimited_args %}')
172 173
 
173 174
         t = template.Template('{% load custom %}{% inclusion_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 %}')
174  
-        self.assertEqual(t.render(c), 'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4\n')
  175
+        self.assertEqual(t.render(c), 'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4' + os.linesep)
175 176
 
176 177
         self.assertRaisesRegexp(template.TemplateSyntaxError,
177 178
             "'inclusion_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
@@ -191,40 +192,40 @@ def test_inclusion_tags_from_template(self):
191 192
         c = template.Context({'value': 42})
192 193
 
193 194
         t = template.Template('{% load custom %}{% inclusion_no_params_from_template %}')
194  
-        self.assertEqual(t.render(c), 'inclusion_no_params_from_template - Expected result\n')
  195
+        self.assertEqual(t.render(c), 'inclusion_no_params_from_template - Expected result' + os.linesep)
195 196
 
196 197
         t = template.Template('{% load custom %}{% inclusion_one_param_from_template 37 %}')
197  
-        self.assertEqual(t.render(c), 'inclusion_one_param_from_template - Expected result: 37\n')
  198
+        self.assertEqual(t.render(c), 'inclusion_one_param_from_template - Expected result: 37' + os.linesep)
198 199
 
199 200
         t = template.Template('{% load custom %}{% inclusion_explicit_no_context_from_template 37 %}')
200  
-        self.assertEqual(t.render(c), 'inclusion_explicit_no_context_from_template - Expected result: 37\n')
  201
+        self.assertEqual(t.render(c), 'inclusion_explicit_no_context_from_template - Expected result: 37' + os.linesep)
201 202
 
202 203
         t = template.Template('{% load custom %}{% inclusion_no_params_with_context_from_template %}')
203  
-        self.assertEqual(t.render(c), 'inclusion_no_params_with_context_from_template - Expected result (context value: 42)\n')
  204
+        self.assertEqual(t.render(c), 'inclusion_no_params_with_context_from_template - Expected result (context value: 42)' + os.linesep)
204 205
 
205 206
         t = template.Template('{% load custom %}{% inclusion_params_and_context_from_template 37 %}')
206  
-        self.assertEqual(t.render(c), 'inclusion_params_and_context_from_template - Expected result (context value: 42): 37\n')
  207
+        self.assertEqual(t.render(c), 'inclusion_params_and_context_from_template - Expected result (context value: 42): 37' + os.linesep)
207 208
 
208 209
         t = template.Template('{% load custom %}{% inclusion_two_params_from_template 37 42 %}')
209  
-        self.assertEqual(t.render(c), 'inclusion_two_params_from_template - Expected result: 37, 42\n')
  210
+        self.assertEqual(t.render(c), 'inclusion_two_params_from_template - Expected result: 37, 42' + os.linesep)
210 211
 
211 212
         t = template.Template('{% load custom %}{% inclusion_one_default_from_template 37 %}')
212  
-        self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, hi\n')
  213
+        self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, hi' + os.linesep)
213 214
 
214 215
         t = template.Template('{% load custom %}{% inclusion_one_default_from_template 37 42 %}')
215  
-        self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, 42\n')
  216
+        self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, 42' + os.linesep)
216 217
 
217 218
         t = template.Template('{% load custom %}{% inclusion_unlimited_args_from_template 37 %}')
218  
-        self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, hi\n')
  219
+        self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, hi' + os.linesep)
219 220
 
220 221
         t = template.Template('{% load custom %}{% inclusion_unlimited_args_from_template 37 42 56 89 %}')
221  
-        self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, 42, 56, 89\n')
  222
+        self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, 42, 56, 89' + os.linesep)
222 223
 
223 224
         t = template.Template('{% load custom %}{% inclusion_only_unlimited_args_from_template %}')
224  
-        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: \n')
  225
+        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: ' + os.linesep)
225 226
 
226 227
         t = template.Template('{% load custom %}{% inclusion_only_unlimited_args_from_template 37 42 56 89 %}')
227  
-        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: 37, 42, 56, 89\n')
  228
+        self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: 37, 42, 56, 89' + os.linesep)
228 229
 
229 230
     def test_inclusion_tag_registration(self):
230 231
         # Test that the decorators preserve the decorated function's docstring, name and attributes.
7  tests/regressiontests/templates/response.py
@@ -11,6 +11,7 @@
11 11
 from django.template.response import (TemplateResponse, SimpleTemplateResponse,
12 12
                                       ContentNotRenderedError)
13 13
 from django.test.utils import override_settings
  14
+from django.utils.encoding import force_bytes
14 15
 
15 16
 def test_processor(request):
16 17
     return {'processors': 'yes'}
@@ -31,12 +32,12 @@ def _response(self, template='foo', *args, **kwargs):
31 32
     def test_template_resolving(self):
32 33
         response = SimpleTemplateResponse('first/test.html')
33 34
         response.render()
34  
-        self.assertEqual(response.content, b'First template\n')
  35
+        self.assertEqual(response.content, b'First template' + force_bytes(os.linesep))
35 36
 
36 37
         templates = ['foo.html', 'second/test.html', 'first/test.html']
37 38
         response = SimpleTemplateResponse(templates)
38 39
         response.render()
39  
-        self.assertEqual(response.content, b'Second template\n')
  40
+        self.assertEqual(response.content, b'Second template' + force_bytes(os.linesep))
40 41
 
41 42
         response = self._response()
42 43
         response.render()
@@ -142,7 +143,7 @@ def post2(obj):
142 143
 
143 144
         # When the content is rendered, all the callbacks are invoked, too.
144 145
         response.render()
145  
-        self.assertEqual(response.content, b'First template\n')
  146
+        self.assertEqual(response.content, b'First template' + force_bytes(os.linesep))
146 147
         self.assertEqual(post, ['post1','post2'])
147 148
 
148 149
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.