Skip to content

Commit 0d33bc7

Browse files
committed
Get the encoding right for HTML reporting. Fixes #5
1 parent 5433451 commit 0d33bc7

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

django_coverage_plugin/plugin.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,20 @@ def __init__(self, filename):
142142
self.name = os.path.relpath(filename)
143143
# TODO: html filenames are absolute.
144144

145+
self._source = None
146+
147+
def source(self):
148+
if self._source is None:
149+
self._source = read_template_source(self.filename)
150+
return self._source
151+
145152
def statements(self):
146153
source_lines = set()
147154

148155
if SHOW_PARSING:
149156
print("-------------- {}".format(self.filename))
150157

151-
text = read_template_source(self.filename)
152-
tokens = Lexer(text, self.filename).tokenize()
158+
tokens = Lexer(self.source(), self.filename).tokenize()
153159

154160
# Are we inside a comment?
155161
comment = False

tests/test_html.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# coding: utf8
2+
"""Tests of HTML reporting for django_coverage_plugin."""
3+
4+
import os
5+
6+
from .plugin_test import DjangoPluginTestCase
7+
8+
9+
class HtmlTest(DjangoPluginTestCase):
10+
11+
def test_simple(self):
12+
self.make_template("""\
13+
Simple © 2015
14+
""")
15+
16+
self.run_django_coverage()
17+
self.cov.html_report()
18+
print(os.getcwd())
19+
print(os.listdir("htmlcov"))
20+
with open("htmlcov/templates_test_simple_html.html") as fhtml:
21+
html = fhtml.read()
22+
self.assertIn("<span class='txt'>Simple &#169; 2015</span>", html)

0 commit comments

Comments
 (0)