Skip to content

Commit

Permalink
Add test for setting Radio Buttons
Browse files Browse the repository at this point in the history
The test file has 4 radio buttons in a group on page 0. We set on every one of them and check that the other three are set to Off.
Finally confirm that setting off all buttons also sets the group value to Off.
  • Loading branch information
JorjMcKie committed May 10, 2023
1 parent 3526eda commit 0c288e5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

scriptdir = os.path.abspath(os.path.dirname(__file__))
filename = os.path.join(scriptdir, "resources", "widgettest.pdf")
file_2333 = os.path.join(scriptdir, "resources", "test-2333.pdf")


doc = fitz.open()
Expand Down Expand Up @@ -158,6 +159,32 @@ def test_text2():
assert field.field_type_string == "Text"


def test_2333():
doc = fitz.open(file_2333)
page = doc[0]

def values():
return set(
(
doc.xref_get_key(635, "AS")[1],
doc.xref_get_key(636, "AS")[1],
doc.xref_get_key(637, "AS")[1],
doc.xref_get_key(638, "AS")[1],
doc.xref_get_key(127, "V")[1],
)
)

for i, xref in enumerate((635, 636, 637, 638)):
w = page.load_widget(xref)
w.field_value = True
w.update()
assert values() == set(("/Off", f"{i}", f"/{i}"))
w.field_value=False
w.update()
assert values() == set(("Off", "/Off"))



# def test_deletewidget():
# pdf = fitz.open(filename)
# page = pdf[0]
Expand Down

0 comments on commit 0c288e5

Please sign in to comment.