From 288169f87d3f8d37a23d981224a6daab082acaf2 Mon Sep 17 00:00:00 2001 From: Jaap Roes Date: Thu, 4 Nov 2021 15:07:43 +0100 Subject: [PATCH] Add test with non-unicode static file --- django_coverage_plugin/plugin.py | 2 +- tests/test_simple.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index a3e4867..eb58987 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -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 diff --git a/tests/test_simple.py b/tests/test_simple.py index 7ca9188..e04dce0 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -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)