Skip to content

Commit

Permalink
tests/test_toc.py: added test for #2355.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Apr 18, 2023
1 parent e884d57 commit 6dce764
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Verify stability against circular TOC items
"""
import os
import sys
import fitz

scriptdir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -62,3 +63,24 @@ def test_circular():
"""The test file contains circular bookmarks."""
doc = fitz.open(circular)
toc = doc.get_toc(False) # this must not loop

def test_2355():

# Create a test PDF with toc.
doc = fitz.Document()
for _ in range(10):
doc.new_page(doc.page_count)
doc.set_toc([[1, 'test', 1], [1, 'test2', 5]])

path = 'test_2355.pdf'
doc.save(path)

# Open many times
for i in range(10):
with fitz.open(path) as new_doc:
new_doc.get_toc()

# Open once and read many times
with fitz.open(path) as new_doc:
for i in range(10):
new_doc.get_toc()

0 comments on commit 6dce764

Please sign in to comment.