Skip to content

Commit

Permalink
TST: Add test for #1897
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Jun 22, 2023
1 parent ab42636 commit b19567b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements/ci.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ flake8
flake8_implicit_str_concat
flake8-bugbear
flake8-print
fpdf2==2.4.1
mypy
pillow
pycryptodome
Expand Down
6 changes: 5 additions & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ flake8-implicit-str-concat==0.2.0
# via -r requirements/ci.in
flake8-print==4.0.1
# via -r requirements/ci.in
fpdf2==2.4.1
# via -r requirements/ci.in
importlib-metadata==4.2.0
# via
# flake8
Expand All @@ -40,7 +42,9 @@ mypy-extensions==1.0.0
packaging==21.3
# via pytest
pillow==8.4.0
# via -r requirements/ci.in
# via
# -r requirements/ci.in
# fpdf2
pluggy==1.0.0
# via pytest
py==1.11.0
Expand Down
28 changes: 28 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,3 +1174,31 @@ def test_image_new_property():
with pytest.raises(KeyError):
reader.pages[0]._get_image(["test"], reader.pages[0])
assert list(PageObject(None, None).images) == []


@pytest.mark.samples()
def test_compression():
"""Test for issue #1897"""

def create_stamp_pdf() -> BytesIO:
from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font("helvetica", "B", 16)
pdf.cell(40, 10, "Hello World!")
byte_string = pdf.output()
return BytesIO(byte_string)

template = PdfReader(create_stamp_pdf())
template_page = template.pages[0]
writer = PdfWriter()
writer.append(SAMPLE_ROOT / "009-pdflatex-geotopo/GeoTopo.pdf", [1])
nb1 = len(writer._objects)

for page in writer.pages:
page.merge_page(template_page)
assert len(writer._objects) == nb1 + 1 # font is added that's all
for page in writer.pages:
page.compress_content_streams()
assert len(writer._objects) == nb1 + 1

0 comments on commit b19567b

Please sign in to comment.