Skip to content

Commit

Permalink
Added a mock (not ideal) to test unicodedecodeerror
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Jan 15, 2024
1 parent 1095aec commit 582fd4f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions z3c/dependencychecker/tests/test_modules_docfiles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from unittest import mock

from z3c.dependencychecker.modules import DocFiles
from z3c.dependencychecker.tests.utils import write_source_file_at
Expand Down Expand Up @@ -81,6 +82,20 @@ def test_create_from_files_deep_nested_txt(minimal_structure):
assert len(modules_found) == 1


def test_unicode_decode_error():
docfiles = DocFiles("somewhere", "some_file")
docfiles._scan = mock.MagicMock
# Thanks to
# https://gehrcke.de/2015/12/how-to-raise-unicodedecodeerror-in-python-3/
# for the error syntax :-)
o = b"\x00\x00"
docfiles._scan.side_effect = UnicodeDecodeError(
"funnycodec", o, 1, 2, "This is just a fake reason!"
)
# The unicode error logs an error but continues otherwise.
assert list(docfiles.scan()) == []


def test_create_from_files_deep_nested_rst(minimal_structure):
path, package_name = minimal_structure
src_path = path / "src"
Expand Down

0 comments on commit 582fd4f

Please sign in to comment.