Exemplo n.º 1
0
 def assert_validate_attributes(self,
                                attrs_dict,
                                actions,
                                expected_attrs_dict,
                                issues=None):
     attrs = []
     start = 3
     for ident in sorted(attrs_dict):
         value = attrs_dict[ident]
         raw = '{}="{}"'.format(ident, value)
         attrs.append(
             HTMLAttribute(raw=raw, start=start, ident=ident, value=value))
         start += len(raw) + 1
     attrs_raw = ' '.join(attr.raw for attr in attrs)
     html_attrs = HTMLAttributes(raw=attrs_raw, start=3, attributes=attrs)
     if attrs_raw:
         tag_raw = '<a {}>'.format(attrs_raw)
     else:
         tag_raw = '<a>'
     tag = HTMLOpenTag(raw=tag_raw,
                       tag='a',
                       attributes=html_attrs,
                       attribute_actions=actions)
     attributes = tag.attributes.as_dict()
     self.assertEqual(expected_attrs_dict, attributes)
     self.assertEqual(issues or [], tag.issues)
Exemplo n.º 2
0
 def test_to_text(self):
     raw = '<p>A <strong>Text</strong> Element</p>'
     strong_attrs = HTMLAttributes(raw='', attributes=[])
     strong_open_tag = HTMLOpenTag(raw='<strong>',
                                   tag='strong',
                                   attributes=strong_attrs)
     strong_close_tag = HTMLCloseTag(raw='</strong>', tag='strong')
     strong_text = HTMLText(raw='Text')
     strong_elem = HTMLElement(raw='<strong>Text</strong>',
                               open_tag=strong_open_tag,
                               close_tag=strong_close_tag,
                               children=[strong_text])
     p_attrs = HTMLAttributes(raw='', attributes=[])
     p_open_tag = HTMLOpenTag(raw='<p>', tag='p', attributes=p_attrs)
     p_close_tag = HTMLCloseTag(raw='</p>', tag='p')
     text1 = HTMLText(raw='A ')
     text2 = HTMLText(raw=' Element')
     p_elem = HTMLElement(raw=raw,
                          open_tag=p_open_tag,
                          close_tag=p_close_tag,
                          children=[text1, strong_elem, text2])
     self.assertEqual('A Text Element', p_elem.to_text())
Exemplo n.º 3
0
 def test_to_text(self):
     raw = '<p>A <strong>Text</strong> Element</p>'
     strong_attrs = HTMLAttributes(raw="", attributes=[])
     strong_open_tag = HTMLOpenTag(raw="<strong>",
                                   tag="strong",
                                   attributes=strong_attrs)
     strong_close_tag = HTMLCloseTag(raw="</strong>", tag="strong")
     strong_text = HTMLText(raw="Text")
     strong_elem = HTMLElement(raw="<strong>Text</strong>",
                               open_tag=strong_open_tag,
                               close_tag=strong_close_tag,
                               children=[strong_text])
     p_attrs = HTMLAttributes(raw="", attributes=[])
     p_open_tag = HTMLOpenTag(raw="<p>", tag="p", attributes=p_attrs)
     p_close_tag = HTMLCloseTag(raw="</p>", tag="p")
     text1 = HTMLText(raw="A ")
     text2 = HTMLText(raw=" Element")
     p_elem = HTMLElement(raw=raw,
                          open_tag=p_open_tag,
                          close_tag=p_close_tag,
                          children=[text1, strong_elem, text2])
     self.assertEqual('A Text Element', p_elem.to_text())
Exemplo n.º 4
0
 def test_str(self):
     raw = '<p class="first">A Text Element</p>'
     attr = HTMLAttribute(raw='class="first"',
                          start=3,
                          ident='class',
                          value='first')
     attrs = HTMLAttributes(raw='class="first"', start=3, attributes=[attr])
     open_tag = HTMLOpenTag(raw='<p class="first">',
                            tag='p',
                            attributes=attrs)
     close_tag = HTMLCloseTag(raw='</p>', start=31, tag='p')
     children = [HTMLInterval(raw='A Text Element', start=17)]
     element = HTMLElement(raw=raw,
                           open_tag=open_tag,
                           close_tag=close_tag,
                           children=children)
     self.assertEqual(raw, str(element))
Exemplo n.º 5
0
 def test_str_without_attrs(self):
     raw = '<strong>'
     attrs = HTMLAttributes(start=3)
     tag = HTMLOpenTag(raw='<strong>', tag='strong', attributes=attrs)
     self.assertEqual(raw, text_type(tag))