Skip to content

Commit 3eee25d

Browse files
committed
refactor: a more convenient assert for measured files
1 parent 578a2a9 commit 3eee25d

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

tests/plugin_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,15 @@ def get_analysis(self, name=None):
176176
_, executable, _, missing, _ = analysis
177177
return executable, missing
178178

179-
def measured_files(self):
180-
"""Get the list of measured files, in relative form."""
181-
return [os.path.relpath(f) for f in self.cov.get_data().measured_files()]
179+
def assert_measured_files(self, *template_files):
180+
"""Assert that the measured files are `template_files`.
181+
182+
The names in `template_files` are the base names of files
183+
in the templates directory.
184+
"""
185+
measured = {os.path.relpath(f) for f in self.cov.get_data().measured_files()}
186+
expected = {os.path.join("templates", f) for f in template_files}
187+
self.assertEqual(measured, expected)
182188

183189
def assert_analysis(self, executable, missing=None, name=None):
184190
"""Assert that the analysis for `name` is right."""

tests/test_extends.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
"""Tests of template inheritance for django_coverage_plugin."""
55

6-
import os.path
7-
86
from .plugin_test import DjangoPluginTestCase, django_stop_before
97

108

@@ -170,13 +168,7 @@ def test_ssi_unparsed(self):
170168
text = self.run_django_coverage(name="outer.html", context={'a': 17})
171169
self.assertEqual(text, "First\nInside {{ a }}\nJob\n\nLast\n")
172170
self.assert_analysis([1, 2, 3], name="outer.html")
173-
self.assertEqual(
174-
set(self.measured_files()),
175-
set([
176-
os.path.join("templates", "outer.html"),
177-
os.path.join("templates", "nested.html"),
178-
])
179-
)
171+
self.assert_measured_files("outer.html", "nested.html")
180172

181173
def test_ssi_parsed(self):
182174
nested = self.make_template(name="nested.html", text="""\
@@ -193,10 +185,4 @@ def test_ssi_parsed(self):
193185
text = self.run_django_coverage(name="outer.html", context={'a': 17})
194186
self.assertEqual(text, "First\nInside 17\nJob\n\nLast\n")
195187
self.assert_analysis([1, 2, 3], name="outer.html")
196-
self.assertEqual(
197-
set(self.measured_files()),
198-
set([
199-
os.path.join("templates", "outer.html"),
200-
os.path.join("templates", "nested.html"),
201-
])
202-
)
188+
self.assert_measured_files("outer.html", "nested.html")

0 commit comments

Comments
 (0)