B
    ê¹`b  ã            
   @   sŠ   d Z ddlZyddlmZ dZW n& ek
rF Z zdZW ddZ[X Y nX ddlmZ ddl	m
Z
mZmZ ee dƒG d	d
„ d
ee
ƒƒZdS )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Œ   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd S )!ÚHTML5LibBuilderSmokeTestz"See ``HTML5TreeBuilderSmokeTest``.c             C   s   t S )N)r   )Úself© r	   ú_/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/bs4/tests/test_html5lib.pyÚdefault_builder   s    z(HTML5LibBuilderSmokeTest.default_builderc          	   C   sd   t dƒ}d}tjdd}| j||d}W d Q R X |  | ¡ |  |¡¡ |  dt|d j	ƒk¡ d S )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_forÚ
assertTrueÚstrÚmessage)r   ZstrainerÚmarkupÚwr   r	   r	   r
   Útest_soupstrainer   s    z*HTML5LibBuilderSmokeTest.test_soupstrainerc             C   s   d}|   |d¡ |   d¡ dS )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)ZassertSoupEquals)r   r   r	   r	   r
   Útest_correctly_nested_tables(   s    z5HTML5LibBuilderSmokeTest.test_correctly_nested_tablesc             C   s$   d}|   |¡}|  d|j ¡ ¡ d S )Nzy<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
   <p>foo</p>
  </body>
</html>s
   <p>foo</p>)r   r   ÚpÚencode)r   r   r   r	   r	   r
   Ú(test_xml_declaration_followed_by_doctype<   s    	
zAHTML5LibBuilderSmokeTest.test_xml_declaration_followed_by_doctypec             C   s:   d}|   |¡}|  d|j ¡ ¡ |  dt| d¡ƒ¡ d S )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   )r   r   Úbodyr   ÚlenÚfind_all)r   r   r   r	   r	   r
   Útest_reparented_markupJ   s    
z/HTML5LibBuilderSmokeTest.test_reparented_markupc             C   s:   d}|   |¡}|  d|j ¡ ¡ |  dt| d¡ƒ¡ d S )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>r   r   )r   r   r   r   r   r    )r   r   r   r	   r	   r
   Ú+test_reparented_markup_ends_with_whitespaceQ   s    
zDHTML5LibBuilderSmokeTest.test_reparented_markup_ends_with_whitespacec             C   sL   d}|   |¡}|jdd\}}| d¡\}}|j|ks:t‚|j|ksHt‚dS )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>ú )ÚstringÚtbodyN)r   r    Únext_elementÚAssertionError)r   r   r   Zspace1Zspace2Ztbody1Ztbody2r	   r	   r
   Ú<test_reparented_markup_containing_identical_whitespace_nodesW   s    
zUHTML5LibBuilderSmokeTest.test_reparented_markup_containing_identical_whitespace_nodesc             C   s^   d}|   |¡}|j}|  d|j¡ |jdd}|jddd }|  ||j¡ |  ||j¡ d S )NzF<div><a>aftermath<p><noscript>target</noscript>aftermath</a></p></div>Útarget)r$   Z	aftermathéÿÿÿÿ)r   Únoscriptr   r&   Úfindr    Zprevious_element)r   r   r   r+   r)   Zfinal_aftermathr	   r	   r
   Ú*test_reparented_markup_containing_childrenb   s    
zCHTML5LibBuilderSmokeTest.test_reparented_markup_containing_childrenc             C   s$   d}|   |¡}t|ƒ d¡s t‚dS )z(Processing instructions become comments.s   <?PITarget PIContent?>z<!--?PITarget PIContent?-->N)r   r   Ú
startswithr'   )r   r   r   r	   r	   r
   Útest_processing_instructionr   s    
z4HTML5LibBuilderSmokeTest.test_processing_instructionc             C   s8   d}|   |¡}| d¡\}}|  ||¡ ||k	s4t‚d S )Ns   <a class="my_class"><p></a>Úa)r   r    r   r'   )r   r   r   Za1Za2r	   r	   r
   Útest_cloned_multivalue_nodex   s
    
z4HTML5LibBuilderSmokeTest.test_cloned_multivalue_nodec             C   s$   d}|   |¡}|  d|j ¡ ¡ d S )Ns   <table><td></tbody>Az><body>A<table><tbody><tr><td></td></tr></tbody></table></body>)r   r   r   r   )r   r   r   r	   r	   r
   Útest_foster_parenting   s    
z.HTML5LibBuilderSmokeTest.test_foster_parentingc             C   sL   d}|   |¡}dd„ |dƒD ƒ dd„ |dƒD ƒ |  t| d¡ƒd¡ d	S )
z€
        Test that extraction does not destroy the tree.

        https://bugs.launchpad.net/beautifulsoup/+bug/1782928
        zW
<html><head></head>
<style>
</style><script></script><body><p>hello</p></body></html>
c             S   s   g | ]}|  ¡ ‘qS r	   )Úextract)Ú.0Úsr	   r	   r
   ú
<listcomp>‘   s    z<HTML5LibBuilderSmokeTest.test_extraction.<locals>.<listcomp>Úscriptc             S   s   g | ]}|  ¡ ‘qS r	   )r3   )r4   r5   r	   r	   r
   r6   ’   s    Ústyler   é   N)r   r   r   r    )r   r   r   r	   r	   r
   Útest_extraction„   s
    
z(HTML5LibBuilderSmokeTest.test_extractionc             C   sJ   d}|   |¡}g }x"| d¡D ]}| | d¡¡ qW |  t|ƒd¡ dS )z‚
        Test that empty comment does not break structure.

        https://bugs.launchpad.net/beautifulsoup/+bug/1806598
        zI
<html>
<body>
<form>
<!----><input type="text">
</form>
</body>
</html>
ÚformÚinputr9   N)r   r    Úextendr   r   )r   r   r   Úinputsr;   r	   r	   r
   Útest_empty_comment–   s    
z+HTML5LibBuilderSmokeTest.test_empty_commentc             C   sz   d}|   |¡}|  d|jj¡ |  d|jj¡ |  d|j d¡j¡ | j |dd}|  d|jjj¡ |  d|jjj¡ d S )Nz=
   <p>

<sourceline>
<b>text</b></sourceline><sourcepos></p>r   é   Ú
sourcelineF)Zstore_line_numbersÚ	sourcepos)r   r   r   rA   rB   r,   Úname)r   r   r   r	   r	   r
   Útest_tracking_line_numbers¬   s    
z3HTML5LibBuilderSmokeTest.test_tracking_line_numbersc             C   s   d S )Nr	   )r   r	   r	   r
   Útest_special_string_containersº   s    z7HTML5LibBuilderSmokeTest.test_special_string_containersN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r   r!   r"   r(   r-   r/   r1   r2   r:   r?   rD   rE   r	   r	   r	   r
   r      s    r   )rI   r   Zbs4.builderr   ZHTML5LIB_PRESENTÚImportErrorÚeZbs4.elementr   Zbs4.testingr   r   r   r   r	   r	   r	   r
   Ú<module>   s   