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)
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'))
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'))
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'))
def test_element_not_matched(self): self.assert_not_match('<html></html>', elem('div'))
def test_closed_root_element_match(self): self.assert_match('<html/>', elem('html'))
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)
def test_non_root_element_match(self): self.assert_match('<html><head/><body><div></div></body></html>', elem('div'))
def test_root_element_match(self): self.assert_match('<html></html>', elem('html'))
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)
def test_nested_elements_with_wrong_child_element_not_matched(self): self.assert_not_match('<html><body/></html>', elem('html', (elem('div'))))
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'))
def test_nested_elements_match(self): self.assert_match('<html><body/></html>', elem('html', elem('body')))
def test_element_with_attribute_match(self): self.assert_match('<html><body id="the_body"></body></html>', elem('body', id='the_body'))
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'))
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'))
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'))
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'))
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'))
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'))
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'))
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'))