Skip to content

Commit 288169f

Browse files
author
Jaap Roes
committed
Add test with non-unicode static file
1 parent 5d499a6 commit 288169f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

django_coverage_plugin/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def read_template_source(filename):
145145
charset = 'utf-8'
146146
else:
147147
charset = settings.FILE_CHARSET
148-
text = f.read().decode(charset)
148+
text = f.read().decode(charset, errors='backslashreplace')
149149

150150
return text
151151

tests/test_simple.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,11 @@ def test_with_branch_enabled(self):
262262
)
263263
self.assertEqual(text, 'Hello\nWorld\n\nGoodbye')
264264
self.assert_analysis([1, 2, 3, 4])
265+
266+
267+
class TestNonUTF8StaticFile(DjangoPluginTestCase):
268+
def test_non_utf8_static_file(self):
269+
# Non-template file containing a word encoded in CP-1252
270+
self.make_file("static/german.txt", bytes=b"sh\xf6n")
271+
self.run_django_coverage(text='Hello')
272+
self.assertEqual(self.get_html_report('../static/german.txt'), 0)

0 commit comments

Comments
 (0)