a
    ÷£Be‚   ã                   @   sh   d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
 ejje dd�G d	d
„ d
e
e	ƒƒZdS )zDTests to ensure that the html5lib tree builder generates good trees.é    N)ÚBeautifulSoup)ÚSoupStraineré   )ÚHTML5LIB_PRESENTÚHTML5TreeBuilderSmokeTestÚSoupTestz?html5lib seems not to be present, not testing its tree builder.)Úreasonc                   @   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 d!„ Zd"S )#ÚTestHTML5LibBuilderz"See ``HTML5TreeBuilderSmokeTest``.c                 C   s   ddl m} |S )Nr   )ÚHTML5TreeBuilder)Zbs4.builderr
   )Úselfr
   © r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/bs4/tests/test_html5lib.pyÚdefault_builder   s    z#TestHTML5LibBuilder.default_builderc                 C   s†   t dƒ}d}tjdd��}t|d|d�}W d   ƒ n1 s<0    Y  | ¡ |  |¡ks\J ‚|\}|jtkspJ ‚dt|j	ƒv s‚J ‚d S )NÚbz<p>A <b>bold</b> statement.</p>T)ÚrecordZhtml5lib)Z
parse_onlyz4the html5lib tree builder doesn't support parse_only)
r   ÚwarningsÚcatch_warningsr   ÚdecodeZdocument_forÚfilenameÚ__file__ÚstrÚmessage)r   ZstrainerÚmarkupÚwÚsoupÚwarningr   r   r   Útest_soupstrainer   s    ,z%TestHTML5LibBuilder.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assert_soup)r   r   r   r   r   Útest_correctly_nested_tables&   s    þÿz0TestHTML5LibBuilder.test_correctly_nested_tablesc                 C   s$   d}|   |¡}d|j ¡ ks 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   ÚpÚencode©r   r   r   r   r   r   Ú(test_xml_declaration_followed_by_doctype:   s    	
z<TestHTML5LibBuilder.test_xml_declaration_followed_by_doctypec                 C   s:   d}|   |¡}d|j ¡ ks J ‚dt| d¡ƒks6J ‚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   Úbodyr   ÚlenÚfind_allr    r   r   r   Útest_reparented_markupH   s    
z*TestHTML5LibBuilder.test_reparented_markupc                 C   s:   d}|   |¡}d|j ¡ ks J ‚dt| d¡ƒks6J ‚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   Ú+test_reparented_markup_ends_with_whitespaceO   s    
z?TestHTML5LibBuilder.test_reparented_markup_ends_with_whitespacec                 C   sL   d}|   |¡}|jdd�\}}| d¡\}}|j|u s:J ‚|j|u sHJ ‚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>ú ©ÚstringZtbodyN)r   r&   Únext_element)r   r   r   Zspace1Zspace2Ztbody1Ztbody2r   r   r   Ú<test_reparented_markup_containing_identical_whitespace_nodesU   s    
zPTestHTML5LibBuilder.test_reparented_markup_containing_identical_whitespace_nodesc                 C   s^   d}|   |¡}|j}d|jks"J ‚|jdd�}|jdd�d }||jksLJ ‚||jksZJ ‚d S )NzF<div><a>aftermath<p><noscript>target</noscript>aftermath</a></p></div>Útargetr*   Z	aftermathéÿÿÿÿ)r   Únoscriptr,   Úfindr&   Zprevious_element)r   r   r   r0   r.   Zfinal_aftermathr   r   r   Ú*test_reparented_markup_containing_children`   s    
z>TestHTML5LibBuilder.test_reparented_markup_containing_childrenc                 C   s$   d}|   |¡}t|ƒ d¡s J ‚dS )z(Processing instructions become comments.s   <?PITarget PIContent?>z<!--?PITarget PIContent?-->N)r   r   Ú
startswithr    r   r   r   Útest_processing_instructionp   s    
z/TestHTML5LibBuilder.test_processing_instructionc                 C   s8   d}|   |¡}| d¡\}}||ks(J ‚||us4J ‚d S )Ns   <a class="my_class"><p></a>Úa)r   r&   )r   r   r   Za1Za2r   r   r   Útest_cloned_multivalue_nodev   s
    
z/TestHTML5LibBuilder.test_cloned_multivalue_nodec                 C   s$   d}|   |¡}d|j ¡ ks 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   Útest_foster_parenting}   s    
z)TestHTML5LibBuilder.test_foster_parentingc                 C   sL   d}|   |¡}dd„ |dƒD ƒ dd„ |dƒD ƒ t| d¡ƒdksHJ ‚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>�   ó    z7TestHTML5LibBuilder.test_extraction.<locals>.<listcomp>Úscriptc                 S   s   g | ]}|  ¡ ‘qS r   r8   r:   r   r   r   r=   �   r>   Ústyler   r   N)r   r%   r&   r    r   r   r   Útest_extraction‚   s
    
z#TestHTML5LibBuilder.test_extractionc                 C   sF   d}|   |¡}g }| d¡D ]}| | d¡¡ qt|ƒdksBJ ‚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Úinputr   N)r   r&   Úextendr%   )r   r   r   ÚinputsrB   r   r   r   Útest_empty_comment”   s    	
z&TestHTML5LibBuilder.test_empty_commentc                 C   sz   d}|   |¡}d|jjksJ ‚d|jjks.J ‚d|j d¡jksDJ ‚| j |dd�}d|jjjksdJ ‚d|jjjksvJ ‚d S )Nz=
   <p>

<sourceline>
<b>text</b></sourceline><sourcepos></p>r"   é   Ú
sourcelineF)Zstore_line_numbersÚ	sourcepos)r   r   rH   rI   r1   Únamer    r   r   r   Útest_tracking_line_numbersª   s    
z.TestHTML5LibBuilder.test_tracking_line_numbersc                 C   s   d S )Nr   )r   r   r   r   Útest_special_string_containers¸   s    z2TestHTML5LibBuilder.test_special_string_containersc           	      C   sj   dD ]`\}}}d| }|   |¡j}| ¡ }d| d¡ }||ksDJ ‚|jdd�}d| }||ksJ ‚qd S )N))z&RightArrowLeftArrow;u   â‡„s   &rlarr;)z&models;u   âŠ§s   &models;)z&Nfr;u   ð�”‘s   &Nfr;)z&ngeqq;u   â‰§Ì¸s   &ngeqq;)z&not;õ   Â¬s   &not;)z&Not;u   â«¬s   &Not;)z&quot;ú"ó   ")z&there4;õ   âˆ´ó   &there4;)z&Therefore;rP   rQ   )z&therefore;rP   rQ   )z&fjlig;Úfjs   fj)z&sqcup;u   âŠ”s   &sqcup;)z&sqcups;u   âŠ”ï¸€s   &sqcups;)z&apos;ú'ó   ')z&verbar;ú|ó   |z<div>%s</div>s   <div>%s</div>Úutf8Úhtml)Ú	formatter)r   Údivr   )	r   Zinput_elementZoutput_unicodeZoutput_elementr   rZ   Zwithout_elementÚexpectZwith_elementr   r   r   Útest_html5_attributes¾   s    	z)TestHTML5LibBuilder.test_html5_attributesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r!   r'   r(   r-   r2   r4   r6   r7   rA   rF   rK   rL   r\   r   r   r   r   r	      s$   
r	   )r`   Zpytestr   Zbs4r   Zbs4.elementr   Ú r   r   r   ÚmarkZskipifr	   r   r   r   r   Ú<module>   s   þ