a
    #.c6                   
   @   s   d Z ddlZzddlmZ dZW n( eyH Z zdZW Y dZ[n
dZ[0 0 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 d! Zd"S )#TestHTML5LibBuilderz"See ``HTML5TreeBuilderSmokeTest``.c                 C   s   t S Nr   self r   Q/var/www/brookimports/venv/lib/python3.9/site-packages/bs4/tests/test_html5lib.pydefault_builder   s    z#TestHTML5LibBuilder.default_builderc                 C   sv   t d}d}tjdd}| j||d}W d    n1 s<0    Y  | | |ks\J dt|d jv srJ 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decodeZdocument_forstrmessage)r   Zstrainermarkupwr   r   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_doctype9   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_markupG   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_whitespaceN   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 )zVerify 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_nodesT   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   r.   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_instructiono   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_nodeu   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   r6   r8   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   inputsr@   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   rF   rG   r/   namer   r   r   r   test_tracking_line_numbers   s    
z.TestHTML5LibBuilder.test_tracking_line_numbersc                 C   s   d S r
   r   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;rN   rO   )z&therefore;rN   rO   )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   rX   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+   r0   r2   r4   r5   r?   rD   rI   rJ   rZ   r   r   r   r   r	      s$   

r	   )r^   r   Zbs4.builderr   ZHTML5LIB_PRESENTImportErroreZbs4.elementr    r   r   r   r	   r   r   r   r   <module>   s   