|
| 1 | +from __future__importabsolute_import,division,unicode_literals |
| 2 | + |
| 3 | +from .importsupport# flake8: noqa |
| 4 | + |
| 5 | +importhtml5lib |
| 6 | +fromhtml5lib.treeadaptersimportsax |
| 7 | +fromhtml5lib.treewalkersimportgetTreeWalker |
| 8 | + |
| 9 | + |
| 10 | +deftest_to_sax(): |
| 11 | +handler=support.TracingSaxHandler() |
| 12 | +tree=html5lib.parse("""<html xml:lang="en"> |
| 13 | + <title>Directory Listing</title> |
| 14 | + <a href="/"><b/></p> |
| 15 | + """,treebuilder="etree") |
| 16 | +walker=getTreeWalker("etree") |
| 17 | +sax.to_sax(walker(tree),handler) |
| 18 | +expected= [ |
| 19 | +'startDocument', |
| 20 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','html'), |
| 21 | +'html', {(None,'xml:lang'):'en'}), |
| 22 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','head'),'head', {}), |
| 23 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','title'),'title', {}), |
| 24 | + ('characters','Directory Listing'), |
| 25 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','title'),'title'), |
| 26 | + ('characters','\n '), |
| 27 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','head'),'head'), |
| 28 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','body'),'body', {}), |
| 29 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','a'),'a', {(None,'href'):'/'}), |
| 30 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','b'),'b', {}), |
| 31 | + ('startElementNS', ('http://www.w3.org/1999/xhtml','p'),'p', {}), |
| 32 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','p'),'p'), |
| 33 | + ('characters','\n '), |
| 34 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','b'),'b'), |
| 35 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','a'),'a'), |
| 36 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','body'),'body'), |
| 37 | + ('endElementNS', ('http://www.w3.org/1999/xhtml','html'),'html'), |
| 38 | +'endDocument', |
| 39 | + ] |
| 40 | +assertexpected==handler.visited |