
    ,h]                         d Z ddlZ	 ddlmZ dZddlmZ ddl	m
Z
mZmZ  ee d       G d	 d
ee
             Zy# e$ rZdZY dZ[6dZ[ww xY w)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                   n    e Zd ZdZed        Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zy)HTML5LibBuilderSmokeTestz"See ``HTML5TreeBuilderSmokeTest``.c                     t         S )Nr   )selfs    Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/bs4/tests/test_html5lib.pydefault_builderz(HTML5LibBuilderSmokeTest.default_builder   s        c                 J   t        d      }d}t        j                  d      5 }| j                  ||      }d d d        | j	                  j                         | j                  |             | j                  dt        d   j                        v        y # 1 sw Y   bxY w)Nbz<p>A <b>bold</b> statement.</p>T)record)
parse_onlyz4the html5lib tree builder doesn't support parse_onlyr   )
r   warningscatch_warningssoupassertEqualdecodedocument_for
assertTruestrmessage)r   strainermarkupwr   s        r   test_soupstrainerz*HTML5LibBuilderSmokeTest.test_soupstrainer   s    $2$$D1 	:Q99V99D	:KKM4,,V4	6 	B!		: 	:s   BB"c                 N    d}| j                  |d       | j                  d       y)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)assertSoupEquals)r   r   s     r   test_correctly_nested_tablesz5HTML5LibBuilderSmokeTest.test_correctly_nested_tables(   s6    " 	)	* 	;	<r   c                 ~    d}| j                  |      }| j                  d|j                  j                                y )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   s      r   (test_xml_declaration_followed_by_doctypezAHTML5LibBuilderSmokeTest.test_xml_declaration_followed_by_doctype<   s3     yy 8r   c                     d}| j                  |      }| j                  d|j                  j                                | j                  dt	        |j                  d                   y )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_allr'   s      r   test_reparented_markupz/HTML5LibBuilderSmokeTest.test_reparented_markupJ   sT    9yy `bfbkbkbrbrbtuCc 234r   c                     d}| j                  |      }| j                  d|j                  j                                | j                  dt	        |j                  d                   y )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'   s      r   +test_reparented_markup_ends_with_whitespacezDHTML5LibBuilderSmokeTest.test_reparented_markup_ends_with_whitespaceQ   sT    ;yy bdhdmdmdtdtdvwCc 234r   c                     d}| j                  |      }|j                  d      \  }}|j                  d      \  }}|j                  |u sJ |j                  |u sJ y)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> stringtbodyN)r   r.   next_element)r   r   r   space1space2tbody1tbody2s          r   <test_reparented_markup_containing_identical_whitespace_nodeszUHTML5LibBuilderSmokeTest.test_reparented_markup_containing_identical_whitespace_nodesW   sc     @yy c2w/""f,,""f,,,r   c                 8   d}| j                  |      }|j                  }| j                  d|j                         |j	                  d      }|j                  d      d   }| j                  ||j                         | j                  ||j                         y )NzF<div><a>aftermath<p><noscript>target</noscript>aftermath</a></p></div>targetr4   	aftermath)r   noscriptr   r7   findr.   previous_element)r   r   r   rA   r>   final_aftermaths         r   *test_reparented_markup_containing_childrenzCHTML5LibBuilderSmokeTest.test_reparented_markup_containing_childrenb   s    Yyy ==8#8#89(+ --{-;B?
 	&*=*=>!A!ABr   c                 b    d}| j                  |      }t        |      j                  d      sJ y)z(Processing instructions become comments.s   <?PITarget PIContent?>z<!--?PITarget PIContent?-->N)r   r   
startswithr'   s      r   test_processing_instructionz4HTML5LibBuilderSmokeTest.test_processing_instructionr   s.    .yy 4y##$ABBBr   c                     d}| j                  |      }|j                  d      \  }}| j                  ||       ||usJ y )Ns   <a class="my_class"><p></a>a)r   r.   r   )r   r   r   a1a2s        r   test_cloned_multivalue_nodez4HTML5LibBuilderSmokeTest.test_cloned_multivalue_nodex   sC    3yy s#BR ||r   c                 ~    d}| j                  |      }| j                  d|j                  j                                y )Ns   <table><td></tbody>Az><body>A<table><tbody><tr><td></td></tr></tbody></table></body>)r   r   r,   r   r'   s      r   test_foster_parentingz.HTML5LibBuilderSmokeTest.test_foster_parenting   s6    ,yy Y[_[d[d[k[k[mnr   c                 "   d}| j                  |      } |d      D cg c]  }|j                          c}  |d      D cg c]  }|j                          c} | j                  t        |j	                  d            d       yc c}w c c}w )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>
scriptstyler%      N)r   extractr   r-   r.   )r   r   r   ss       r   test_extractionz(HTML5LibBuilderSmokeTest.test_extraction   so    
 yy "8n--"7m,,T]]3/0!4 	.,s   BBc                     d}| j                  |      }g }|j                  d      D ]"  }|j                  |j                  d             $ | j                  t	        |      d       y)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inputrS   N)r   r.   extendr   r-   )r   r   r   inputsrX   s        r   test_empty_commentz+HTML5LibBuilderSmokeTest.test_empty_comment   s_     yy MM&) 	2DMM$--01	2Va(r   c                    d}| j                  |      }| j                  d|j                  j                         | j                  d|j                  j                         | j                  d|j                  j                  d      j                         | j                  |d      }| j                  d|j                  j                  j                         | j                  d|j                  j                  j                         y )Nz=
   <p>

<sourceline>
<b>text</b></sourceline><sourcepos></p>r*      
sourcelineF)store_line_numbers	sourcepos)r   r   r%   r_   ra   rB   namer'   s      r   test_tracking_line_numbersz3HTML5LibBuilderSmokeTest.test_tracking_line_numbers   s     Uyy DFF--.DFF,,-tvv{{<'@'E'EF yyEy:tvv'8'8'='=>dff&6&6&;&;<r   N)__name__
__module____qualname____doc__propertyr   r    r#   r(   r/   r1   r<   rE   rH   rM   rO   rV   r\   rc    r   r   r
   r
      s]     -   <(955	-C Co
5$),=r   r
   )rg   r   bs4.builderr   HTML5LIB_PRESENTImportErrorebs4.elementr   bs4.testingr   r   r   r
   ri   r   r   <module>rp      sq    J , %  EGd=x)B d=Gd=  s   : AAA