Skip to content

Commit

Permalink
Got testing of the generator-with-exception to work
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Jan 16, 2024
1 parent e1ec314 commit cffac3d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions z3c/dependencychecker/tests/test_modules_docfiles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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 @@ -84,14 +83,19 @@ def test_create_from_files_deep_nested_txt(minimal_structure):

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!"
)

def mock_scan():
# Thanks to
# https://gehrcke.de/2015/12/how-to-raise-unicodedecodeerror-in-python-3/
# for the error syntax :-)
o = b"\x00\x00"
if True:
raise UnicodeDecodeError(
"funnycodec", o, 1, 2, "This is just a fake reason!"
)
yield "dummy yieldto make it an iterable"

docfiles._scan = mock_scan
# The unicode error logs an error but continues otherwise.
assert list(docfiles.scan()) == []

Expand Down

0 comments on commit cffac3d

Please sign in to comment.