diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-12-21 21:19:05 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-12-30 18:16:25 +0100 |
| commit | 51890ce8898f821d28f2f6fb6071c936e9bd88f0 (patch) | |
| tree | 6522c597d411086b0a5c2ec3dd7a1d9bc2feeafd /tests/template_tests/syntax_tests | |
| parent | 66f9a74b4514bd259976ce8ee3a4e78288358a5f (diff) | |
Applied ignore_warnings to Django tests
Diffstat (limited to 'tests/template_tests/syntax_tests')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_cycle.py | 19 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_filter_syntax.py | 8 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_firstof.py | 24 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_for.py | 42 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_ssi.py | 17 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_url.py | 103 |
6 files changed, 85 insertions, 128 deletions
diff --git a/tests/template_tests/syntax_tests/test_cycle.py b/tests/template_tests/syntax_tests/test_cycle.py index 8a47ff8879..88a7187b1a 100644 --- a/tests/template_tests/syntax_tests/test_cycle.py +++ b/tests/template_tests/syntax_tests/test_cycle.py @@ -1,7 +1,5 @@ -import warnings - from django.template import TemplateSyntaxError -from django.test import SimpleTestCase +from django.test import SimpleTestCase, ignore_warnings from django.utils.deprecation import RemovedInDjango20Warning from ..utils import setup @@ -141,24 +139,21 @@ class CycleTagTests(SimpleTestCase): output = self.engine.render_to_string('cycle25', {'a': '<'}) self.assertEqual(output, '<') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'cycle26': '{% load cycle from future %}{% cycle a b as ab %}{% cycle ab %}'}) def test_cycle26(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('cycle26', {'a': '<', 'b': '>'}) + output = self.engine.render_to_string('cycle26', {'a': '<', 'b': '>'}) self.assertEqual(output, '<>') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'cycle27': '{% load cycle from future %}' '{% autoescape off %}{% cycle a b as ab %}{% cycle ab %}{% endautoescape %}'}) def test_cycle27(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('cycle27', {'a': '<', 'b': '>'}) + output = self.engine.render_to_string('cycle27', {'a': '<', 'b': '>'}) self.assertEqual(output, '<>') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'cycle28': '{% load cycle from future %}{% cycle a|safe b as ab %}{% cycle ab %}'}) def test_cycle28(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('cycle28', {'a': '<', 'b': '>'}) + output = self.engine.render_to_string('cycle28', {'a': '<', 'b': '>'}) self.assertEqual(output, '<>') diff --git a/tests/template_tests/syntax_tests/test_filter_syntax.py b/tests/template_tests/syntax_tests/test_filter_syntax.py index 4fd62be7c8..58ee527758 100644 --- a/tests/template_tests/syntax_tests/test_filter_syntax.py +++ b/tests/template_tests/syntax_tests/test_filter_syntax.py @@ -1,9 +1,8 @@ # coding: utf-8 from __future__ import unicode_literals -import warnings from django.template import TemplateSyntaxError -from django.test import SimpleTestCase +from django.test import SimpleTestCase, ignore_warnings from django.utils.deprecation import RemovedInDjango20Warning from ..utils import setup, SomeClass, SomeOtherException, UTF8Class @@ -76,14 +75,13 @@ class FilterSyntaxTests(SimpleTestCase): with self.assertRaises(TemplateSyntaxError): self.engine.get_template('filter-syntax08') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'filter-syntax09': '{{ var|removetags:"b i"|upper|lower }}'}) def test_filter_syntax09(self): """ Chained filters, with an argument to the first one """ - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('filter-syntax09', {'var': '<b><i>Yes</i></b>'}) + output = self.engine.render_to_string('filter-syntax09', {'var': '<b><i>Yes</i></b>'}) self.assertEqual(output, 'yes') @setup({'filter-syntax10': r'{{ var|default_if_none:" endquote\" hah" }}'}) diff --git a/tests/template_tests/syntax_tests/test_firstof.py b/tests/template_tests/syntax_tests/test_firstof.py index c7c4434446..2c227f2304 100644 --- a/tests/template_tests/syntax_tests/test_firstof.py +++ b/tests/template_tests/syntax_tests/test_firstof.py @@ -1,7 +1,5 @@ -import warnings - from django.template import TemplateSyntaxError -from django.test import SimpleTestCase +from django.test import SimpleTestCase, ignore_warnings from django.utils.deprecation import RemovedInDjango20Warning from ..utils import setup @@ -59,31 +57,27 @@ class FirstOfTagTests(SimpleTestCase): output = self.engine.render_to_string('firstof10', {'a': '<'}) self.assertEqual(output, '<') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'firstof11': '{% load firstof from future %}{% firstof a b %}'}) def test_firstof11(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('firstof11', {'a': '<', 'b': '>'}) + output = self.engine.render_to_string('firstof11', {'a': '<', 'b': '>'}) self.assertEqual(output, '<') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'firstof12': '{% load firstof from future %}{% firstof a b %}'}) def test_firstof12(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('firstof12', {'a': '', 'b': '>'}) + output = self.engine.render_to_string('firstof12', {'a': '', 'b': '>'}) self.assertEqual(output, '>') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'firstof13': '{% load firstof from future %}' '{% autoescape off %}{% firstof a %}{% endautoescape %}'}) def test_firstof13(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('firstof13', {'a': '<'}) + output = self.engine.render_to_string('firstof13', {'a': '<'}) self.assertEqual(output, '<') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'firstof14': '{% load firstof from future %}{% firstof a|safe b %}'}) def test_firstof14(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('firstof14', {'a': '<'}) + output = self.engine.render_to_string('firstof14', {'a': '<'}) self.assertEqual(output, '<') diff --git a/tests/template_tests/syntax_tests/test_for.py b/tests/template_tests/syntax_tests/test_for.py index 156d17d0b1..566b86f3d8 100644 --- a/tests/template_tests/syntax_tests/test_for.py +++ b/tests/template_tests/syntax_tests/test_for.py @@ -1,7 +1,5 @@ -import warnings - from django.template import TemplateSyntaxError -from django.test import SimpleTestCase +from django.test import SimpleTestCase, ignore_warnings from django.utils.deprecation import RemovedInDjango20Warning from ..utils import setup @@ -129,48 +127,44 @@ class ForTagTests(SimpleTestCase): # These tests raise deprecation warnings and will raise an exception # in Django 2.0. The existing behavior is silent truncation if the # length of loopvars differs to the length of each set of items. + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'for-tag-unpack10': '{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}'}) def test_for_tag_unpack10(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string( - 'for-tag-unpack10', - {'items': (('one', 1, 'carrot'), ('two', 2, 'orange'))}, - ) + output = self.engine.render_to_string( + 'for-tag-unpack10', + {'items': (('one', 1, 'carrot'), ('two', 2, 'orange'))}, + ) self.assertEqual(output, 'one:1/two:2/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'for-tag-unpack11': '{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}'}) def test_for_tag_unpack11(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string( - 'for-tag-unpack11', - {'items': (('one', 1), ('two', 2))}, - ) + output = self.engine.render_to_string( + 'for-tag-unpack11', + {'items': (('one', 1), ('two', 2))}, + ) if self.engine.string_if_invalid: self.assertEqual(output, 'one:1,INVALID/two:2,INVALID/') else: self.assertEqual(output, 'one:1,/two:2,/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'for-tag-unpack12': '{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}'}) def test_for_tag_unpack12(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string( - 'for-tag-unpack12', - {'items': (('one', 1, 'carrot'), ('two', 2))} - ) + output = self.engine.render_to_string( + 'for-tag-unpack12', + {'items': (('one', 1, 'carrot'), ('two', 2))} + ) if self.engine.string_if_invalid: self.assertEqual(output, 'one:1,carrot/two:2,INVALID/') else: self.assertEqual(output, 'one:1,carrot/two:2,/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'for-tag-unpack14': '{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}'}) def test_for_tag_unpack14(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('for-tag-unpack14', {'items': (1, 2)}) + output = self.engine.render_to_string('for-tag-unpack14', {'items': (1, 2)}) if self.engine.string_if_invalid: self.assertEqual(output, 'INVALID:INVALID/INVALID:INVALID/') diff --git a/tests/template_tests/syntax_tests/test_ssi.py b/tests/template_tests/syntax_tests/test_ssi.py index c5e89b0d2f..bc70aca9c6 100644 --- a/tests/template_tests/syntax_tests/test_ssi.py +++ b/tests/template_tests/syntax_tests/test_ssi.py @@ -1,7 +1,6 @@ import os -import warnings -from django.test import SimpleTestCase +from django.test import ignore_warnings, SimpleTestCase from django.utils.deprecation import RemovedInDjango19Warning from ..utils import ROOT, setup @@ -32,20 +31,18 @@ class SsiTagTests(SimpleTestCase): self.assertEqual(output, ''), # Test passing as a variable + @ignore_warnings(category=RemovedInDjango19Warning) @setup({'ssi04': '{% load ssi from future %}{% ssi ssi_file %}'}) def test_ssi04(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango19Warning) - output = self.engine.render_to_string('ssi04', { - 'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html') - }) + output = self.engine.render_to_string('ssi04', { + 'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html') + }) self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n') + @ignore_warnings(category=RemovedInDjango19Warning) @setup({'ssi05': '{% load ssi from future %}{% ssi ssi_file %}'}) def test_ssi05(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango19Warning) - output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'}) + output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'}) self.assertEqual(output, '') # Test parsed output diff --git a/tests/template_tests/syntax_tests/test_url.py b/tests/template_tests/syntax_tests/test_url.py index 389aefa00a..60f777f6d0 100644 --- a/tests/template_tests/syntax_tests/test_url.py +++ b/tests/template_tests/syntax_tests/test_url.py @@ -1,9 +1,7 @@ # coding: utf-8 -import warnings - from django.core.urlresolvers import NoReverseMatch from django.template import TemplateSyntaxError -from django.test import override_settings, SimpleTestCase +from django.test import ignore_warnings, override_settings, SimpleTestCase from django.utils.deprecation import RemovedInDjango20Warning from ..utils import setup @@ -13,46 +11,40 @@ from ..utils import setup class UrlTagTests(SimpleTestCase): # Successes + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url01': '{% url "template_tests.views.client" client.id %}'}) def test_url01(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url01', {'client': {'id': 1}}) + output = self.engine.render_to_string('url01', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url02': '{% url "template_tests.views.client_action" id=client.id action="update" %}'}) def test_url02(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url02', {'client': {'id': 1}}) + output = self.engine.render_to_string('url02', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/update/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url02a': '{% url "template_tests.views.client_action" client.id "update" %}'}) def test_url02a(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url02a', {'client': {'id': 1}}) + output = self.engine.render_to_string('url02a', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/update/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url02b': "{% url 'template_tests.views.client_action' id=client.id action='update' %}"}) def test_url02b(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url02b', {'client': {'id': 1}}) + output = self.engine.render_to_string('url02b', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/update/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url02c': "{% url 'template_tests.views.client_action' client.id 'update' %}"}) def test_url02c(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url02c', {'client': {'id': 1}}) + output = self.engine.render_to_string('url02c', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/update/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url03': '{% url "template_tests.views.index" %}'}) def test_url03(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url03') + output = self.engine.render_to_string('url03') self.assertEqual(output, '/') @setup({'url04': '{% url "named.client" client.id %}'}) @@ -70,11 +62,10 @@ class UrlTagTests(SimpleTestCase): output = self.engine.render_to_string('url06', {'v': 'Ω'}) self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url07': '{% url "template_tests.views.client2" tag=v %}'}) def test_url07(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url07', {'v': 'Ω'}) + output = self.engine.render_to_string('url07', {'v': 'Ω'}) self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/') @setup({'url08': '{% url "метка_оператора" v %}'}) @@ -87,62 +78,54 @@ class UrlTagTests(SimpleTestCase): output = self.engine.render_to_string('url09', {'v': 'Ω'}) self.assertEqual(output, '/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url10': '{% url "template_tests.views.client_action" id=client.id action="two words" %}'}) def test_url10(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url10', {'client': {'id': 1}}) + output = self.engine.render_to_string('url10', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/two%20words/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url11': '{% url "template_tests.views.client_action" id=client.id action="==" %}'}) def test_url11(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url11', {'client': {'id': 1}}) + output = self.engine.render_to_string('url11', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/==/') @setup({'url12': '{% url "template_tests.views.client_action" ' 'id=client.id action="!$&\'()*+,;=~:@," %}'}) + @ignore_warnings(category=RemovedInDjango20Warning) def test_url12(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url12', {'client': {'id': 1}}) + output = self.engine.render_to_string('url12', {'client': {'id': 1}}) self.assertEqual(output, '/client/1/!$&\'()*+,;=~:@,/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url13': '{% url "template_tests.views.client_action" ' 'id=client.id action=arg|join:"-" %}'}) def test_url13(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url13', {'client': {'id': 1}, 'arg': ['a', 'b']}) + output = self.engine.render_to_string('url13', {'client': {'id': 1}, 'arg': ['a', 'b']}) self.assertEqual(output, '/client/1/a-b/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url14': '{% url "template_tests.views.client_action" client.id arg|join:"-" %}'}) def test_url14(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url14', {'client': {'id': 1}, 'arg': ['a', 'b']}) + output = self.engine.render_to_string('url14', {'client': {'id': 1}, 'arg': ['a', 'b']}) self.assertEqual(output, '/client/1/a-b/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url15': '{% url "template_tests.views.client_action" 12 "test" %}'}) def test_url15(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url15') + output = self.engine.render_to_string('url15') self.assertEqual(output, '/client/12/test/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url18': '{% url "template_tests.views.client" "1,2" %}'}) def test_url18(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url18') + output = self.engine.render_to_string('url18') self.assertEqual(output, '/client/1,2/') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url19': '{% url named_url client.id %}'}) def test_url19(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'}) + output = self.engine.render_to_string('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'}) self.assertEqual(output, '/client/1/') @setup({'url20': '{% url url_name_in_var client.id %}'}) @@ -161,12 +144,11 @@ class UrlTagTests(SimpleTestCase): with self.assertRaises(NoReverseMatch): self.engine.render_to_string('url-fail02') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url-fail03': '{% url "template_tests.views.client" %}'}) def test_url_fail03(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - with self.assertRaises(NoReverseMatch): - self.engine.render_to_string('url-fail03') + with self.assertRaises(NoReverseMatch): + self.engine.render_to_string('url-fail03') @setup({'url-fail04': '{% url "view" id, %}'}) def test_url_fail04(self): @@ -208,12 +190,11 @@ class UrlTagTests(SimpleTestCase): with self.assertRaises(NoReverseMatch): self.engine.render_to_string('url-fail12', {'named_url': 'no_such_view'}) + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url-fail13': '{% url named_url %}'}) def test_url_fail13(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - with self.assertRaises(NoReverseMatch): - self.engine.render_to_string('url-fail13', {'named_url': 'template_tests.views.client'}) + with self.assertRaises(NoReverseMatch): + self.engine.render_to_string('url-fail13', {'named_url': 'template_tests.views.client'}) @setup({'url-fail14': '{% url named_url id, %}'}) def test_url_fail14(self): @@ -246,18 +227,16 @@ class UrlTagTests(SimpleTestCase): self.engine.render_to_string('url-fail19', {'named_url': 'view'}) # {% url ... as var %} + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url-asvar01': '{% url "template_tests.views.index" as url %}'}) def test_url_asvar01(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url-asvar01') + output = self.engine.render_to_string('url-asvar01') self.assertEqual(output, '') + @ignore_warnings(category=RemovedInDjango20Warning) @setup({'url-asvar02': '{% url "template_tests.views.index" as url %}{{ url }}'}) def test_url_asvar02(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", RemovedInDjango20Warning) - output = self.engine.render_to_string('url-asvar02') + output = self.engine.render_to_string('url-asvar02') self.assertEqual(output, '/') @setup({'url-asvar03': '{% url "no_such_view" as url %}{{ url }}'}) |
