Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix unittests that use OS specific linesep. #330

Closed
wants to merge 2 commits into from

2 participants

@manfre
Collaborator

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

@apollo13
Owner

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

@apollo13 apollo13 closed this
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.
View
55 tests/regressiontests/templates/custom.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals
+import os
from django import template
from django.utils.unittest import TestCase
@@ -109,50 +110,50 @@ def test_inclusion_tags(self):
c = template.Context({'value': 42})
t = template.Template('{% load custom %}{% inclusion_no_params %}')
- self.assertEqual(t.render(c), 'inclusion_no_params - Expected result\n')
+ self.assertEqual(t.render(c), 'inclusion_no_params - Expected result' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_param 37 %}')
- self.assertEqual(t.render(c), 'inclusion_one_param - Expected result: 37\n')
+ self.assertEqual(t.render(c), 'inclusion_one_param - Expected result: 37' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_explicit_no_context 37 %}')
- self.assertEqual(t.render(c), 'inclusion_explicit_no_context - Expected result: 37\n')
+ self.assertEqual(t.render(c), 'inclusion_explicit_no_context - Expected result: 37' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_no_params_with_context %}')
- self.assertEqual(t.render(c), 'inclusion_no_params_with_context - Expected result (context value: 42)\n')
+ self.assertEqual(t.render(c), 'inclusion_no_params_with_context - Expected result (context value: 42)' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_params_and_context 37 %}')
- self.assertEqual(t.render(c), 'inclusion_params_and_context - Expected result (context value: 42): 37\n')
+ self.assertEqual(t.render(c), 'inclusion_params_and_context - Expected result (context value: 42): 37' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_two_params 37 42 %}')
- self.assertEqual(t.render(c), 'inclusion_two_params - Expected result: 37, 42\n')
+ self.assertEqual(t.render(c), 'inclusion_two_params - Expected result: 37, 42' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_default 37 %}')
- self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hi\n')
+ self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hi' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_default 37 two="hello" %}')
- self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hello\n')
+ self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, hello' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_default one=99 two="hello" %}')
- self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 99, hello\n')
+ self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 99, hello' + os.linesep)
self.assertRaisesRegexp(template.TemplateSyntaxError,
"'inclusion_one_default' received unexpected keyword argument 'three'",
template.Template, '{% load custom %}{% inclusion_one_default 99 two="hello" three="foo" %}')
t = template.Template('{% load custom %}{% inclusion_one_default 37 42 %}')
- self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, 42\n')
+ self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 37, 42' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_unlimited_args 37 %}')
- self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, hi\n')
+ self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, hi' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_unlimited_args 37 42 56 89 %}')
- self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, 42, 56, 89\n')
+ self.assertEqual(t.render(c), 'inclusion_unlimited_args - Expected result: 37, 42, 56, 89' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_only_unlimited_args %}')
- self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: \n')
+ self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: ' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_only_unlimited_args 37 42 56 89 %}')
- self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89\n')
+ self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89' + os.linesep)
self.assertRaisesRegexp(template.TemplateSyntaxError,
"'inclusion_two_params' received too many positional arguments",
@@ -171,7 +172,7 @@ def test_inclusion_tags(self):
template.Template, '{% load custom %}{% inclusion_unlimited_args %}')
t = template.Template('{% load custom %}{% inclusion_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 %}')
- self.assertEqual(t.render(c), 'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4\n')
+ self.assertEqual(t.render(c), 'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4' + os.linesep)
self.assertRaisesRegexp(template.TemplateSyntaxError,
"'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):
c = template.Context({'value': 42})
t = template.Template('{% load custom %}{% inclusion_no_params_from_template %}')
- self.assertEqual(t.render(c), 'inclusion_no_params_from_template - Expected result\n')
+ self.assertEqual(t.render(c), 'inclusion_no_params_from_template - Expected result' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_param_from_template 37 %}')
- self.assertEqual(t.render(c), 'inclusion_one_param_from_template - Expected result: 37\n')
+ self.assertEqual(t.render(c), 'inclusion_one_param_from_template - Expected result: 37' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_explicit_no_context_from_template 37 %}')
- self.assertEqual(t.render(c), 'inclusion_explicit_no_context_from_template - Expected result: 37\n')
+ self.assertEqual(t.render(c), 'inclusion_explicit_no_context_from_template - Expected result: 37' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_no_params_with_context_from_template %}')
- self.assertEqual(t.render(c), 'inclusion_no_params_with_context_from_template - Expected result (context value: 42)\n')
+ self.assertEqual(t.render(c), 'inclusion_no_params_with_context_from_template - Expected result (context value: 42)' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_params_and_context_from_template 37 %}')
- self.assertEqual(t.render(c), 'inclusion_params_and_context_from_template - Expected result (context value: 42): 37\n')
+ self.assertEqual(t.render(c), 'inclusion_params_and_context_from_template - Expected result (context value: 42): 37' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_two_params_from_template 37 42 %}')
- self.assertEqual(t.render(c), 'inclusion_two_params_from_template - Expected result: 37, 42\n')
+ self.assertEqual(t.render(c), 'inclusion_two_params_from_template - Expected result: 37, 42' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_default_from_template 37 %}')
- self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, hi\n')
+ self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, hi' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_one_default_from_template 37 42 %}')
- self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, 42\n')
+ self.assertEqual(t.render(c), 'inclusion_one_default_from_template - Expected result: 37, 42' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_unlimited_args_from_template 37 %}')
- self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, hi\n')
+ self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, hi' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_unlimited_args_from_template 37 42 56 89 %}')
- self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, 42, 56, 89\n')
+ self.assertEqual(t.render(c), 'inclusion_unlimited_args_from_template - Expected result: 37, 42, 56, 89' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_only_unlimited_args_from_template %}')
- self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: \n')
+ self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: ' + os.linesep)
t = template.Template('{% load custom %}{% inclusion_only_unlimited_args_from_template 37 42 56 89 %}')
- self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: 37, 42, 56, 89\n')
+ self.assertEqual(t.render(c), 'inclusion_only_unlimited_args_from_template - Expected result: 37, 42, 56, 89' + os.linesep)
def test_inclusion_tag_registration(self):
# Test that the decorators preserve the decorated function's docstring, name and attributes.
View
7 tests/regressiontests/templates/response.py
@@ -11,6 +11,7 @@
from django.template.response import (TemplateResponse, SimpleTemplateResponse,
ContentNotRenderedError)
from django.test.utils import override_settings
+from django.utils.encoding import force_bytes
def test_processor(request):
return {'processors': 'yes'}
@@ -31,12 +32,12 @@ def _response(self, template='foo', *args, **kwargs):
def test_template_resolving(self):
response = SimpleTemplateResponse('first/test.html')
response.render()
- self.assertEqual(response.content, b'First template\n')
+ self.assertEqual(response.content, b'First template' + force_bytes(os.linesep))
templates = ['foo.html', 'second/test.html', 'first/test.html']
response = SimpleTemplateResponse(templates)
response.render()
- self.assertEqual(response.content, b'Second template\n')
+ self.assertEqual(response.content, b'Second template' + force_bytes(os.linesep))
response = self._response()
response.render()
@@ -142,7 +143,7 @@ def post2(obj):
# When the content is rendered, all the callbacks are invoked, too.
response.render()
- self.assertEqual(response.content, b'First template\n')
+ self.assertEqual(response.content, b'First template' + force_bytes(os.linesep))
self.assertEqual(post, ['post1','post2'])
Something went wrong with that request. Please try again.