Skip to content

Commit 081cd5a

Browse files
committed
Properly handle load (and other) tags in inheriting templates
1 parent 2305530 commit 081cd5a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

django_coverage_plugin/plugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def statements(self):
176176
)
177177
)
178178
if token.token_type == TOKEN_BLOCK:
179-
if token.contents == 'endcomment':
179+
if token.contents == "endcomment":
180180
comment = False
181181
continue
182182

@@ -191,7 +191,12 @@ def statements(self):
191191
if extends:
192192
continue
193193

194-
if token.contents == 'comment':
194+
if extends and not inblock:
195+
# In an inheriting tempalte, ignore all tags outside of
196+
# blocks.
197+
continue
198+
199+
if token.contents == "comment":
195200
comment = True
196201
if token.contents.startswith("end"):
197202
continue

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='django_coverage_plugin',
7-
version='0.3.3',
7+
version='0.3.4',
88
description='Django template coverage.py plugin',
99
author='Ned Batchelder',
1010
author_email='[email protected]',

tests/test_extends.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_inheriting_with_unused_blocks(self):
102102

103103

104104
class LoadTest(DjangoPluginTestCase):
105-
def test_loads(self):
105+
def test_load(self):
106106
self.make_template(name="load.html", text="""\
107107
{% load i18n %}
108108
@@ -114,3 +114,23 @@ def test_loads(self):
114114
self.assertEqual(text, "\n\nFIRST\nSECOND\n")
115115
self.assertEqual(self.get_line_data("load.html"), [1, 2, 3, 4])
116116
self.assertEqual(self.get_analysis("load.html"), ([1, 2, 3, 4], []))
117+
118+
def test_load_with_extends(self):
119+
self.make_template(name="base.html", text="""\
120+
Hello
121+
{% block second_line %}second{% endblock %}
122+
Goodbye
123+
""")
124+
125+
self.make_template(name="specific.html", text="""\
126+
{% extends "base.html" %}
127+
{% load i18n %}
128+
{% block second_line %}
129+
SPECIFIC
130+
{% endblock %}
131+
""")
132+
133+
text = self.run_django_coverage(name="specific.html")
134+
self.assertEqual(text, "Hello\n\nSPECIFIC\n\nGoodbye\n")
135+
self.assertEqual(self.get_line_data("specific.html"), [1, 4])
136+
self.assertEqual(self.get_analysis("specific.html"), ([1, 4], []))

0 commit comments

Comments
 (0)