Skip to content

Commit e4d6966

Browse files
committed
{% lorem %} test, and a django version skipping decorator.
1 parent 7397513 commit e4d6966

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tests/plugin_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import os.path
55
import re
6+
import unittest
67

78
import coverage
89
from coverage.test_helpers import TempDirMixin
@@ -30,6 +31,7 @@
3031
if hasattr(django, "setup"):
3132
django.setup()
3233

34+
3335
from django.template import Context, Template
3436
from django.template.loader import get_template
3537
from django.test import TestCase
@@ -141,3 +143,17 @@ def get_xml_report(self, name=None):
141143
def squashed(s):
142144
"""Remove all of the whitespace from s."""
143145
return re.sub(r"\s", "", s)
146+
147+
148+
def needs_django(*needed_version):
149+
"""A decorator for tests to require a minimum version of Django.
150+
151+
@needs_django(1, 8) # Don't run the test on 1.7 or lower.
152+
def test_thing(self):
153+
...
154+
155+
"""
156+
if django.VERSION >= tuple(needed_version):
157+
return lambda func: func
158+
else:
159+
return unittest.skip("Django version must be newer")

tests/test_simple.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf8
22
"""Simple tests for django_coverage_plugin."""
33

4-
from .plugin_test import DjangoPluginTestCase
4+
from .plugin_test import DjangoPluginTestCase, needs_django
55

66
# TODO: test what happens if TEMPLATE_DEBUG is not set.
77

@@ -159,6 +159,18 @@ def test_firstof(self):
159159
self.assertEqual(self.get_line_data(), [1, 2, 3])
160160
self.assertEqual(self.get_analysis(), ([1, 2, 3], []))
161161

162+
@needs_django(1, 8)
163+
def test_lorem(self):
164+
self.make_template("""\
165+
First
166+
{% lorem 3 w %}
167+
Last
168+
""")
169+
text = self.run_django_coverage()
170+
self.assertEqual(text, "First\nlorem ipsum dolor\nLast\n")
171+
self.assertEqual(self.get_line_data(), [1, 2, 3])
172+
self.assertEqual(self.get_analysis(), ([1, 2, 3], []))
173+
162174

163175
class StringTemplateTest(DjangoPluginTestCase):
164176

0 commit comments

Comments
 (0)