Skip to content

Clarification and improvements in test_filters.py #3510

@j-t-1

Description

@j-t-1

filter_inputs = (
string.ascii_lowercase,
string.ascii_uppercase,
string.ascii_letters,
string.digits,
string.hexdigits,
string.punctuation,
string.whitespace, # Add more...
)

Any ideas on what to add so we can remove the comment?

def test_flatedecode_unsupported_predictor():
"""
FlateDecode raises PdfReadError for unsupported predictors.
Predictors outside the [10, 15] range are not supported.
This test function checks that a PdfReadError is raised when decoding with
unsupported predictors. Once this predictor support is updated in the
future, this test case may be removed.
"""
codec = FlateDecode()
predictors = (-10, -1, 0, 9, 16, 20, 100)
for predictor, s in cartesian_product(predictors, filter_inputs):
s = s.encode()
with pytest.raises(PdfReadError):
codec.decode(codec.encode(s), DictionaryObject({"/Predictor": predictor}))

We support all the predictor values (1-2, 10-15). I think we should keep the test for values outside the range. So the comment needs updating.

pypdf/tests/test_filters.py

Lines 136 to 140 in 56cf557

def test_ascii_hex_decode_missing_eod():
"""ASCIIHexDecode.decode() raises error when no EOD character is present."""
# with pytest.raises(PdfStreamError) as exc:
ASCIIHexDecode.decode("")
# assert exc.value.args[0] == "Unexpected EOD in ASCIIHexDecode"

The docstring does not match the test, so the test needs changing?

pypdf/tests/test_filters.py

Lines 236 to 252 in 56cf557

def test_ccitt_fax_decode():
data = b""
parameters = DictionaryObject(
{"/K": NumberObject(-1), "/Columns": NumberObject(17)}
)
# This was just the result pypdf 1.27.9 returned.
# It would be awesome if we could check if that is actually correct.
assert CCITTFaxDecode.decode(data, parameters) == (
b"II*\x00\x08\x00\x00\x00\x08\x00\x00\x01\x04\x00\x01\x00\x00\x00\x11\x00"
b"\x00\x00\x01\x01\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x01"
b"\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x03\x01\x03\x00\x01\x00"
b"\x00\x00\x04\x00\x00\x00\x06\x01\x03\x00\x01\x00\x00\x00\x00\x00"
b"\x00\x00\x11\x01\x04\x00\x01\x00\x00\x00l\x00\x00\x00\x16\x01"
b"\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x01\x04\x00\x01\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00"
)

Needs checking; is the b"x00l" wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions