summaryrefslogtreecommitdiff
path: root/tests/docx/document_matchers.py
blob: ef2100eccfb6402c33f16a6ed1905f0c3c50a6da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from precisely import all_of, has_attrs, instance_of

from mammoth import documents


def create_element_matcher(element_type):
    def matcher(**kwargs):
        return all_of(
            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)
is_image = create_element_matcher(documents.Image)


is_empty_run = is_run(children=[])


def is_text(value):
    return all_of(
        instance_of(documents.Text),
        has_attrs(value=value),
    )