diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-11-30 13:56:29 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-11-30 13:56:29 +0000 |
| commit | fe6fb7ea7380280c8589548fd61b121a917a356a (patch) | |
| tree | 810e648b0132ff4931e91d2cd986689d6600e450 /tests/docx | |
| parent | fe7708b65b7d479e795f379e11ab486d2d08af4e (diff) | |
Read complex field checkboxes, always unchecked
Diffstat (limited to 'tests/docx')
| -rw-r--r-- | tests/docx/body_xml_tests.py | 47 | ||||
| -rw-r--r-- | tests/docx/document_matchers.py | 3 |
2 files changed, 49 insertions, 1 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 117d966..cb5a9b5 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -18,6 +18,7 @@ from .document_matchers import ( is_empty_run, is_run, is_hyperlink, + is_checkbox, is_text, is_table, is_row, @@ -630,6 +631,52 @@ class ComplexFieldTests(object): ))) +class CheckboxTests: + def test_complex_field_checkbox_without_separate_is_read(self): + element = xml_element("w:p", {}, [ + xml_element("w:r", {}, [ + xml_element("w:fldChar", {"w:fldCharType": "begin"}) + ]), + xml_element("w:instrText", {}, [ + xml_text(' FORMCHECKBOX ') + ]), + xml_element("w:r", {}, [ + xml_element("w:fldChar", {"w:fldCharType": "end"}) + ]) + ]) + + paragraph = _read_and_get_document_xml_element(element); + + assert_that(paragraph, is_paragraph(children=is_sequence( + is_empty_run, + is_run(children=is_sequence(is_checkbox())), + ))) + + def test_complex_field_checkbox_with_separate_is_read(self): + element = xml_element("w:p", {}, [ + xml_element("w:r", {}, [ + xml_element("w:fldChar", {"w:fldCharType": "begin"}) + ]), + xml_element("w:instrText", {}, [ + xml_text(' FORMCHECKBOX ') + ]), + xml_element("w:r", {}, [ + xml_element("w:fldChar", {"w:fldCharType": "separate"}) + ]), + xml_element("w:r", {}, [ + xml_element("w:fldChar", {"w:fldCharType": "end"}) + ]) + ]) + + paragraph = _read_and_get_document_xml_element(element); + + assert_that(paragraph, is_paragraph(children=is_sequence( + is_empty_run, + is_empty_run, + is_run(children=is_sequence(is_checkbox())), + ))) + + def test_can_read_tab_element(): element = xml_element("w:tab") tab = _read_and_get_document_xml_element(element) diff --git a/tests/docx/document_matchers.py b/tests/docx/document_matchers.py index d2e5d5c..6b02cf9 100644 --- a/tests/docx/document_matchers.py +++ b/tests/docx/document_matchers.py @@ -9,13 +9,14 @@ def create_element_matcher(element_type): instance_of(element_type), has_attrs(**kwargs), ) - + return matcher is_paragraph = create_element_matcher(documents.Paragraph) is_run = create_element_matcher(documents.Run) is_hyperlink = create_element_matcher(documents.Hyperlink) +is_checkbox = create_element_matcher(documents.Checkbox) is_table = create_element_matcher(documents.Table) is_row = create_element_matcher(documents.TableRow) |
