Example #1
0
    def test_element_def_construction(self):
        child_element_def = text('child')
        parent_element_def = elem('parent', child_element_def, id="abc", title="the parent")

        self.assertEquals(r'^parent$', parent_element_def.name_regex)
        self.assertIsNotNone(parent_element_def.name_matcher)
        self.assertIsNone(parent_element_def.content)
        self.assertIsNone(parent_element_def.parent)
        self.assertEquals(1, len(parent_element_def.children))
        self.assertIn(child_element_def, parent_element_def.children)
        self.assertEquals(2, len(parent_element_def.attrs))
        self.assertEquals('abc', parent_element_def.attrs['id'])
        self.assertEquals('the parent', parent_element_def.attrs['title'])

        self.assertEquals(parent_element_def, child_element_def.parent)
        self.assertEquals('child', child_element_def.content)
Example #2
0
    def test_element_def_construction(self):
        child_element_def = text('child')
        parent_element_def = elem('parent',
                                  child_element_def,
                                  id="abc",
                                  title="the parent")

        self.assertEquals(r'^parent$', parent_element_def.name_regex)
        self.assertIsNotNone(parent_element_def.name_matcher)
        self.assertIsNone(parent_element_def.content)
        self.assertIsNone(parent_element_def.parent)
        self.assertEquals(1, len(parent_element_def.children))
        self.assertIn(child_element_def, parent_element_def.children)
        self.assertEquals(2, len(parent_element_def.attrs))
        self.assertEquals('abc', parent_element_def.attrs['id'])
        self.assertEquals('the parent', parent_element_def.attrs['title'])

        self.assertEquals(parent_element_def, child_element_def.parent)
        self.assertEquals('child', child_element_def.content)
Example #3
0
 def test_element_with_one_attribute_partial_match(self):
     self.assert_match('<html><body id="this_is_the_body"></body></html>', elem('body', id='is_the'))
Example #4
0
 def test_element_with_one_attribute_wrong_value_not_matched(self):
     self.assert_not_match('<html><body id="the_body" title="some_name"/></html>',
                           elem('body', id='the_body', title='some_other_name'))
Example #5
0
 def test_element_with_multiple_attributes_match(self):
     self.assert_match('<html><body id="the_body" title="some_name"/></html>',
                       elem('body', id='the_body', title='some_name'))
Example #6
0
 def test_element_not_matched(self):
     self.assert_not_match('<html></html>', elem('div'))
Example #7
0
 def test_closed_root_element_match(self):
     self.assert_match('<html/>', elem('html'))
Example #8
0
    def test_element_def_construction_with_escaped_attribute_name(self):
        element_def = elem('element', class_='some-class')

        self.assertEquals('some-class', element_def.attrs['class'])
        self.assertFalse('class_' in element_def.attrs)
Example #9
0
 def test_non_root_element_match(self):
     self.assert_match('<html><head/><body><div></div></body></html>',
                       elem('div'))
Example #10
0
 def test_closed_root_element_match(self):
     self.assert_match('<html/>', elem('html'))
Example #11
0
 def test_root_element_match(self):
     self.assert_match('<html></html>', elem('html'))
Example #12
0
    def test_element_def_construction_with_escaped_attribute_name(self):
        element_def = elem('element', class_='some-class')

        self.assertEquals('some-class', element_def.attrs['class'])
        self.assertFalse('class_' in element_def.attrs)
Example #13
0
    def test_element_def_construction_with_content_as_keyword(self):
        element_def = elem('element', content='Some content')

        self.assertEquals('Some content', element_def.content)
        self.assertFalse('content' in element_def.attrs)
Example #14
0
 def test_nested_elements_with_wrong_child_element_not_matched(self):
     self.assert_not_match('<html><body/></html>',
                           elem('html', (elem('div'))))
Example #15
0
 def test_element_with_content_not_match(self):
     self.assert_not_match('<html><body><p>This is some content</p></body></html>',
                           elem('p', content='This is some different content'))
Example #16
0
 def test_element_not_matched(self):
     self.assert_not_match('<html></html>', elem('div'))
Example #17
0
 def test_nested_elements_match(self):
     self.assert_match('<html><body/></html>', elem('html', elem('body')))
Example #18
0
 def test_element_with_attribute_match(self):
     self.assert_match('<html><body id="the_body"></body></html>',
                       elem('body', id='the_body'))
Example #19
0
    def test_element_def_construction_with_content_as_keyword(self):
        element_def = elem('element', content='Some content')

        self.assertEquals('Some content', element_def.content)
        self.assertFalse('content' in element_def.attrs)
Example #20
0
 def test_element_with_multiple_attributes_match(self):
     self.assert_match(
         '<html><body id="the_body" title="some_name"/></html>',
         elem('body', id='the_body', title='some_name'))
Example #21
0
 def test_root_element_match(self):
     self.assert_match('<html></html>', elem('html'))
Example #22
0
 def test_element_with_attribute_match_when_element_has_additional_attributes(
         self):
     self.assert_match(
         '<html><body id="the_body" title="some_name"/></html>',
         elem('body', id='the_body'))
Example #23
0
 def test_non_root_element_match(self):
     self.assert_match('<html><head/><body><div></div></body></html>', elem('div'))
Example #24
0
 def test_element_with_one_attribute_wrong_value_not_matched(self):
     self.assert_not_match(
         '<html><body id="the_body" title="some_name"/></html>',
         elem('body', id='the_body', title='some_other_name'))
Example #25
0
 def test_element_with_attribute_match(self):
     self.assert_match('<html><body id="the_body"></body></html>', elem('body', id='the_body'))
Example #26
0
 def test_element_with_one_attribute_missing_not_matched(self):
     self.assert_not_match('<html><body id="the_body"></body></html>',
                           elem('body', id='the_body', title='other_name'))
Example #27
0
 def test_element_with_attribute_match_when_element_has_additional_attributes(self):
     self.assert_match('<html><body id="the_body" title="some_name"/></html>',
                       elem('body', id='the_body'))
Example #28
0
 def test_element_with_one_attribute_partial_match(self):
     self.assert_match('<html><body id="this_is_the_body"></body></html>',
                       elem('body', id='is_the'))
Example #29
0
 def test_element_with_one_attribute_missing_not_matched(self):
     self.assert_not_match('<html><body id="the_body"></body></html>',
                           elem('body', id='the_body', title='other_name'))
Example #30
0
 def test_element_with_content_partial_match(self):
     self.assert_match(
         '<html><body><p>This is some content</p></body></html>',
         elem('p', content='some'))
Example #31
0
 def test_element_with_content_partial_match(self):
     self.assert_match('<html><body><p>This is some content</p></body></html>', elem('p', content='some'))
Example #32
0
 def test_nested_elements_with_wrong_child_element_not_matched(self):
     self.assert_not_match('<html><body/></html>', elem('html', (elem('div'))))
Example #33
0
 def test_nested_elements_match(self):
     self.assert_match('<html><body/></html>', elem('html', elem('body')))
Example #34
0
 def test_element_with_content_not_match(self):
     self.assert_not_match(
         '<html><body><p>This is some content</p></body></html>',
         elem('p', content='This is some different content'))