Exemplo n.º 1
0
 def test_parser_nested(self):
     # Tests T parese with multiple nested elements
     html_string = '<div><a></a></div>'
     tempy_elements = T.from_string(html_string)
     self.assertIsInstance(tempy_elements[0], Div)
     self.assertIsInstance(tempy_elements[0][0], A)
     self.assertEqual(tempy_elements[0].render(), html_string)
Exemplo n.º 2
0
 def test_parser_contents(self):
     # Parsed handling of tag contents
     content = "I'm a content"
     html_string = '<div>' + content + '</div>'
     temped = T.from_string(html_string)[0]
     self.assertEqual(temped.childs[0], content)
     self.assertEqual(temped.text(), content)
     self.assertEqual(temped.html(), html.escape(content))
Exemplo n.º 3
0
    def test_parser_attrs(self):
        # Tests parser dealing with tag attributes
        html_string = '<div class="cssClass"></div>'
        temped = T.from_string(html_string)[0]
        self.assertTrue(temped.has_class("cssClass"))

        html_string = '<div class="cssClass" id="cssId"></div>'
        temped = T.from_string(html_string)[0]
        self.assertTrue(temped.is_id("cssId"))

        html_string = '<div custom_attr="foo"></div>'
        temped = T.from_string(html_string)[0]
        self.assertEqual(temped.attrs["custom_attr"], 'foo')

        html_string = '<div custom_bool_attr></div>'
        temped = T.from_string(html_string)[0]
        self.assertIsInstance(temped.attrs["custom_bool_attr"], bool)
Exemplo n.º 4
0
    def test_parser_base(self):
        # Test the T parser
        div_string = '<div></div>'
        tempy_elements = T.from_string(div_string)
        self.assertIsInstance(tempy_elements[0], Div)

        a_string = '<a></a>'
        tempy_elements = T.from_string(a_string)
        self.assertIsInstance(tempy_elements[0], A)

        br_string = '<br>'
        tempy_elements = T.from_string(br_string)
        self.assertIsInstance(tempy_elements[0], Br)

        custom_string = '<custom>'
        tempy_elements = T.from_string(custom_string)
        self.assertIsInstance(tempy_elements[0], DOMElement)
        self.assertIsInstance(tempy_elements[0], Tag)

        custom_string = '<custom_void/>'
        tempy_elements = T.from_string(custom_string)
        self.assertIsInstance(tempy_elements[0], VoidTag)
        self.assertIsInstance(tempy_elements[0], DOMElement)
        self.assertIsInstance(tempy_elements[0], Tag)
Exemplo n.º 5
0
 def test_parser_multi(self):
     # Tests T parese with multiple non-nested elements
     multi_string = '<a></a><div></div>'
     tempy_elements = T.from_string(multi_string)
     self.assertIsInstance(tempy_elements[0], A)
     self.assertIsInstance(tempy_elements[1], Div)