B F.�`F� @s�dZddlZyddlmZdZWn&ek rFZzdZWddZ[XYnXddlmZddl m Z m Z m Z e e d�Gd d �d e e ��Z dS) zDTests to ensure that the html5lib tree builder generates good trees.�N)�HTML5TreeBuilderTF)� SoupStrainer)�HTML5TreeBuilderSmokeTest�SoupTest�skipIfz?html5lib seems not to be present, not testing its tree builder.c@s\eZdZdZedd��Zdd�Zdd�Zdd �Zd d �Z d d �Z dd�Z dd�Z dd�Z dS)�HTML5LibBuilderSmokeTestz"See ``HTML5TreeBuilderSmokeTest``.cCst�S)N)r)�self�r �H/opt/alt/python37/lib/python3.7/site-packages/bs4/tests/test_html5lib.py�default_buildersz(HTML5LibBuilderSmokeTest.default_builderc Csdtd�}d}tjdd��}|j||d�}WdQRX|�|��|�|��|�dt|dj �k�dS)N�bz<p>A <b>bold</b> statement.</p>T)�record)Z parse_onlyz4the html5lib tree builder doesn't support parse_onlyr) r�warnings�catch_warnings�soup� assertEqual�decodeZ document_forZ assertTrue�str�message)rZstrainer�markup�wrr r r �test_soupstrainersz*HTML5LibBuilderSmokeTest.test_soupstrainercCsd}|�|d�|�d�dS)z8html5lib inserts <tbody> tags where other parsers don't.z[<table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td>z�<table id="1"><tbody><tr><td>Here's another table:<table id="2"><tbody><tr><td>foo</td></tr></tbody></table></td></tr></tbody></table>z{<table><thead><tr><td>Foo</td></tr></thead><tbody><tr><td>Bar</td></tr></tbody><tfoot><tr><td>Baz</td></tr></tfoot></table>N)ZassertSoupEquals)rrr r r �test_correctly_nested_tables(s z5HTML5LibBuilderSmokeTest.test_correctly_nested_tablescCs$d}|�|�}|�d|j���dS)Nzy<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html> <head> </head> <body> <p>foo</p> </body> </html>s <p>foo</p>)rr�p�encode)rrrr r r �(test_xml_declaration_followed_by_doctype<s  zAHTML5LibBuilderSmokeTest.test_xml_declaration_followed_by_doctypecCs:d}|�|�}|�d|j���|�dt|�d���dS)Nz%<p><em>foo</p> <p>bar<a></a></em></p>zD<body><p><em>foo</em></p><em> </em><p><em>bar<a></a></em></p></body>�r)rr�bodyr�len�find_all)rrrr r r �test_reparented_markupJs z/HTML5LibBuilderSmokeTest.test_reparented_markupcCs:d}|�|�}|�d|j���|�dt|�d���dS)Nz&<p><em>foo</p> <p>bar<a></a></em></p> zE<body><p><em>foo</em></p><em> </em><p><em>bar<a></a></em></p> </body>rr)rrrrrr)rrrr r r �+test_reparented_markup_ends_with_whitespaceQs zDHTML5LibBuilderSmokeTest.test_reparented_markup_ends_with_whitespacecCsLd}|�|�}|jdd�\}}|�d�\}}|j|ks:t�|j|ksHt�dS)z�Verify that we keep the two whitespace nodes in this document distinct when reparenting the adjacent <tbody> tags. z,<table> <tbody><tbody><ims></tbody> </table>� )�stringZtbodyN)rrZ next_element�AssertionError)rrrZspace1Zspace2Ztbody1Ztbody2r r r �<test_reparented_markup_containing_identical_whitespace_nodesWs  zUHTML5LibBuilderSmokeTest.test_reparented_markup_containing_identical_whitespace_nodescCs$d}|�|�}t|��d�s t�dS)z(Processing instructions become comments.s<?PITarget PIContent?>z<!--?PITarget PIContent?-->N)rr� startswithr$)rrrr r r �test_processing_instructionbs z4HTML5LibBuilderSmokeTest.test_processing_instructioncCs8d}|�|�}|�d�\}}|�||�||k s4t�dS)Ns<a class="my_class"><p></a>�a)rrrr$)rrrZa1Za2r r r �test_cloned_multivalue_nodehs   z4HTML5LibBuilderSmokeTest.test_cloned_multivalue_nodeN)�__name__� __module__� __qualname__�__doc__�propertyr rrrr r!r%r'r)r r r r rs   r)r-rZ bs4.builderrZHTML5LIB_PRESENT� ImportError�eZ bs4.elementrZ bs4.testingrrrrr r r r �<module>s