aboutsummaryrefslogtreecommitdiff
path: root/tests/style_reader_tests.py
blob: 776e2dce4595f27a9199b7788143970e685402bd (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from nose.tools import istest, assert_equal

from mammoth import html_paths, document_matchers, documents, styles
from mammoth.style_reader import read_html_path, read_document_matcher, read_style


@istest
class ReadHtmlPathTests(object):
    @istest
    def can_read_empty_path(self):
        assert_equal(
            html_paths.empty,
            read_html_path("")
        )

    @istest
    def can_read_single_element(self):
        assert_equal(
            html_paths.path([html_paths.element(["p"])]),
            read_html_path("p")
        )

    
    @istest
    def can_read_choice_of_two_elements(self):
        assert_equal(
            html_paths.path([html_paths.element(["ul", "ol"])]),
            read_html_path("ul|ol")
        )

    
    @istest
    def can_read_choice_of_three_elements(self):
        assert_equal(
            html_paths.path([html_paths.element(["ul", "ol", "p"])]),
            read_html_path("ul|ol|p")
        )

    
    @istest
    def can_read_nested_elements(self):
        assert_equal(
            html_paths.path([html_paths.element(["ul"]), html_paths.element(["li"])]),
            read_html_path("ul > li")
        )

    
    @istest
    def can_read_class_on_element(self):
        assert_equal(
            html_paths.path([html_paths.element(["p"], class_names=["tip"])]),
            read_html_path("p.tip")
        )

    
    @istest
    def can_read_multiple_classes_on_element(self):
        assert_equal(
            html_paths.path([html_paths.element(["p"], class_names=["tip", "help"])]),
            read_html_path("p.tip.help")
        )

    
    @istest
    def can_read_when_element_must_be_fresh(self):
        assert_equal(
            html_paths.path([html_paths.element(["p"], fresh=True)]),
            read_html_path("p:fresh")
        )


@istest
class ReadDocumentMatcherTests(object):
    @istest
    def reads_plain_paragraph(self):
        assert_equal(
            document_matchers.paragraph(),
            read_document_matcher("p")
        )
    
    
    @istest
    def reads_paragraph_with_style_id(self):
        assert_equal(
            document_matchers.paragraph(style_id="Heading1"),
            read_document_matcher("p.Heading1")
        )
    
    
    @istest
    def reads_paragraph_with_style_name(self):
        assert_equal(
            document_matchers.paragraph(style_name="Heading 1"),
            read_document_matcher("p[style-name='Heading 1']")
        )
    
    
    @istest
    def reads_paragraph_ordered_list(self):
        assert_equal(
            document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=True)),
            read_document_matcher("p:ordered-list(2)")
        )
    
    
    @istest
    def reads_paragraph_unordered_list(self):
        assert_equal(
            document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=False)),
            read_document_matcher("p:unordered-list(2)")
        )
    
    
    @istest
    def reads_plain_run(self):
        assert_equal(
            document_matchers.run(),
            read_document_matcher("r")
        )
    
    
    @istest
    def reads_run_with_style_id(self):
        assert_equal(
            document_matchers.run(style_id="Emphasis"),
            read_document_matcher("r.Emphasis")
        )
    
    
    @istest
    def reads_run_with_style_name(self):
        assert_equal(
            document_matchers.run(style_name="Emphasis"),
            read_document_matcher("r[style-name='Emphasis']")
        )

    @istest
    def reads_underline(self):
        assert_equal(
            document_matchers.underline,
            read_document_matcher("u")
        )

    @istest
    def reads_strikethrough(self):
        assert_equal(
            document_matchers.strikethrough,
            read_document_matcher("strike")
        )


@istest
def document_matcher_is_mapped_to_html_path_using_fat_arrow():
    style_result = read_style("p => h1")
    assert_equal(
        styles.style(document_matchers.paragraph(), html_paths.path([html_paths.element(["h1"])])),
        style_result.value
    )
    assert_equal([], style_result.messages)