()
| 266 | |
| 267 | |
| 268 | def test_merge_checks2(): |
| 269 | # Join / merge Form PDFs joining any duplicate names in the src PDF. |
| 270 | merge_file1 = os.path.join(resources, "merge-form1.pdf") |
| 271 | merge_file2 = os.path.join(resources, "merge-form2.pdf") |
| 272 | tar = pymupdf.open(merge_file1) |
| 273 | rc0 = names_and_kids(tar) # list of root names and kid counts |
| 274 | names0 = [itm["name"] for itm in rc0] # root names in target |
| 275 | kids0 = sum([itm["kids"] for itm in rc0]) # number of kids in target |
| 276 | |
| 277 | src = pymupdf.open(merge_file2) |
| 278 | rc1 = names_and_kids(src) # list of root namesand kids in source PDF |
| 279 | dup_count = 0 # counts duplicate names in source PDF |
| 280 | dup_kids = 0 # counts the expected kids after merge |
| 281 | |
| 282 | for itm in rc1: # walk root fields of source pdf |
| 283 | if itm["name"] not in names0: # not a duplicate name |
| 284 | continue |
| 285 | # if target field has kids, add their count, else add 1 |
| 286 | dup_kids0 = sum([i["kids"] for i in rc0 if i["name"] == itm["name"]]) |
| 287 | dup_kids += dup_kids0 if dup_kids0 else 1 |
| 288 | # if source field has kids add their count, else add 1 |
| 289 | dup_kids += itm["kids"] if itm["kids"] else 1 |
| 290 | |
| 291 | names1 = [itm["name"] for itm in rc1] # names in source |
| 292 | |
| 293 | tar.insert_pdf(src, join_duplicates=True) # join merging any duplicate names |
| 294 | |
| 295 | rc2 = names_and_kids(tar) # get names and kid counts in resulting PDF |
| 296 | names2 = [itm["name"] for itm in rc2] # resulting names in target |
| 297 | kids2 = sum([itm["kids"] for itm in rc2]) # total resulting kid count |
| 298 | |
| 299 | assert len(set(names0 + names1)) == len(names2) |
| 300 | assert kids2 == dup_kids |
| 301 | |
| 302 | |
| 303 | test_4412_path = os.path.normpath(f'{__file__}/../../tests/resources/test_4412.pdf') |
nothing calls this directly
no test coverage detected
searching dependent graphs…