Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan6419846 committed Feb 27, 2025
1 parent b7f853d commit 8a61592
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
from io import BytesIO
from itertools import product as cartesian_product
from pathlib import Path
from unittest import mock

import pytest
from PIL import Image

from pypdf import PdfReader
from pypdf.errors import DeprecationError, PdfReadError
from pypdf.errors import DependencyError, DeprecationError, PdfReadError
from pypdf.filters import (
ASCII85Decode,
ASCIIHexDecode,
CCITParameters,
CCITTFaxDecode,
CCITTParameters,
FlateDecode,
JBIG2Decode,
)
from pypdf.generic import ArrayObject, DictionaryObject, IndirectObject, NameObject, NumberObject

Expand Down Expand Up @@ -642,3 +644,25 @@ def test_ascii85decode__non_recoverable(caplog):
with pytest.raises(ValueError, match="Non-Ascii85 digit found: Ã"):
ASCII85Decode.decode(data)
assert caplog.text == ""


def test_jbig2decode__binary_errors():
with (
mock.patch("pypdf.filters._JBIG2DEC_BINARY", None),
pytest.raises(DependencyError, match="jbig2dec binary is not available.")
):
JBIG2Decode.decode(b"dummy")

result = subprocess.CompletedProcess(
args=["dummy"], returncode=0, stdout=b"",
stderr=(
b"jbig2dec: unrecognized option '--embedded'\n"
b"Usage: jbig2dec [options] <file.jbig2>\n"
b" or jbig2dec [options] <global_stream> <page_stream>\n"
)
)
with (
mock.patch("pypdf.filters.subprocess.run", return_value=result),
pytest.raises(DependencyError, match="jbig2dec>=0.15 is required.")
):
JBIG2Decode.decode(b"dummy")

0 comments on commit 8a61592

Please sign in to comment.