@@ -57,7 +57,11 @@ def approx_compare( a, b, max_delta):
5757
5858
5959def test_joining ():
60- """Join 4 files and compare result with previously stored one."""
60+ """Join 4 files and compare result with previously stored one.
61+
62+ This test can fail between different versions of MuPDF because arrangements
63+ of objects can change arbitrarily.
64+ """
6165 flist = ("1.pdf" , "2.pdf" , "3.pdf" , "4.pdf" )
6266 doc = fitz .open ()
6367 for f in flist :
@@ -68,20 +72,21 @@ def test_joining():
6872
6973 tobytes = doc .tobytes (deflate = True , garbage = 4 )
7074 new_output = fitz .open ("pdf" , tobytes )
71- #new_output.save( os.path.join(resources, "joined-1.20.pdf"))
7275 old_output = fitz .open (oldfile )
73- old_output_1_20 = fitz .open (oldfile_1_20 )
7476 # result must have same objects, because MuPDF garbage
7577 # collection is a predictable process.
7678
77- # We do approximate comparison if new_output with old_output, and an exact
78- # comparison of new_output with old_output_1_20.
79+ # We do approximate comparison if new_output with old_output.
7980 #
80- assert old_output .xref_length () == new_output .xref_length () == old_output_1_20 .xref_length ()
81+ assert old_output .xref_length () == new_output .xref_length ()
82+ def xref_str ( p ):
83+ ret = ''
84+ for xref in range (1 , p .xref_length ()):
85+ ret += f' { xref } ={ p .xref_object (xref , compressed = True )} '
86+ return ret
8187 num_fails = 0
8288 for xref in range (1 , old_output .xref_length ()):
8389 old = old_output .xref_object (xref , compressed = True )
84- old_1_20 = old_output_1_20 .xref_object (xref , compressed = True )
8590 new = new_output .xref_object (xref , compressed = True )
8691 if approx_compare ( old , new , max_delta = 1.5 ):
8792 num_fails += 1
@@ -90,18 +95,10 @@ def test_joining():
9095 f'\n old={ old_output .xref_object (xref , compressed = True )} '
9196 f'\n new={ new_output .xref_object (xref , compressed = True )} '
9297 )
93- assert old_1_20 == new , (
94- f'xref={ xref } '
95- f'\n old_1_20: { old_1_20 } '
96- f'\n new@ { new } '
97- )
9898 assert not num_fails
9999 assert old_output .xref_get_keys (- 1 ) == new_output .xref_get_keys (- 1 )
100100 assert old_output .xref_get_key (- 1 , "ID" ) != new_output .xref_get_key (- 1 , "ID" )
101101
102- assert old_output_1_20 .xref_get_keys (- 1 ) == new_output .xref_get_keys (- 1 )
103- assert old_output_1_20 .xref_get_key (- 1 , "ID" ) != new_output .xref_get_key (- 1 , "ID" )
104-
105102
106103def test_issue1417_insertpdf_in_loop ():
107104 """Using a context manager instead of explicitly closing files"""
0 commit comments