|
8 | 8 | scriptdir = os.path.abspath(os.path.dirname(__file__))
|
9 | 9 | filename = os.path.join(scriptdir, "resources", "widgettest.pdf")
|
10 | 10 | file_2333 = os.path.join(scriptdir, "resources", "test-2333.pdf")
|
| 11 | +file_4055 = os.path.join(scriptdir, "resources", "test-4055.pdf") |
11 | 12 |
|
12 | 13 |
|
13 | 14 | doc = pymupdf.open()
|
@@ -379,3 +380,57 @@ def get_widgets_by_name(doc):
|
379 | 380 | assert str(e) == 'Annot is not bound to a page'
|
380 | 381 |
|
381 | 382 | doc.close()
|
| 383 | + |
| 384 | + |
| 385 | +def test_4055(): |
| 386 | + """Check correct setting of CheckBox "Yes" values. |
| 387 | +
|
| 388 | + Test scope: |
| 389 | + * setting on with any of 'True' / 'Yes' / built-in values works |
| 390 | + * setting off with any of 'False' or 'Off' works |
| 391 | + """ |
| 392 | + |
| 393 | + # this PDF has digits as "Yes" values. |
| 394 | + doc = pymupdf.open(file_4055) |
| 395 | + page = doc[0] |
| 396 | + |
| 397 | + # Round 1: confirm all check boxes are off |
| 398 | + for w in page.widgets(types=[2]): |
| 399 | + # check that this file doesn't use the "Yes" standard |
| 400 | + assert w.on_state() != "Yes" |
| 401 | + assert w.field_value == "Off" # all check boxes are off |
| 402 | + w.field_value = w.on_state() |
| 403 | + w.update() |
| 404 | + |
| 405 | + page = doc.reload_page(page) # reload page to make sure we start fresh |
| 406 | + |
| 407 | + # Round 2: confirm that fields contain the PDF's own on values |
| 408 | + for w in page.widgets(types=[2]): |
| 409 | + # confirm each value coincides with the "Yes" value |
| 410 | + assert w.field_value == w.on_state() |
| 411 | + w.field_value = False # switch to "Off" using False |
| 412 | + w.update() |
| 413 | + |
| 414 | + page = doc.reload_page(page) |
| 415 | + |
| 416 | + # Round 3: confirm that 'False' achieved "Off" values |
| 417 | + for w in page.widgets(types=[2]): |
| 418 | + assert w.field_value == "Off" |
| 419 | + w.field_value = True # use True for the next round |
| 420 | + w.update() |
| 421 | + |
| 422 | + page = doc.reload_page(page) |
| 423 | + |
| 424 | + # Round 4: confirm that setting to True also worked |
| 425 | + for w in page.widgets(types=[2]): |
| 426 | + assert w.field_value == w.on_state() |
| 427 | + w.field_value = "Off" # set off again |
| 428 | + w.update() |
| 429 | + w.field_value = "Yes" |
| 430 | + w.update() |
| 431 | + |
| 432 | + page = doc.reload_page(page) |
| 433 | + |
| 434 | + # Round 5: final check: setting to "Yes" also does work |
| 435 | + for w in page.widgets(types=[2]): |
| 436 | + assert w.field_value == w.on_state() |
0 commit comments