mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[py3k] Silence many warnings while running the tests.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django import template
|
||||
from django.utils import six
|
||||
from django.utils.unittest import TestCase
|
||||
|
||||
from .templatetags import custom
|
||||
@@ -51,7 +52,7 @@ class CustomTagTests(TestCase):
|
||||
t = template.Template('{% load custom %}{% simple_one_default one=99 two="hello" %}')
|
||||
self.assertEqual(t.render(c), 'simple_one_default - Expected result: 99, hello')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'simple_one_default' received unexpected keyword argument 'three'",
|
||||
template.Template, '{% load custom %}{% simple_one_default 99 two="hello" three="foo" %}')
|
||||
|
||||
@@ -70,22 +71,22 @@ class CustomTagTests(TestCase):
|
||||
t = template.Template('{% load custom %}{% simple_only_unlimited_args 37 42 56 89 %}')
|
||||
self.assertEqual(t.render(c), 'simple_only_unlimited_args - Expected result: 37, 42, 56, 89')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'simple_two_params' received too many positional arguments",
|
||||
template.Template, '{% load custom %}{% simple_two_params 37 42 56 %}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'simple_one_default' received too many positional arguments",
|
||||
template.Template, '{% load custom %}{% simple_one_default 37 42 56 %}')
|
||||
|
||||
t = template.Template('{% load custom %}{% simple_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 %}')
|
||||
self.assertEqual(t.render(c), 'simple_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'simple_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
|
||||
template.Template, '{% load custom %}{% simple_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3 %}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'simple_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'",
|
||||
template.Template, '{% load custom %}{% simple_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled" %}')
|
||||
|
||||
@@ -101,7 +102,7 @@ class CustomTagTests(TestCase):
|
||||
|
||||
def test_simple_tag_missing_context(self):
|
||||
# The 'context' parameter must be present when takes_context is True
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'simple_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
|
||||
template.Template, '{% load custom %}{% simple_tag_without_context_parameter 123 %}')
|
||||
|
||||
@@ -135,7 +136,7 @@ class CustomTagTests(TestCase):
|
||||
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.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_one_default' received unexpected keyword argument 'three'",
|
||||
template.Template, '{% load custom %}{% inclusion_one_default 99 two="hello" three="foo" %}')
|
||||
|
||||
@@ -154,36 +155,36 @@ class CustomTagTests(TestCase):
|
||||
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.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_two_params' received too many positional arguments",
|
||||
template.Template, '{% load custom %}{% inclusion_two_params 37 42 56 %}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_one_default' received too many positional arguments",
|
||||
template.Template, '{% load custom %}{% inclusion_one_default 37 42 56 %}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_one_default' did not receive value\(s\) for the argument\(s\): 'one'",
|
||||
template.Template, '{% load custom %}{% inclusion_one_default %}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_unlimited_args' did not receive value\(s\) for the argument\(s\): 'one'",
|
||||
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.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
|
||||
template.Template, '{% load custom %}{% inclusion_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3 %}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'",
|
||||
template.Template, '{% load custom %}{% inclusion_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled" %}')
|
||||
|
||||
def test_include_tag_missing_context(self):
|
||||
# The 'context' parameter must be present when takes_context is True
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'inclusion_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
|
||||
template.Template, '{% load custom %}{% inclusion_tag_without_context_parameter 123 %}')
|
||||
|
||||
@@ -296,7 +297,7 @@ class CustomTagTests(TestCase):
|
||||
t = template.Template('{% load custom %}{% assignment_one_default one=99 two="hello" as var %}The result is: {{ var }}')
|
||||
self.assertEqual(t.render(c), 'The result is: assignment_one_default - Expected result: 99, hello')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_one_default' received unexpected keyword argument 'three'",
|
||||
template.Template, '{% load custom %}{% assignment_one_default 99 two="hello" three="foo" as var %}')
|
||||
|
||||
@@ -315,42 +316,42 @@ class CustomTagTests(TestCase):
|
||||
t = template.Template('{% load custom %}{% assignment_only_unlimited_args 37 42 56 89 as var %}The result is: {{ var }}')
|
||||
self.assertEqual(t.render(c), 'The result is: assignment_only_unlimited_args - Expected result: 37, 42, 56, 89')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_one_param' tag takes at least 2 arguments and the second last argument must be 'as'",
|
||||
template.Template, '{% load custom %}{% assignment_one_param 37 %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_one_param' tag takes at least 2 arguments and the second last argument must be 'as'",
|
||||
template.Template, '{% load custom %}{% assignment_one_param 37 as %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_one_param' tag takes at least 2 arguments and the second last argument must be 'as'",
|
||||
template.Template, '{% load custom %}{% assignment_one_param 37 ass var %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_two_params' received too many positional arguments",
|
||||
template.Template, '{% load custom %}{% assignment_two_params 37 42 56 as var %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_one_default' received too many positional arguments",
|
||||
template.Template, '{% load custom %}{% assignment_one_default 37 42 56 as var %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_one_default' did not receive value\(s\) for the argument\(s\): 'one'",
|
||||
template.Template, '{% load custom %}{% assignment_one_default as var %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_unlimited_args' did not receive value\(s\) for the argument\(s\): 'one'",
|
||||
template.Template, '{% load custom %}{% assignment_unlimited_args as var %}The result is: {{ var }}')
|
||||
|
||||
t = template.Template('{% load custom %}{% assignment_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 as var %}The result is: {{ var }}')
|
||||
self.assertEqual(t.render(c), 'The result is: assignment_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
|
||||
template.Template, '{% load custom %}{% assignment_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3 as var %}The result is: {{ var }}')
|
||||
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'",
|
||||
template.Template, '{% load custom %}{% assignment_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled" as var %}The result is: {{ var }}')
|
||||
|
||||
@@ -371,6 +372,6 @@ class CustomTagTests(TestCase):
|
||||
|
||||
def test_assignment_tag_missing_context(self):
|
||||
# The 'context' parameter must be present when takes_context is True
|
||||
self.assertRaisesRegexp(template.TemplateSyntaxError,
|
||||
six.assertRaisesRegex(self, template.TemplateSyntaxError,
|
||||
"'assignment_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
|
||||
template.Template, '{% load custom %}{% assignment_tag_without_context_parameter 123 as var %}')
|
||||
|
||||
@@ -17,7 +17,7 @@ import os.path
|
||||
from django.template import TemplateDoesNotExist, Context
|
||||
from django.template.loaders.eggs import Loader as EggLoader
|
||||
from django.template import loader
|
||||
from django.utils import unittest
|
||||
from django.utils import unittest, six
|
||||
from django.utils.six import StringIO
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class MockProvider(pkg_resources.NullProvider):
|
||||
def _has(self, path):
|
||||
return path in self.module._resources
|
||||
|
||||
def _isdir(self,path):
|
||||
def _isdir(self, path):
|
||||
return False
|
||||
|
||||
def get_resource_stream(self, manager, resource_name):
|
||||
@@ -61,8 +61,8 @@ class EggLoaderTest(unittest.TestCase):
|
||||
|
||||
self.empty_egg = create_egg("egg_empty", {})
|
||||
self.egg_1 = create_egg("egg_1", {
|
||||
os.path.normcase('templates/y.html') : StringIO("y"),
|
||||
os.path.normcase('templates/x.txt') : StringIO("x"),
|
||||
os.path.normcase('templates/y.html'): StringIO("y"),
|
||||
os.path.normcase('templates/x.txt'): StringIO("x"),
|
||||
})
|
||||
self._old_installed_apps = settings.INSTALLED_APPS
|
||||
settings.INSTALLED_APPS = []
|
||||
@@ -144,12 +144,12 @@ class RenderToStringTest(unittest.TestCase):
|
||||
self.assertEqual(context['obj'], 'before')
|
||||
|
||||
def test_empty_list(self):
|
||||
self.assertRaisesRegexp(TemplateDoesNotExist,
|
||||
six.assertRaisesRegex(self, TemplateDoesNotExist,
|
||||
'No template names provided$',
|
||||
loader.render_to_string, [])
|
||||
|
||||
|
||||
def test_select_templates_from_empty_list(self):
|
||||
self.assertRaisesRegexp(TemplateDoesNotExist,
|
||||
six.assertRaisesRegex(self, TemplateDoesNotExist,
|
||||
'No template names provided$',
|
||||
loader.select_template, [])
|
||||
|
||||
Reference in New Issue
Block a user