Skip to content

Commit

Permalink
TST: generic._base (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Aug 13, 2022
1 parent a85148a commit 3424c71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/__init__.py
Expand Up @@ -50,3 +50,8 @@ def _strip_position(line: str) -> str:

def normalize_warnings(caplog_text: str) -> List[str]:
return [_strip_position(line) for line in caplog_text.strip().split("\n")]


class ReaderDummy:
def __init__(self, strict=False):
self.strict = strict
22 changes: 21 additions & 1 deletion tests/test_generic.py
Expand Up @@ -32,7 +32,7 @@
read_string_from_stream,
)

from . import get_pdf_from_url
from . import ReaderDummy, get_pdf_from_url

TESTS_ROOT = Path(__file__).parent.resolve()
PROJECT_ROOT = TESTS_ROOT.parent
Expand Down Expand Up @@ -645,3 +645,23 @@ def test_annotation_builder_text():

def test_CheckboxRadioButtonAttributes_opt():
assert "/Opt" in CheckboxRadioButtonAttributes.attributes_dict()


def test_name_object_invalid_decode():
stream = BytesIO(b"/\x80\x02\x03")

# strict:
with pytest.raises(PdfReadError) as exc:
NameObject.read_from_stream(stream, ReaderDummy(strict=True))
assert exc.value.args[0] == "Illegal character in Name Object"

# non-strict:
stream.seek(0)
NameObject.read_from_stream(stream, ReaderDummy(strict=False))


def test_indirect_object_invalid_read():
stream = BytesIO(b"0 1 s")
with pytest.raises(PdfReadError) as exc:
IndirectObject.read_from_stream(stream, ReaderDummy())
assert exc.value.args[0] == "Error reading indirect object reference at byte 0x5"

0 comments on commit 3424c71

Please sign in to comment.