Skip to content

Commit

Permalink
TST: Regression test against non-deterministic accidental object reuse (
Browse files Browse the repository at this point in the history
#2244)

Full credit to sjoerdjob for this contribution via #1995

See #1788

Co-authored-by: Sjoerd Job Postmus <[email protected]>
  • Loading branch information
MartinThoma and sjoerdjob authored Oct 8, 2023
1 parent 207152f commit 126f6be
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,3 +1859,31 @@ def test_object_contains_indirect_reference_to_self():
outpage = writer.add_blank_page(width, height)
outpage.merge_page(reader.pages[6])
writer.append(reader)


def test_merging_many_temporary_files():
def create_number_pdf(n) -> BytesIO:
from fpdf import FPDF

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

writer = PdfWriter()
for n in range(100):
reader = PdfReader(create_number_pdf(n))
for page in reader.pages:
# Should only be one page.
writer.add_page(page)

out = BytesIO()
writer.write(out)

out.seek(0)
reader = PdfReader(out)
for n, page in enumerate(reader.pages):
text = page.extract_text()
assert text == str(n)

0 comments on commit 126f6be

Please sign in to comment.