Skip to content

Commit

Permalink
Add test with non-unicode static file
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap3 committed Nov 8, 2021
1 parent 5d499a6 commit 288169f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_coverage_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def read_template_source(filename):
charset = 'utf-8'
else:
charset = settings.FILE_CHARSET
text = f.read().decode(charset)
text = f.read().decode(charset, errors='backslashreplace')

return text

Expand Down
8 changes: 8 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,11 @@ def test_with_branch_enabled(self):
)
self.assertEqual(text, 'Hello\nWorld\n\nGoodbye')
self.assert_analysis([1, 2, 3, 4])


class TestNonUTF8StaticFile(DjangoPluginTestCase):
def test_non_utf8_static_file(self):
# Non-template file containing a word encoded in CP-1252
self.make_file("static/german.txt", bytes=b"sh\xf6n")
self.run_django_coverage(text='Hello')
self.assertEqual(self.get_html_report('../static/german.txt'), 0)

0 comments on commit 288169f

Please sign in to comment.