def testNextSibling(self): parser = AdvancedHTMLParser() parser.parseStr( '<div>Head Text<div id="one">An item</div><div id="two">Another item</div>More Text<div id="three">Last item</div></div>' ) root = parser.getRoot() assert root.getElementById( 'one' ).nextSibling.id == 'two', 'Expected to get element with id "two"' assert root.getElementById( 'one' ).nextSiblingElement.id == 'two', 'Expected to get element with id "two"' assert root.getElementById( 'two' ).nextSibling == 'Another Item', 'Expected to get text "Another Item" after item id=two' assert root.getElementById( 'two' ).nextSiblingElement.id == 'three', 'Expected to get element with id "three"' assert root.getElementById( 'three' ).nextSibling == None, 'Expected to get no element after id="three"' assert root.getElementById( 'three' ).nextSiblingElement == None, 'Expected to get no element after id="three"'
def testPreviousSibling(self): parser = AdvancedHTMLParser() parser.parseStr('<div>Head Text<div id="one">An item</div><div id="two">Another item</div>More Text<div id="three">Last item</div></div>') root = parser.getRoot() assert root.getElementById('one').previousSibling == 'Head Text' , 'Expected to get "Head Text" as first sibling' assert root.getElementById('one').previousSiblingElement == None , 'Expected to get no element prior to first sibling' assert root.getElementById('two').previousSibling.id == 'one' , 'Expected to get element "one" prior to two' assert root.getElementById('two').previousSiblingElement.id == 'one' , 'Expected to get element "one" prior to two'
def test_previousSibling(self): parser = AdvancedHTMLParser() parser.parseStr('<div>Head Text<div id="one">An item</div><div id="two">Another item</div>More Text<div id="three">Last item</div></div>') root = parser.getRoot() assert root.getElementById('one').previousSibling == 'Head Text' , 'Expected to get "Head Text" as first sibling' assert root.getElementById('one').previousSiblingElement == None , 'Expected to get no element prior to first sibling' assert root.getElementById('two').previousSibling.id == 'one' , 'Expected to get element "one" prior to two' assert root.getElementById('two').previousSiblingElement.id == 'one' , 'Expected to get element "one" prior to two'
def testNextSibling(self): parser = AdvancedHTMLParser() parser.parseStr('<div>Head Text<div id="one">An item</div><div id="two">Another item</div>More Text<div id="three">Last item</div></div>') root = parser.getRoot() assert root.getElementById('one').nextSibling.id == 'two' , 'Expected to get element with id "two"' assert root.getElementById('one').nextSiblingElement.id == 'two' , 'Expected to get element with id "two"' assert root.getElementById('two').nextSibling == 'Another Item' , 'Expected to get text "Another Item" after item id=two' assert root.getElementById('two').nextSiblingElement.id == 'three' , 'Expected to get element with id "three"' assert root.getElementById('three').nextSibling == None , 'Expected to get no element after id="three"' assert root.getElementById('three').nextSiblingElement == None , 'Expected to get no element after id="three"'
def test_setRoot(self): parser = AdvancedHTMLParser() assert not parser.root, 'Root should start blank' root = AdvancedTag('html') parser.setRoot(root) assert parser.root, 'Expected root to be set' assert parser.root.tagName == 'html', 'Expected root node to be tagName=html' parser.reset() assert not parser.root, 'Expected parser root to be blank after reset is called' parser.parseStr(root.outerHTML) root = parser.getRoot() assert parser.root, 'Expected root to be set' assert parser.root.tagName == 'html', 'Expected root node to be tagName=html'
def test_setRoot(self): parser = AdvancedHTMLParser() assert not parser.root, 'Root should start blank' root = AdvancedTag('html') parser.setRoot(root) assert parser.root , 'Expected root to be set' assert parser.root.tagName == 'html' , 'Expected root node to be tagName=html' parser.reset() assert not parser.root, 'Expected parser root to be blank after reset is called' parser.parseStr(root.outerHTML) root = parser.getRoot() assert parser.root , 'Expected root to be set' assert parser.root.tagName == 'html' , 'Expected root node to be tagName=html'