o
    x!åg7Ö  ã                   @   s„  d Z ddl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mZmZ ddlmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd „ d eƒZG d!d"„ d"eƒZG d#d$„ d$eƒZG d%d&„ d&eƒZ g d'¢Z!G d(d)„ d)eƒZ"G d*d+„ d+eƒZ#dS ),a8  Tests for Beautiful Soup's tree traversal methods.

The tree traversal methods are the main advantage of using Beautiful
Soup over just using a parser.

Different parsers will build different Beautiful Soup trees given the
same markup, but all Beautiful Soup trees can be traversed with the
methods tested here.
é    N)ÚBeautifulSoup)Úbuilder_registry)Ú!AttributeResemblesVariableWarningÚCDataÚCommentÚNavigableStringÚTag)ÚSoupStraineré   )ÚSoupTestc                   @   sH   e Zd Z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 )ÚTestFindz&Basic tests of the find() method.
    c                 C   s"   |   d¡}| d¡jdksJ ‚d S )Nz <a>1</a><b>2</b><a>3</a><b>4</b>ÚbÚ2)ÚsoupÚfindÚstring©Úselfr   © r   úU/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/bs4/tests/test_tree.pyÚtest_find_tag"   ó   
zTestFind.test_find_tagc                 C   s"   |   d¡}|jdddksJ ‚d S )Nu   <h1>RÃ¤ksmÃ¶rgÃ¥s</h1>õ   RÃ¤ksmÃ¶rgÃ¥s©r   )r   r   r   r   r   r   Útest_unicode_text_find&   r   zTestFind.test_unicode_text_findc                 C   s,   |   d¡}t|ƒ d|jddjksJ ‚d S )Nu&   <h1 id="RÃ¤ksmÃ¶rgÃ¥s">here it is</h1>z
here it isr   ©Úid)r   Ústrr   Útextr   r   r   r   Útest_unicode_attribute_find*   s   
z$TestFind.test_unicode_attribute_findc                 C   s"   |   d¡}dt| ¡ ƒksJ ‚dS )z)Test an optimization that finds all tags.ú<a>foo</a><b>bar</b>é   N©r   ÚlenÚfind_allr   r   r   r   Útest_find_everything/   s   
zTestFind.test_find_everythingc                 C   s$   |   d¡}dt| d¡ƒksJ ‚dS )z;Test an optimization that finds all tags with a given name.z<a>foo</a><b>bar</b><a>baz</a>r!   ÚaNr"   r   r   r   r   Útest_find_everything_with_name4   s   
z'TestFind.test_find_everything_with_namec                 C   óP   |   d¡}d| ¡ jksJ ‚d| d¡ ¡ jksJ ‚d| d¡ ¡ jks&J ‚d S )Nz<div></div><p></p>ÚdivÚp©r   r   ÚnameÚfind_previous_siblingÚfind_next_siblingr   r   r   r   Útest_find_with_no_arguments9   ó   
z$TestFind.test_find_with_no_argumentsc                 C   r(   )Nz"text<div>text</div>text<p>text</p>r)   r*   r+   r   r   r   r   Ú+test_find_with_no_arguments_only_finds_tags?   r0   z4TestFind.test_find_with_no_arguments_only_finds_tagsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r%   r'   r/   r1   r   r   r   r   r      s    r   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚTestFindAllz%Basic tests of the find_all() method.c                 C   sX   |   d¡}dt|j ¡ ƒksJ ‚dt| d¡ ¡ ƒksJ ‚dt| d¡ ¡ ƒks*J ‚d S )Nz/<body>text<div>text</div>text<p>text</p></body>r!   r
   r*   r)   )r   r#   Úbodyr$   r   Úfind_previous_siblingsÚfind_next_siblingsr   r   r   r   Ú/test_find_all_with_no_arguments_only_finds_tagsI   s   
z;TestFindAll.test_find_all_with_no_arguments_only_finds_tagsc                 C   sv   |   d¡}|jdddgksJ ‚|jddgdddgksJ ‚|jt d¡dg d¢ks-J ‚|jddg d¢ks9J ‚dS )	z'You can search the tree for text nodes.u   <html>Foo<b>bar</b>Â»</html>Úbarr   ÚFooz.*)r<   r;   õ   Â»TN)r   r$   ÚreÚcompiler   r   r   r   Útest_find_all_text_nodesO   s
   
z$TestFindAll.test_find_all_text_nodesc                 C   st   |   d¡}|  |jdddg d¢¡ |  |jddddg¡ |  |jdddg d	¢¡ |  |jdd
dg d	¢¡ dS )z7You can limit the number of items returned by find_all.z(<a>1</a><a>2</a><a>3</a><a>4</a><a>5</a>r&   é   ©Úlimit)Ú1r   Ú3r
   rD   é
   )rD   r   rE   Ú4Ú5r   N©r   Úassert_selectsr$   r   r   r   r   Útest_find_all_limit\   s
   
zTestFindAll.test_find_all_limitc                 C   s:   |   d¡}|  |ddddg¡ |  |jdddg¡ d S )	Nz!<a>1</a><b>2<a id='foo'>3</a></b>r&   r
   rB   rD   Úfoor   rE   )r   rJ   r   r   r   r   r   Ú%test_calling_a_tag_is_calling_findallf   s   
z1TestFindAll.test_calling_a_tag_is_calling_findallc                 C   s†   |   d¡}g }| |¡ tjdd'}g | |¡ksJ ‚|\}|jtks&J ‚t|jƒ}|dks1J ‚W d   ƒ d S 1 s<w   Y  d S )Nú<a></a>T©ÚrecordzLIgnoring nested list [[...]] to avoid the possibility of infinite recursion.)	r   ÚappendÚwarningsÚcatch_warningsr$   ÚfilenameÚ__file__r   Úmessage)r   r   ÚselfrefÚwÚwarningÚmsgr   r   r   ÚTtest_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursionk   s   



ÿ"úz`TestFindAll.test_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursionc                 C   sX   |   d¡}| d¡}t|dƒsJ ‚| d¡}t|dƒsJ ‚|jdd}t|dƒs*J ‚dS )z%All find_all calls return a ResultSetrN   r&   ÚsourceTrL   r   N)r   r$   Úhasattr©r   r   Úresultr   r   r   Útest_find_all_resultset   s   


z#TestFindAll.test_find_all_resultsetN)
r2   r3   r4   r5   r:   r@   rK   rM   r[   r`   r   r   r   r   r6   F   s    
r6   c                   @   s   e Zd Zdd„ ZdS )ÚTestFindAllBasicNamespacesc                 C   s<   |   d¡}d| d¡jksJ ‚d|jddidjksJ ‚d S )Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">rG   zmathml:msqrtr&   zsvg:fillÚred©Úattrs)r   r   r   r,   r   r   r   r   Útest_find_by_namespaced_name   s   
z7TestFindAllBasicNamespaces.test_find_by_namespaced_nameN)r2   r3   r4   re   r   r   r   r   ra   Œ   s    ra   c                   @   sj   e Zd ZdZd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 )ÚTestFindAllByNamez&Test ways of finding tags by tag name.ÚreturnNc                 C   ó   |   d¡| _d S )Nz<a>First tag.</a>
                                  <b>Second tag.</b>
                                  <c>Third <a>Nested tag.</a> tag.</c>©r   Útree©r   r   r   r   Úsetup_method–   ó   zTestFindAllByName.setup_methodc                 C   s   |   | j d¡ddg¡ d S ©Nr&   ú
First tag.úNested tag.©rJ   rj   r$   rk   r   r   r   Útest_find_all_by_tag_name›   ó   z+TestFindAllByName.test_find_all_by_tag_namec                 C   s\   |   | jjddddg¡ |   | jjdddddg¡ |   | jjdt d¡dddg¡ d S )Nr&   ro   r   Trp   Útag©rJ   rj   r$   r>   r?   rk   r   r   r   Útest_find_all_by_name_and_textŸ   s   ÿÿþz0TestFindAllByName.test_find_all_by_name_and_textc                 C   s   |   | jj d¡dg¡ d S )Nr&   rp   )rJ   rj   Úcr$   rk   r   r   r   Ú!test_find_all_on_non_root_element­   rs   z3TestFindAllByName.test_find_all_on_non_root_elementc                 C   s   |   |  d¡ddg¡ d S rn   )rJ   rj   rk   r   r   r   Ú%test_calling_element_invokes_find_all±   s   z7TestFindAllByName.test_calling_element_invokes_find_allc                 C   s    |   | j tdƒ¡ddg¡ d S rn   )rJ   rj   r$   r	   rk   r   r   r   Útest_find_all_by_tag_strainer´   ó   ÿz/TestFindAllByName.test_find_all_by_tag_strainerc                 C   s    |   | j ddg¡g d¢¡ d S )Nr&   r   ©ro   zSecond tag.rp   rq   rk   r   r   r   Útest_find_all_by_tag_names¹   r{   z,TestFindAllByName.test_find_all_by_tag_namesc                 C   s"   |   | j dddœ¡g d¢¡ d S )NT)r&   r   r|   rq   rk   r   r   r   Útest_find_all_by_tag_dict¾   ó   þz+TestFindAllByName.test_find_all_by_tag_dictc                 C   s"   |   | j t d¡¡g d¢¡ d S )Nz^[ab]$r|   ru   rk   r   r   r   Útest_find_all_by_tag_reÄ   r   z)TestFindAllByName.test_find_all_by_tag_rec                 C   s,   dd„ }|   d¡}|  | |¡ddg¡ d S )Nc                 S   s   | j |  d¡kS ©Nr   )r,   Úget©rt   r   r   r   Úid_matches_nameÍ   rm   zRTestFindAllByName.test_find_all_with_tags_matching_method.<locals>.id_matches_namezƒ<a id="a">Match 1.</a>
                            <a id="1">Does not match.</a>
                            <b id="b">Match 2.</a>zMatch 1.zMatch 2.rI   )r   r„   rj   r   r   r   Ú'test_find_all_with_tags_matching_methodÊ   s   
z9TestFindAllByName.test_find_all_with_tags_matching_methodc                 C   sx   |   d¡}| dd¡}| dt d¡¡}| dddg¡\}}d|jks%J ‚d|jks,J ‚d|jks3J ‚d|jks:J ‚d S )NzH<div class='a b'>1</div><div class='a c'>2</div><div class='a d'>3</div>r)   za dza brE   rD   )r   r   r>   r?   r$   r   )r   r   Úr1Úr2Úr3Úr4r   r   r   Ú%test_find_with_multi_valued_attributeÖ   s   ÿz7TestFindAllByName.test_find_with_multi_valued_attribute©rg   N)r2   r3   r4   r5   rl   rr   rv   rx   ry   rz   r}   r~   r€   r…   rŠ   r   r   r   r   rf   “   s    
rf   c                   @   sŒ   e Z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d „ Zd!S )"ÚTestFindAllByAttributec                 C   ó&   |   d¡}|  |jddddg¡ d S )NzÅ
                         <a id="first">Matching a.</a>
                         <a id="second">
                          Non-matching <b id="first">Matching b.</b>a.
                         </a>Úfirstr   zMatching a.zMatching b.rI   ©r   rj   r   r   r   Útest_find_all_by_attribute_nameä   s   
z6TestFindAllByAttribute.test_find_all_by_attribute_namec                 C   st   d  d¡}d  d¡}|  |¡}|jg|j|dksJ ‚|jg|j| d¡dks*J ‚|jgs8J |j|dgdƒ‚d S )Nu   ××•×œ×©Úutf8u   <a title="××•×œ×©"></a>)Útitlezsomething else)Úencoder   r&   r$   Údecode)r   ÚpeaceÚdatar   r   r   r   Ú%test_find_all_by_utf8_attribute_valueî   s   


 z<TestFindAllByAttribute.test_find_all_by_utf8_attribute_valuec                 C   sX   |   d¡}|  |jdddg¡ |  |jddiddg¡ |  |jdd	idd
g¡ d S )Na0  
                         <a name="name1" class="class1">Name match.</a>
                         <a name="name2" class="class2">Class match.</a>
                         <a name="name3" class="class3">Non-match.</a>
                         <name1>A tag called 'name1'.</name1>
                         Úname1©r,   zA tag called 'name1'.r,   rc   zName match.ÚclassÚclass2zClass match.rI   r   r   r   r   Útest_find_all_by_attribute_dictö   s   
z6TestFindAllByAttribute.test_find_all_by_attribute_dictc                 C   s°   |   d¡}|  |jddddg¡ |  |jddddg¡ |  |jdd	ddg¡ |  | dd¡dg¡ |  |jdd
ddg¡ |  | dd¡dg¡ |  | dd	¡dg¡ d S )Nzî
                         <a class="1">Class 1.</a>
                         <a class="2">Class 2.</a>
                         <b class="1">Class 1.</b>
                         <c class="3 4">Class 3 and 4.</c>
                         r&   rD   ©Úclass_zClass 1.rw   rE   zClass 3 and 4.rG   rc   rI   r   r   r   r   Útest_find_all_by_class  s   
	z-TestFindAllByAttribute.test_find_all_by_classc                 C   st   |   d¡}|jdt d¡d}|  |dg¡ |jdt d¡d}|  |dg¡ |jdt d¡d}|  |dg¡ d S )Nz#<gar class='foo bar'>Found it</gar>ÚgarÚor   úFound itr&   zo b)r   r$   r>   r?   rJ   )r   rj   Úfr   r   r   Ú0test_find_by_class_when_multiple_classes_present  s   
zGTestFindAllByAttribute.test_find_by_class_when_multiple_classes_presentc                 C   sd   |   d¡}|  | dt d¡¡dg¡ dd„ }|  | d|¡g ¡ dd„ }|  | d|¡dg¡ d S )	Nz<a class='bar'>Found it</a>r&   Úbar¢   c                 S   s   t | ƒdkS ©NrA   ©r#   ©Úvaluer   r   r   Úbig_attribute_value/  ó   znTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.big_attribute_valuec                 S   s   t | ƒdkS r¦   r§   r¨   r   r   r   Úsmall_attribute_value4  r«   zpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_value©r   rJ   r$   r>   r?   )r   r   rª   r¬   r   r   r   Ú:test_find_all_with_non_dictionary_for_attrs_finds_by_class*  s   
zQTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_classc                 C   sŒ   |   d¡}| d¡\}}||gsJ | dd¡ƒ‚|gs#J | dd¡ƒ‚|g|jdddks/J ‚|g| dd¡ks:J ‚g | dd¡ksDJ ‚d S )Nz*<a class="foo bar"></a><a class="foo"></a>r&   rL   r;   zfoo barr   zbar foo©r   r$   )r   r   r&   Úa2r   r   r   Ú:test_find_all_with_string_for_attrs_finds_multiple_classes9  s   
zQTestFindAllByAttribute.test_find_all_with_string_for_attrs_finds_multiple_classesc                 C   s0   |   d¡}tddid}|  | |¡dg¡ d S )Nzi
                         <a id="first">Match.</a>
                         <a id="second">Non-match.</a>r   rŽ   rc   zMatch.)r   r	   rJ   r$   )r   rj   Ústrainerr   r   r   Ú'test_find_all_by_attribute_soupstrainerE  s   
z>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainerc                 C   s&   |   d¡}|  |jdd ddg¡ d S )Nú<a id="1">ID present.</a>
                            <a>No ID present.</a>
                            <a id="">ID is empty.</a>r&   r   zNo ID present.rI   r   r   r   r   Ú$test_find_all_with_missing_attributeM  ó   
z;TestFindAllByAttribute.test_find_all_with_missing_attributec                 C   r   )Nr´   Tr   zID present.zID is empty.rI   r   r   r   r   Ú$test_find_all_with_defined_attributeU  r¶   z;TestFindAllByAttribute.test_find_all_with_defined_attributec                 C   s>   |   d¡}ddg}|  |jdd|¡ |  |jdd|¡ d S )Nz[<a id=1>Unquoted attribute.</a>
                            <a id="1">Quoted attribute.</a>zUnquoted attribute.zQuoted attribute.r
   r   rD   rI   )r   rj   Úexpectedr   r   r   Ú$test_find_all_with_numeric_attribute]  s   
z;TestFindAllByAttribute.test_find_all_with_numeric_attributec                 C   s>   |   d¡}|  |jg d¢dddg¡ |  |jg dg ¡ d S )Nz‘<a id="1">1</a>
                            <a id="2">2</a>
                            <a id="3">3</a>
                            <a>No ID.</a>)rD   rE   rG   r   rD   rE   rI   r   r   r   r   Ú(test_find_all_with_list_attribute_valuesf  s   
z?TestFindAllByAttribute.test_find_all_with_list_attribute_valuesc                 C   s,   |   d¡}|  |jt d¡dddg¡ d S )NzÞ<a id="a">One a.</a>
                            <a id="aa">Two as.</a>
                            <a id="ab">Mixed as and bs.</a>
                            <a id="b">One b.</a>
                            <a>No ID.</a>z^a+$r   zOne a.zTwo as.r­   r   r   r   r   Ú5test_find_all_with_regular_expression_attribute_valuer  s   
"zLTestFindAllByAttribute.test_find_all_with_regular_expression_attribute_valuec                 C   sB   |   d¡}|j}|g|jdddksJ ‚g |jdddksJ ‚d S )Nz<b>foo</b><b>bar</b><a>foo</a>r&   rL   r   r;   ©r   r&   r$   ©r   r   r&   r   r   r   Ú'test_find_by_name_and_containing_string~  ó   
z>TestFindAllByAttribute.test_find_by_name_and_containing_stringc                 C   s*   |   d¡}| d¡|jdddksJ ‚d S )Nz"<a>foo</a><a><b><c>foo</c></b></a>r&   rL   r   r¯   r   r   r   r   Ú=test_find_by_name_and_containing_string_when_string_is_buried…  s   
 zTTestFindAllByAttribute.test_find_by_name_and_containing_string_when_string_is_buriedc                 C   sB   |   d¡}|j}|g|jdddksJ ‚g |jdddksJ ‚d S )Nz"<b id="1">foo</b><a id="2">foo</a>r!   rL   )r   r   r
   r;   r¼   r½   r   r   r   Ú,test_find_by_attribute_and_containing_string‰  r¿   zCTestFindAllByAttribute.test_find_by_attribute_and_containing_stringN)r2   r3   r4   r   r—   rœ   rŸ   r¤   r®   r±   r³   rµ   r·   r¹   rº   r»   r¾   rÀ   rÁ   r   r   r   r   rŒ   ã   s"    
	rŒ   c                   @   ó   e Zd ZdZdd„ ZdS )Ú
TestSmoothzTest Tag.smooth.c                 C   s  |   d¡}|j}| d¡ | d¡ | tdƒ¡ | tdƒ¡ | d¡ |  ¡ }t||dƒ}| d¡ | d	¡ | |¡ d |jju sFJ ‚d
t|j	ƒksOJ ‚| 
¡  dt|j	ƒks\J ‚d|j	d kseJ ‚d|jjksmJ ‚d|j	d ksvJ ‚d|j	d ksJ ‚d S )Nz<div>a</div>r   rw   z	Comment 1z	Comment 2ÚdÚspanrD   r   é   é   Úabcr   Ú12r
   r!   )r   r)   rQ   r   Údefault_builderr   rÅ   r   r#   ÚcontentsÚsmooth)r   r   r)   ÚbuilderrÅ   r   r   r   Útest_smooth”  s(   






zTestSmooth.test_smoothN)r2   r3   r4   r5   rÎ   r   r   r   r   rÃ   ‘  ó    rÃ   c                   @   rÂ   )Ú	TestIndexzTest Tag.indexc                 C   sp   |   d¡}|j}t|jƒD ]\}}|| |¡ksJ ‚qt t¡ | d¡ W d   ƒ d S 1 s1w   Y  d S )Nah  <div>
                            <a>Identical</a>
                            <b>Not identical</b>
                            <a>Identical</a>

                            <c><d>Identical with child</d></c>
                            <b>Also not identical</b>
                            <c><d>Identical with child</d></c>
                            </div>r
   )r   r)   Ú	enumeraterË   ÚindexÚpytestÚraisesÚ
ValueError)r   rj   r)   ÚiÚelementr   r   r   Ú
test_indexÀ  s   
	"ÿzTestIndex.test_indexN)r2   r3   r4   r5   rØ   r   r   r   r   rÐ   ½  rÏ   rÐ   c                   @   sb   e Zd ZdZd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 )ÚTestParentOperationsz;Test navigation and searching through an element's parents.rg   Nc                 C   s   |   d¡| _| jj| _d S )Na<  <ul id="empty"></ul>
                                 <ul id="top">
                                  <ul id="middle">
                                   <ul id="bottom">
                                    <b id="start">Start here</b>
                                   </ul>
                                  </ul>)r   rj   r   Ústartrk   r   r   r   rl   Ô  s   z!TestParentOperations.setup_methodc                 C   sF   | j jd dks
J ‚| j jjd dksJ ‚| j jjjd dks!J ‚d S )Nr   ÚbottomÚmiddleÚtop)rÚ   Úparentrk   r   r   r   Útest_parentÞ  s   z TestParentOperations.test_parentc                 C   s    | j jd }|j| j ksJ ‚d S )Nr   )rj   rË   rÞ   )r   Útop_tagr   r   r   Ú%test_parent_of_top_tag_is_soup_objectã  s   z:TestParentOperations.test_parent_of_top_tag_is_soup_objectc                 C   s   d | j ju sJ ‚d S ©N)rj   rÞ   rk   r   r   r   Útest_soup_object_has_no_parentç  ó   z3TestParentOperations.test_soup_object_has_no_parentc                 C   sL   |   | j d¡g d¢¡ |   | jjddddg¡ | jjddg ks$J ‚d S )NÚul©rÛ   rÜ   rÝ   rÜ   r   rÚ   )Úassert_selects_idsrÚ   Úfind_parentsrk   r   r   r   Útest_find_parentsê  s
   ÿz&TestParentOperations.test_find_parentsc                 C   s6   | j jdddd dksJ ‚| j jddd u sJ ‚d S )Nrå   rÝ   r   r   rÚ   )rÚ   Úfind_parentrk   r   r   r   Útest_find_parentñ  s   z%TestParentOperations.test_find_parentc                 C   s"   | j jdd}|jjdksJ ‚d S )Nú
Start herer   r   )rj   r   rÞ   r,   ©r   r   r   r   r   Útest_parent_of_text_element÷  ó   z0TestParentOperations.test_parent_of_text_elementc                 C   s(   | j jdd}| d¡d dksJ ‚d S )Nrì   r   rå   r   rÛ   )rj   r   rê   rí   r   r   r   Útest_text_element_find_parentû  s   z2TestParentOperations.test_text_element_find_parentc                 C   ó&   dd„ | j jD ƒ}|g d¢ksJ ‚d S )Nc                 S   ó&   g | ]}|d urd|j v r|d ‘qS r   rc   ©Ú.0rÞ   r   r   r   Ú
<listcomp>   ó
    þz>TestParentOperations.test_parent_generator.<locals>.<listcomp>ræ   )rÚ   Úparents)r   r÷   r   r   r   Útest_parent_generatorÿ  ó   þz*TestParentOperations.test_parent_generatorc                 C   rñ   )Nc                 S   rò   r   rc   ró   r   r   r   rõ     rö   zGTestParentOperations.test_self_and_parent_generator.<locals>.<listcomp>)rÚ   rÛ   rÜ   rÝ   )rÚ   Úself_and_parents)r   Úresultsr   r   r   Útest_self_and_parent_generator  rù   z3TestParentOperations.test_self_and_parent_generatorr‹   )r2   r3   r4   r5   rl   rß   rá   rã   ré   rë   rî   rð   rø   rü   r   r   r   r   rÙ   Ñ  s    

rÙ   c                   @   ó   e Zd Zddd„ZdS )ÚProximityTestrg   Nc                 C   rh   )Nz<html id="start"><head id="headtag"></head><body id="bodytag"><b id="1">One</b><b id="2">Two</b><b id="3">Three</b></body></html>ri   rk   r   r   r   rl     s   
ÿzProximityTest.setup_methodr‹   ©r2   r3   r4   rl   r   r   r   r   rþ     ó    rþ   c                       óV   e Zd Zd‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
‡  ZS )ÚTestNextOperationsrg   Nc                    s   t t| ƒ ¡  | jj| _d S râ   )Úsuperr  rl   rj   r   rÚ   rk   ©Ú	__class__r   r   rl     s   zTestNextOperations.setup_methodc                 C   s*   | j jdksJ ‚| j jjd dksJ ‚d S )NÚOner   r   )rÚ   Únext_elementrk   r   r   r   Ú	test_next  s   zTestNextOperations.test_nextc                 C   s    | j jdd}|jd u sJ ‚d S ©NÚThreer   )rj   r   r  )r   Úlastr   r   r   Útest_next_of_last_item_is_none   s   z1TestNextOperations.test_next_of_last_item_is_nonec                 C   ó   | j jd u sJ ‚d S râ   )rj   r  rk   r   r   r   Útest_next_of_root_is_none$  ó   z,TestNextOperations.test_next_of_root_is_nonec                 C   sB   |   | j d¡ddg¡ | jjdd |   | jjdddg¡ d S )Nr   ÚTwor
  rA   r   )rJ   rÚ   Úfind_all_nextrk   r   r   r   Útest_find_all_next(  s   z%TestNextOperations.test_find_all_nextc                 C   ó2   | j  d¡d dksJ ‚| j jdddksJ ‚d S )Nr   r   r   r
  r   )rÚ   Ú	find_nextrk   r   r   r   Útest_find_next-  ó   z!TestNextOperations.test_find_nextc                 C   s<   | j jdd}| d¡jdksJ ‚|  | d¡ddg¡ d S )Nr  r   r   r  r
  )rj   r   r  r   rJ   r  rí   r   r   r   Útest_find_next_for_text_element1  ó   z2TestNextOperations.test_find_next_for_text_elementc                 C   sz   | j jdd}dd„ |jD ƒ}|\}}|d dksJ ‚|dks!J ‚dd„ |jD ƒ}|d	d … |ks3J ‚|d
 |ks;J ‚d S )Nr  r   c                 S   ó   g | ]}|‘qS r   r   ©rô   Únoder   r   r   rõ   8  ó    z;TestNextOperations.test_next_generators.<locals>.<listcomp>r   rE   r
  c                 S   r  r   r   r  r   r   r   rõ   >  r  r
   r   )rj   r   Únext_elementsÚself_and_next_elements)r   rÚ   Ú
successorsrt   rË   Úsuccessors2r   r   r   Útest_next_generators6  s   z'TestNextOperations.test_next_generatorsr‹   )r2   r3   r4   rl   r  r  r  r  r  r  r!  Ú__classcell__r   r   r  r   r    s    r  c                       r  )ÚTestPreviousOperationsrg   Nc                    ó"   t t| ƒ ¡  | jjdd| _d S r	  )r  r#  rl   rj   r   Úendrk   r  r   r   rl   D  rï   z#TestPreviousOperations.setup_methodc                 C   s*   | j jd dks
J ‚| j jjdksJ ‚d S )Nr   rE   r  )r%  Úprevious_elementrk   r   r   r   Útest_previousH  s   z$TestPreviousOperations.test_previousc                 C   s   | j  d¡}|jd u sJ ‚d S )NÚhtml)rj   r   r&  )r   rŽ   r   r   r   Ú#test_previous_of_first_item_is_noneL  s   z:TestPreviousOperations.test_previous_of_first_item_is_nonec                 C   r  râ   )rj   r&  rk   r   r   r   Útest_previous_of_root_is_noneP  r  z4TestPreviousOperations.test_previous_of_root_is_nonec                 C   s4   |   | j d¡g d¢¡ |   | jjdddg¡ d S )Nr   ©r
  r  r  r
   r   r  )rJ   r%  Úfind_all_previousrk   r   r   r   Útest_find_all_previousT  s   z-TestPreviousOperations.test_find_all_previousc                 C   r  )Nr   r   rE   r  r   )r%  Úfind_previousrk   r   r   r   Útest_find_previous[  r  z)TestPreviousOperations.test_find_previousc                 C   s<   | j jdd}| d¡jdksJ ‚|  | d¡g d¢¡ d S )Nr
  r   r   r+  )rj   r   r.  r   rJ   r,  rí   r   r   r   Ú#test_find_previous_for_text_element_  r  z:TestPreviousOperations.test_find_previous_for_text_elementc                 C   s8   | j jddd}|  |jg d¢¡ |  |jg d¢¡ d S )Nr   r  r   )ÚbodytagÚheadtagrÚ   )rD   r1  r2  rÚ   )rj   r   rç   Úprevious_elementsÚself_and_previous_elements)r   rÚ   r   r   r   Útest_previous_generatorsd  s   z/TestPreviousOperations.test_previous_generatorsr‹   )r2   r3   r4   rl   r'  r)  r*  r-  r/  r0  r5  r"  r   r   r  r   r#  C  s    r#  c                   @   rý   )ÚSiblingTestrg   Nc                 C   s&   d}t  d¡ d|¡}|  |¡| _d S )Na‰  <html>
                    <span id="1">
                     <span id="1.1"></span>
                    </span>
                    <span id="2">
                     <span id="2.1"></span>
                    </span>
                    <span id="3">
                     <span id="3.1"></span>
                    </span>
                    <span id="4"></span>
                    </html>z\n\s*Ú )r>   r?   Úsubr   rj   )r   Úmarkupr   r   r   rl   k  s   zSiblingTest.setup_methodr‹   rÿ   r   r   r   r   r6  j  r   r6  c                       r  )ÚTestNextSiblingrg   Nc                    r$  )NrD   r   )r  r:  rl   rj   r   rÚ   rk   r  r   r   rl     rï   zTestNextSibling.setup_methodc                 C   r  râ   )rj   Únext_siblingrk   r   r   r   Ú!test_next_sibling_of_root_is_noneƒ  rä   z1TestNextSibling.test_next_sibling_of_root_is_nonec                 C   óB   | j jd dks
J ‚| j jjd dksJ ‚| j jd dksJ ‚d S )Nr   r   rE   ú1.1)rÚ   r;  r  rk   r   r   r   Útest_next_sibling†  ó   z!TestNextSibling.test_next_siblingc                 C   óN   | j jjd u s	J ‚| j jdd}|jd u sJ ‚| j jdd}|jd u s%J ‚d S )Nr>  r   rG   )rj   r(  r;  r   )r   Únested_spanÚ	last_spanr   r   r   Útest_next_sibling_may_not_exist  ó
   z/TestNextSibling.test_next_sibling_may_not_existc                 C   ó   | j  d¡d dksJ ‚d S )NrÅ   r   r   )rÚ   r.   rk   r   r   r   Útest_find_next_sibling–  ó   z&TestNextSibling.test_find_next_siblingc                 C   ó4   |   | j d¡g d¢¡ |   | jjdddg¡ d S )NrÅ   ©r   rE   rG   rE   r   )rç   rÚ   r9   rk   r   r   r   Útest_next_siblings™  s   z"TestNextSibling.test_next_siblingsc                 C   ó,   |   | jjg d¢¡ |   | jjg d¢¡ d S )NrJ  )rD   r   rE   rG   )rç   rÚ   Únext_siblingsÚself_and_next_siblingsrk   r   r   r   Útest_next_siblings_generatorsž  ó   z-TestNextSibling.test_next_siblings_generatorsc                 C   óv   |   d¡}|jdd}|jjdksJ ‚|jjdksJ ‚|  | d¡dg¡ |jdddks/J ‚|jddd u s9J ‚d S )NúFoo<b>bar</b>bazr<   r   r   Úbazr;   Únonesuch)r   r   r;  r,   rJ   r9   r.   ©r   r   rÚ   r   r   r   Ú"test_next_sibling_for_text_element¢  ó   
z2TestNextSibling.test_next_sibling_for_text_elementr‹   )r2   r3   r4   rl   r<  r?  rD  rG  rK  rO  rV  r"  r   r   r  r   r:  ~  s    	r:  c                       r  )ÚTestPreviousSiblingrg   Nc                    r$  )NrG   r   )r  rX  rl   rj   r   r%  rk   r  r   r   rl   ®  rï   z TestPreviousSibling.setup_methodc                 C   r  râ   )rj   Úprevious_siblingrk   r   r   r   Ú%test_previous_sibling_of_root_is_none²  rä   z9TestPreviousSibling.test_previous_sibling_of_root_is_nonec                 C   r=  )Nr   rE   r   z3.1)r%  rY  r&  rk   r   r   r   Útest_previous_siblingµ  r@  z)TestPreviousSibling.test_previous_siblingc                 C   rA  )Nr>  r   rD   )rj   r(  rY  r   )r   rB  Ú
first_spanr   r   r   Ú#test_previous_sibling_may_not_exist¼  rE  z7TestPreviousSibling.test_previous_sibling_may_not_existc                 C   rF  )NrÅ   r   rE   )r%  r-   rk   r   r   r   Útest_find_previous_siblingÅ  rH  z.TestPreviousSibling.test_find_previous_siblingc                 C   rI  )NrÅ   ©rE   r   rD   rD   r   )rç   r%  r8   rk   r   r   r   Útest_previous_siblingsÈ  s   ÿz*TestPreviousSibling.test_previous_siblingsc                 C   rL  )Nr_  )rG   rE   r   rD   )rç   r%  Úprevious_siblingsÚself_and_previous_siblingsrk   r   r   r   Ú!test_previous_siblings_generatorsÏ  rP  z5TestPreviousSibling.test_previous_siblings_generatorsc                 C   rQ  )NrR  rS  r   r   r<   r;   rT  )r   r   rY  r,   rJ   r8   r-   rU  r   r   r   Ú&test_previous_sibling_for_text_elementÓ  rW  z:TestPreviousSibling.test_previous_sibling_for_text_elementr‹   )r2   r3   r4   rl   rZ  r[  r]  r^  r`  rc  rd  r"  r   r   r  r   rX  ­  s    	rX  c                   @   s  e Z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d „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zej d-d.d/„ d0d/„ g¡d1d2„ ƒZej d3d4d/„ d5gd6d/„ d7gf¡d8d9„ ƒZd:d;„ Zd<d=„ Zd>d?„ Z d@dA„ Z!dBdC„ Z"dDdE„ Z#dFdG„ Z$dHdI„ Z%dJdK„ Z&dLdM„ Z'dNdO„ Z(dPdQ„ Z)dRdS„ Z*dTdU„ Z+dVdW„ Z,dXdY„ Z-dZd[„ Z.d\d]„ Z/d^d_„ Z0d`da„ Z1dbdc„ Z2ddde„ Z3dfdg„ Z4ej dhg di¢¡djdk„ ƒZ5dldm„ Z6dndo„ Z7dpdq„ Z8drds„ Z9dtdu„ Z:dvS )wÚTestTreeModificationc                 C   sl   |   d¡}d|jd< | ¡ |  d¡ksJ ‚|jd= | ¡ |  d¡ks$J ‚d|jd< | ¡ |  d¡ks4J ‚d S )	Nz<a id="1"></a>r!   r   z<a id="2"></a>rN   rL   Úid2z<a id2="foo"></a>)r   r&   r”   Údocument_forr   r   r   r   Útest_attribute_modificationß  s   


z0TestTreeModification.test_attribute_modificationc                 C   sl   t  d¡ƒ }| jd|d}t||dƒ}t||dƒ}d|d< |j d|¡ |j d	|¡ |j ¡ d
ks4J ‚d S )Nr(  z<body></body>©rÍ   r&   Úolzhttp://foo.com/Úhrefr   r
   s4   <body><a href="http://foo.com/"></a><ol></ol></body>)r   Úlookupr   r   r7   Úinsertr“   )r   rÍ   r   r&   rj  r   r   r   Útest_new_tag_creationè  s   ÿz*TestTreeModification.test_new_tag_creationc                 C   s\   d}|   |¡}|jdd}|j}|jdd |j¡ |j|ks!J ‚| ¡ |  d¡ks,J ‚d S )NzT<p id="1">Don't leave me <b>here</b>.</p>
                <p id="2">Don't leave!</p>r   r   zD<p id="1">Don't leave me .</p>
<p id="2">Don't leave!<b>here</b></p>)r   r   r   rQ   rÞ   r”   rg  )r   Údocr   Úsecond_paraÚboldr   r   r   Ú!test_append_to_contents_moves_tagõ  s   

ÿz6TestTreeModification.test_append_to_contents_moves_tagc           	      C   sÔ   |   d¡}| d¡}| | d¡¡}|jdksJ ‚| d| d¡¡\}|jdks*J ‚| d¡}|dks5J ‚| dd¡}|ddgksCJ ‚| d	d
¡}|d	d
gksQJ ‚| ddg¡}|ddgks`J ‚| 	¡ dkshJ ‚d S )Nz<html></html>r(  Úheadr   r’   rH   rE   rG   Ú6Ú7Ú8Ú9Ú3456789)
r   r   rQ   Únew_tagr,   rm  Úinsert_beforeÚinsert_afterÚextendÚget_text)	r   r   r(  rs  r’   Útext5Útext34Útext67Útext89r   r   r   Ú&test_insertion_returns_inserted_things  s   


z;TestTreeModification.test_insertion_returns_inserted_thingsc                 C   s0   d}|   |¡}|j}| |j¡}||ksJ ‚d S )Nz<a></a><b><c></c></b>)r   r&   Úreplace_withrw   ©r   r   r   r&   Únew_ar   r   r   Ú1test_replace_with_returns_thing_that_was_replaced  s
   
zFTestTreeModification.test_replace_with_returns_thing_that_was_replacedc                 C   s,   d}|   |¡}|j}| ¡ }||ksJ ‚d S )Nú<a><b></b><c></c></a>)r   r&   Úunwrapr„  r   r   r   Ú+test_unwrap_returns_thing_that_was_replaced   s
   
z@TestTreeModification.test_unwrap_returns_thing_that_was_replacedc                 C   s”   |   d¡}|j}| ¡  d |ju sJ ‚t t¡ | ¡  W d   ƒ n1 s'w   Y  t t¡ | |j	¡ W d   ƒ d S 1 sCw   Y  d S )Nz<a><b>Foo</b></a><c>Bar</c>)
r   r&   ÚextractrÞ   rÓ   rÔ   rÕ   rˆ  rƒ  rw   r½   r   r   r   ÚItest_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parent'  s   

ÿ"ÿz^TestTreeModification.test_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parentc                 C   sF   d}|   |¡}|j}|j |¡}||ksJ ‚| ¡ |  |¡ks!J ‚d S )Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)r   rw   rƒ  r”   rg  )r   r   r   rw   r_   r   r   r   Útest_replace_tag_with_itself1  s   
z1TestTreeModification.test_replace_tag_with_itselfc                 C   sL   d}|   |¡}t t¡ |j |j¡ W d   ƒ d S 1 sw   Y  d S ©Nú<a><b></b></a>)r   rÓ   rÔ   rÕ   r   rƒ  r&   ©r   r   r   r   r   r   Ú1test_replace_tag_with_its_parent_raises_exception9  s
   
"ÿzFTestTreeModification.test_replace_tag_with_its_parent_raises_exceptionc                 C   sN   d}|   |¡}t t¡ |j d|j¡ W d   ƒ d S 1 s w   Y  d S )NrŽ  r   )r   rÓ   rÔ   rÕ   r&   rm  r  r   r   r   Ú,test_insert_tag_into_itself_raises_exception?  s
   
"ÿzATestTreeModification.test_insert_tag_into_itself_raises_exceptionc                 C   sš   |   d¡}| d|jddd|jddd¡\}}d|jksJ ‚d|jks&J ‚t|jƒ\}}}}d|jks6J ‚d|jks=J ‚d|jksDJ ‚d|jksKJ ‚d S )	Nú-<p>And now, a word:</p><p>And we're back.</p>r
   r*   Úp2r   Úp3úAnd now, a word:úAnd we're back.)r   rm  ry  r   ÚlistÚchildren)r   r   r“  r”  Úp1Úp4r   r   r   Útest_insert_multiple_elementsE  s   
&z2TestTreeModification.test_insert_multiple_elementsc           	      C   s¬   |   d¡}d}|   |¡}| d|¡\}}d|jksJ ‚d|jks"J ‚|jD ]	}t|tƒr.J ‚q%t|jƒ\}}}}d|jks?J ‚d|jksFJ ‚d|jksMJ ‚d|jksTJ ‚dS )	z”Inserting one BeautifulSoup object into another actually inserts all
        of its children -- you'll never combine BeautifulSoup objects.
        r’  z<p>p2</p><p>p3</p>r
   r“  r”  r•  r–  N)r   rm  r   ÚdescendantsÚ
isinstancer   r—  r˜  )	r   r   r   Ú	to_insertr“  r”  rÖ   r™  rš  r   r   r   Ú1test_insert_beautifulsoup_object_inserts_childrenQ  s   


zFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrenc                 C   sN   |   d¡}|j}| dd¡ |j\}}| d¡ | d¡ d|jjks%J ‚d S )Nz<p><a>one</a><b>three</b></p>r
   Útwor7  Úthree)r   r&   rm  rË   rƒ  r   r   )r   r   r&   ÚleftÚrightr   r   r   Ú3test_replace_with_maintains_next_element_throughoutf  s   



zHTestTreeModification.test_replace_with_maintains_next_element_throughoutc                 C   sl   |   d¡}|jdd d¡ |jdd}|j}|j|ksJ ‚|j|ks%J ‚|jj|ks-J ‚|jd u s4J ‚d S )Nz<b>Argh!</b>úArgh!r   úHooray!)r   r   rƒ  r   r&  rÞ   r  )r   r   Únew_textr   r   r   r   Útest_replace_final_nodet  s   
z,TestTreeModification.test_replace_final_nodec                 C   s˜   |   d¡}|j dd¡ | ¡ |  d¡ksJ ‚|jdd}|jdks$J ‚|jj|ks,J ‚|jdks3J ‚|jj	|ks;J ‚|j	d u sBJ ‚|j|j
ksJJ ‚d S )Nz<a><b>Argh!</b><c></c></a>r
   r¦  z!<a><b>Argh!Hooray!</b><c></c></a>r   r¥  )r   r   rm  r”   rg  r   r&  r  rY  r;  rw   )r   r   r§  r   r   r   Útest_consecutive_text_nodes~  s   
z0TestTreeModification.test_consecutive_text_nodesc                 C   sT   |   d¡}|j dd¡ |j dd¡ ddg|jjksJ ‚|jjd jdks(J ‚d S )NrN   r   r;   rL   )r   r&   rm  rË   r  r   r   r   r   Útest_insert_string‘  s
   
z'TestTreeModification.test_insert_stringc                 C   s8   |   d¡}|j d¡}|dksJ ‚|j ¡ dksJ ‚d S )Nz<b>1</b>r   z	<b>12</b>)r   r   rQ   r”   r^   r   r   r   Útest_appendš  s   
z TestTreeModification.test_appendc                 C   sø   |   ¡ }| jd|d}t||dƒ}| dd¡ |j d|¡ | ¡ |  d¡ks)J ‚|j}|j|ks3J ‚|j	|ks:J ‚|j
dd	}|j|ksGJ ‚|j|ksNJ ‚|j}|j|ksXJ ‚|j	|ks_J ‚|j
dd	}|j|kslJ ‚|j|kssJ ‚|j|kszJ ‚d S )
Nz%<a><b>Find</b><c>lady!</c><d></d></a>ri  Úmagictagr   Úther
   z=<a><b>Find</b><magictag>the</magictag><c>lady!</c><d></d></a>ÚFindr   )rÊ   r   r   rm  r&   r”   rg  r   r;  rY  r   r  r&  rw   rÞ   )r   rÍ   r   Ú	magic_tagÚb_tagr   Úc_tagr­  r   r   r   Útest_insert_tag   s*   

ÿz$TestTreeModification.test_insert_tagc                 C   s2   d}|   |¡}|j d|j¡ || ¡ ksJ ‚d S )Nz<a>b<c></c>d</a>r
   )r   r&   rm  rw   r”   ©r   r–   r   r   r   r   Ú%test_insert_into_the_current_location½  ó   
z:TestTreeModification.test_insert_into_the_current_locationc                 C   s0   d}|   |¡}|j |j¡ || ¡ ksJ ‚d S r  )r   r&   rQ   r   r”   r³  r   r   r   Ú*test_append_child_thats_already_at_the_endÃ  ó   
z?TestTreeModification.test_append_child_thats_already_at_the_endc                 C   sJ   d}|   |¡}|j|j|j|j|j|jg}|j |¡ d| 	¡ ks#J ‚d S )Nz1<a><b><c><d><e><f><g></g></f></e></d></c></b></a>z1<a><g></g><f></f><e></e><d></d><c></c><b></b></a>)
r   Úgr£   ÚerÄ   rw   r   r&   r|  r”   ©r   r–   r   Úelementsr   r   r   Ú#test_extend_with_a_list_of_elementsÉ  s
   
z8TestTreeModification.test_extend_with_a_list_of_elementsc                 C   s>   d}|   |¡}ddtdƒdg}|j |¡ d| ¡ ksJ ‚d S )NrN   r   rw   rÄ   r¹  z<a>bcde</a>)r   r   r&   r|  r”   rº  r   r   r   Ú"test_extend_with_a_list_of_stringsÐ  s
   
z7TestTreeModification.test_extend_with_a_list_of_stringsÚget_tagsc                 C   s   | S râ   r   rƒ   r   r   r   Ú<lambda>×  ó    zTestTreeModification.<lambda>c                 C   s   | j S râ   )rË   rƒ   r   r   r   r¿  ×  s    c                 C   s`   d}|   |¡}|jddd}|jddd}||ƒ}| |¡ d| ¡ ks&J ‚d| ¡ ks.J ‚d S )NzS<body><div id="d1"><a>1</a><a>2</a><a>3</a><a>4</a></div><div id="d2"></div></body>r)   Úd1r   Úd2z<div id="d1"></div>z3<div id="d2"><a>1</a><a>2</a><a>3</a><a>4</a></div>)r   r   r|  r”   )r   r¾  r–   r   rÁ  rÂ  Útagsr   r   r   Ú&test_extend_with_another_tags_contents×  s   

z;TestTreeModification.test_extend_with_another_tags_contentszstring_source,resultc                 C   s   | j jS râ   )r&   r   ©r   r   r   r   r¿  å  s    z<a></a><b>1</b>c                 C   s   dS )NÚabcder   rÅ  r   r   r   r¿  æ  rÀ  z<a>1</a><b>abcde</b>c           	      C   s   d}|   |¡}tjdd1}||ƒ}|j |¡ |j ¡ |ks!J ‚|\}|jtks+J ‚t	|j
ƒ}|dks6J ‚W d   ƒ d S 1 sAw   Y  d S )Nz<div><a>1</a><b></b></div>TrO   zIA single non-Tag item was passed into Tag.extend. Use Tag.append instead.)r   rR   rS   r   r|  r)   Údecode_contentsrT   rU   r   rV   )	r   Ústring_sourcer_   r–   r   rX   r   rY   rZ   r   r   r   Ú)test_extend_with_a_single_non_tag_elementâ  s   


ÿ"øz>TestTreeModification.test_extend_with_a_single_non_tag_elementc                 C   s2   d}|   |¡}|j d|j¡ d| ¡ ksJ ‚d S )Nz<a><b></b><c></c><d></d></a>r   z<a><d></d><b></b><c></c></a>)r   r&   rm  rÄ   r”   r³  r   r   r   Ú$test_move_tag_to_beginning_of_parentø  rµ  z9TestTreeModification.test_move_tag_to_beginning_of_parentc                 C   s.   |   d¡}|j dd¡ t|jƒdksJ ‚d S )Nz<br/>r
   ÚContentsz<br>Contents</br>)r   Úbrrm  r   r   r   r   r   Ú&test_insert_works_on_empty_element_tagþ  s   
z;TestTreeModification.test_insert_works_on_empty_element_tagc                 C   sò   |   d¡}|j d¡ |j d¡ | ¡ |  d¡ksJ ‚|j |j¡ | ¡ |  d¡ks.J ‚|j}t t¡ | |¡ W d   ƒ n1 sFw   Y  | 	¡  t t¡ | d¡ W d   ƒ n1 sdw   Y  |   d¡}|j | 
d¡¡ d S )	Nr    ÚBAZÚQUUXzQUUX<a>foo</a>BAZ<b>bar</b>úQUUX<b>bar</b><a>foo</a>BAZÚnopeú<a>r&   )r   r   rz  r&   r”   rg  rÓ   rÔ   rÕ   rŠ  ry  ©r   r   r   r   r   r   Útest_insert_before  s    
ÿÿ
z'TestTreeModification.test_insert_beforec                 C   sj   |   d¡}|j ddd¡ |j ddd¡ | ¡ |  d¡ks J ‚|j |jd¡ | ¡ |  d¡ks3J ‚d S )Nr    rÎ  ú rÏ  z$QUUX BAZ<a>foo</a>BAZ QUUX<b>bar</b>ÚFOOz'QUUX BAZ<b>bar</b>FOO<a>foo</a>BAZ QUUX)r   r   rz  r&   r”   rg  r   r   r   r   Útest_insert_multiple_before   s   


ÿ
ÿz0TestTreeModification.test_insert_multiple_beforec                 C   sò   |   d¡}|j d¡ |j d¡ | ¡ |  d¡ksJ ‚|j |j¡ | ¡ |  d¡ks.J ‚|j}t t¡ | |¡ W d   ƒ n1 sFw   Y  | 	¡  t t¡ | d¡ W d   ƒ n1 sdw   Y  |   d¡}|j 
| d¡¡ d S )	Nr    rÎ  rÏ  z<a>foo</a>QUUX<b>bar</b>BAZrÐ  rÑ  rÒ  r&   )r   r   r{  r&   r”   rg  rÓ   rÔ   rÕ   rŠ  rz  ry  rÓ  r   r   r   Útest_insert_after-  s    
ÿÿ
z&TestTreeModification.test_insert_afterc                 C   sj   |   d¡}|j ddd¡ |j ddd¡ | ¡ |  d¡ks J ‚|j |jd¡ | ¡ |  d¡ks3J ‚d S )Nr    rÎ  rÕ  rÏ  z$<a>foo</a>QUUX BAZ<b>bar</b>BAZ QUUXzFOO z(QUUX BAZ<b>bar</b><a>foo</a>FOO BAZ QUUX)r   r   r{  r&   r”   rg  r   r   r   r   Útest_insert_multiple_afterE  s   


ÿ
ÿz/TestTreeModification.test_insert_multiple_afterc                 C   óÀ   |   d¡}| d¡}| d¡}t t¡ | |¡ W d   ƒ n1 s$w   Y  t t¡ | |¡ W d   ƒ n1 s>w   Y  t t¡ | |¡ W d   ƒ d S 1 sYw   Y  d S ©Nr7  r&   )r   ry  Ú
new_stringrÓ   rÔ   rÕ   r{  ÚNotImplementedError©r   r   rt   r   r   r   r   Ú:test_insert_after_raises_exception_if_after_has_no_meaningQ  ó   


ÿÿ"ÿzOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningc                 C   rÚ  rÛ  )r   ry  rÜ  rÓ   rÔ   rÕ   rz  rÝ  rÞ  r   r   r   ÚFtest_insert_before_raises_notimplementederror_if_before_has_no_meaning\  rà  z[TestTreeModification.test_insert_before_raises_notimplementederror_if_before_has_no_meaningc                 C   sv   |   d¡}| d¡\}}| |¡ | ¡ |  d¡ksJ ‚|jd u s#J ‚|j|jks+J ‚|jdks2J ‚|jdks9J ‚d S )Nz;<p>There's <b>no</b> business like <b>show</b> business</p>r   z0<p>There's  business like <b>no</b> business</p>Únoz	 business)	r   r$   rƒ  r”   rg  rÞ   r*   r  r;  )r   r   râ  Úshowr   r   r   Útest_replace_withg  s   



ÿz&TestTreeModification.test_replace_withc                 C   sÀ   t dd}t t¡ | d¡ W d   ƒ n1 sw   Y  |  d¡j}t t¡ |j |¡ W d   ƒ n1 s;w   Y  t t¡ |j d|d¡ W d   ƒ d S 1 sYw   Y  d S )Nr&   r™   z
won't workrŽ  Ústring1Ústring2)r   rÓ   rÔ   rÕ   rƒ  r   r&   r   )r   Úa_tagr   r   r   Útest_replace_with_errorst  s   
ÿÿ"ÿz-TestTreeModification.test_replace_with_errorsc                 C   sœ   d}|   |¡}| d¡}d|_| d¡}| d¡}d}|j ||||¡ | ¡ dks,J ‚|jj|ks4J ‚|jj|ks<J ‚|jj|ksDJ ‚|jj|ksLJ ‚d S )Nr‡  rÄ   zText In D Tagr¹  r£   zRandom Textz;<a><b></b><d>Text In D Tag</d><e></e>Random Text<f></f></a>)r   ry  r   rw   rƒ  r”   r   r  )r   r–   r   Úd_tagÚe_tagÚf_tagÚa_stringr   r   r   Útest_replace_with_multipleƒ  s   



ÿz/TestTreeModification.test_replace_with_multiplec                 C   ó0   d}|   |¡}|j |j¡ d| ¡ ksJ ‚d S )Nr‡  z<a><c></c></a>)r   r   rƒ  rw   r”   r³  r   r   r   Útest_replace_first_child•  r·  z-TestTreeModification.test_replace_first_childc                 C   rî  )Nr‡  rŽ  )r   rw   rƒ  r   r”   r³  r   r   r   Útest_replace_last_child›  r·  z,TestTreeModification.test_replace_last_childc                 C   s  |   d¡}|j}|j}| |¡ | ¡ |  d¡ksJ ‚|jd u s"J ‚|jddjd u s-J ‚|j	d u s4J ‚|j
d u s;J ‚|jd u sBJ ‚|j|jksJJ ‚|j	dksQJ ‚|jj|jksZJ ‚|j
d u saJ ‚|jdd}|j}|j|ksqJ ‚|j
|ksxJ ‚|j	|ksJ ‚|j|ks†J ‚d S )NzQ<a>We<b>reserve<c>the</c><d>right</d></b></a><e>to<f>refuse</f><g>service</g></e>z-<a>We<f>refuse</f></a><e>to<g>service</g></e>r£  r   ÚWeÚto)r   r   r£   rƒ  r”   rg  rÞ   r   r  r&  r;  rY  r&   r¹  r¸  )r   r   Ú
remove_tagÚmove_tagÚto_textÚg_tagr   r   r   Útest_nested_tag_replace_with¡  s0   ÿ


ÿz1TestTreeModification.test_nested_tag_replace_withc                 C   s6   |   d¡}|j ¡  |jd u sJ ‚|jjdksJ ‚d S )NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r   Úemrˆ  r*   r   r   r   r   r   Útest_unwrapÆ  s   

z TestTreeModification.test_unwrapc                 C   sF   |   d¡}|j | d¡¡}| ¡ dksJ ‚| ¡ |  d¡ks!J ‚d S )NzI wish I was bold.r   ú<b>I wish I was bold.</b>)r   r   Úwrapry  r”   rg  )r   r   r©   r   r   r   Ú	test_wrapÎ  s   
zTestTreeModification.test_wrapc                 C   s4   |   d¡}|jj |j¡ | ¡ |  d¡ksJ ‚d S )Nz<b></b>I wish I was bold.rú  )r   r   r;  rû  r”   rg  r   r   r   r   Ú%test_wrap_extracts_tag_from_elsewhereÔ  s   
z:TestTreeModification.test_wrap_extracts_tag_from_elsewherec                 C   sH   |   d¡}|jj |j¡ dt|jjƒksJ ‚| ¡ |  d¡ks"J ‚d S )Nz+<b>I like being bold.</b>I wish I was bold.r!   z+<b>I like being bold.I wish I was bold.</b>)r   r   r;  rû  r#   rË   r”   rg  r   r   r   r   Ú&test_wrap_puts_new_contents_at_the_endÙ  s   

ÿz;TestTreeModification.test_wrap_puts_new_contents_at_the_endc                 C   sâ   |   d¡}t|jjƒdksJ ‚|jdd ¡ }| ¡ dksJ ‚| ¡ dks'J ‚t|jjƒdks1J ‚|jd u s8J ‚|jd u s?J ‚|j	j	d u sGJ ‚|jdd	}|jd
d	}|j	|ksZJ ‚|j
|ksaJ ‚|j|kshJ ‚|j|ksoJ ‚d S )NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>rA   Únavr   z6<html><body>Some content.  More content.</body></html>z<div id="nav">Nav crap</div>r!   zSome content. r   z More content.)r   r#   r7   rË   r   rŠ  r”   rÞ   r&  r  r;  rY  )r   r   Ú	extractedÚ	content_1Ú	content_2r   r   r   Útest_extractá  s"   ÿz!TestTreeModification.test_extractc                 C   sr   |   d¡}|jj}| d¡}| d¡}|j |¡ |j |¡ | ¡  | ¡  ||jjks/J ‚||jjks7J ‚d S )Nr    rL   r;   )r   r&   r   rÜ  rQ   r   rŠ  )r   r   Úfoo_1Úfoo_2Úbar_2r   r   r   Ú4test_extract_distinguishes_between_identical_stringsú  s   


zITestTreeModification.test_extract_distinguishes_between_identical_stringsc                    s8   |   d¡‰ ‡ fdd„ˆ  d¡D ƒ dtˆ jƒksJ ‚d S )Nzv
<html>
<head>
<script>foo</script>
</head>
<body>
 <script>bar</script>
 <a></a>
</body>
<script>baz</script>
</html>c                    s   g | ]}ˆ j  ¡ ‘qS r   )ÚscriptrŠ  )rô   rÖ   rÅ  r   r   rõ     s    zKTestTreeModification.test_extract_multiples_of_same_tag.<locals>.<listcomp>r  z<body>

<a></a>
</body>)r   r$   r   r7   rk   r   rÅ  r   Ú"test_extract_multiples_of_same_tag
  s   
z7TestTreeModification.test_extract_multiples_of_same_tagc                 C   s.   |   d¡}| d¡ ¡  d | d¡u sJ ‚d S )Nz<html>
<body>hi</body>
</html>r7   )r   r   rŠ  r   r   r   r   ÚBtest_extract_works_when_element_is_surrounded_by_identical_strings  s   
zWTestTreeModification.test_extract_works_when_element_is_surrounded_by_identical_stringsc                 C   sd   |   d¡}|j}|j ¡  t|jjƒdksJ ‚t|dƒsJ ‚|j}|jdd dt|jƒks0J ‚dS )zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>r   rË   T)Ú	decomposeN)r   r&   r*   Úclearr#   rË   r]   rø  )r   r   r&   rø  r   r   r   Ú
test_clear  s   

zTestTreeModification.test_clearzmethod_name,expected_result))rœ  ú9<div><em>child1</em><p id="start"></p><p>child3</p></div>)rM  zH<div><em>child1</em><p id="start"><a>Second <em>child</em></a></p></div>)r  r  )r˜  r  )r3  r7  )ra  zF<div><p id="start"><a>Second <em>child</em></a></p><p>child3</p></div>)r÷   r7  c                 C   s<   |   d¡}t|j|ƒ}|D ]}| ¡  q|| ¡ ksJ ‚d S )NzU<div><em>child1</em><p id='start'><a>Second <em>child</em></a></p><p>child3</p></div>)r   Úgetattrr*   rŠ  r”   )r   Úmethod_nameÚexpected_resultr   ÚiteratorrÖ   r   r   r   Útest_extract_during_iteration,  s   ÿ
z2TestTreeModification.test_extract_during_iterationc                 C   s~   |   d¡}| d¡\}}|j}|jj}||||fD ]	}d|ju s"J ‚q| ¡  |||fD ]	}d|ju s5J ‚q,d|ju s=J ‚d S )Nz;<p><a>String <em>Italicized</em></a></p><p>Another para</p>r*   FT)r   r$   r&   rø  r   Ú
decomposedr  )r   r   r™  r“  r&   r   rÖ   r   r   r   Útest_decomposeQ  s   
z#TestTreeModification.test_decomposec                 C   sP   |   d¡}|j}|jj}d|ju sJ ‚| ¡  d|ju sJ ‚d| ¡ ks&J ‚d S )Nz'<div><p>String 1</p><p>String 2</p></p>FTz!<div><p></p><p>String 2</p></div>)r   r)   r*   r   r  r  r”   )r   r   r)   r   r   r   r   Útest_decompose_stringa  s   
z*TestTreeModification.test_decompose_stringc                 C   sB   |   d¡}d|j_|jjdgksJ ‚d|j_|jjdgksJ ‚dS )zTag.string = 'string'z<a></a> <b><c></c></b>rL   r;   N)r   r&   r   rË   r   r   r   r   r   Útest_string_setj  s
   
z$TestTreeModification.test_string_setc                 C   s,   |   d¡}|jj|j_|j ¡ dksJ ‚d S )Nz<a><b>foo</b><c>bar</c>s   <a><b>bar</b><c>bar</c></a>)r   rw   r   r   r&   r“   r   r   r   r   Ú/test_string_set_does_not_affect_original_stringr  s   
zDTestTreeModification.test_string_set_does_not_affect_original_stringc                 C   s0   |   d¡}tdƒ}||j_t|jjtƒsJ ‚d S )NrN   rL   )r   r   r&   r   r  )r   r   Úcdatar   r   r   Ú)test_set_string_preserves_class_of_stringw  s   
z>TestTreeModification.test_set_string_preserves_class_of_stringN);r2   r3   r4   rh  rn  rr  r‚  r†  r‰  r‹  rŒ  r  r‘  r›  rŸ  r¤  r¨  r©  rª  r«  r²  r´  r¶  r¼  r½  rÓ   ÚmarkÚparametrizerÄ  rÉ  rÊ  rÍ  rÔ  r×  rØ  rÙ  rß  rá  rä  rè  rí  rï  rð  r÷  rù  rü  rý  rþ  r  r  r	  r
  r  r  r  r  r  r  r  r   r   r   r   re  Þ  s‚    	

	



þþ
	%þ
	re  )r   r$   rê   rè   r  r  r.  r,  r.   r9   r-   r8   c                   @   ó"   e Zd Zej de¡dd„ ƒZdS )ÚTestDeprecatedArgumentsr  c                 C   s|   |   d¡}t|j|ƒ}tjdd#}|dd |\}|jtks!J ‚t|jƒ}|dks,J ‚W d   ƒ d S 1 s7w   Y  d S )Nú<a>some</a><b>markup</b>TrO   r9  )r   zOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.)	r   r  r   rR   rS   rT   rU   r   rV   ©r   r  r   ÚmethodrX   rY   rZ   r   r   r   Útest_find_type_method_string  s   



ÿ"úz4TestDeprecatedArguments.test_find_type_method_stringN)r2   r3   r4   rÓ   r  r  Úall_find_type_methodsr"  r   r   r   r   r  Ž  ó    r  c                   @   r  )ÚTestWarningsr  c                 C   sŒ   |   d¡}t|j|ƒ}tjdd+}|dd |\}|jtks!J ‚t|jt	ƒs)J ‚t
|jƒ}d|v s4J ‚W d   ƒ d S 1 s?w   Y  d S )Nr  TrO   Úu)Ú_classzN'_class' is an unusual attribute name and is a common misspelling for 'class_')r   r  r   rR   rS   rT   rU   r  rV   r   r   r   r   r   r   Útest_suspicious_syntax_warningŸ  s   



ÿ"ùz+TestWarnings.test_suspicious_syntax_warningN)r2   r3   r4   rÓ   r  r  r#  r(  r   r   r   r   r%  ž  r$  r%  )$r5   rÓ   r>   rR   Úbs4r   Úbs4.builderr   Úbs4.elementr   r   r   r   r   Ú
bs4.filterr	   r7  r   r   r6   ra   rf   rŒ   rÃ   rÐ   rÙ   rþ   r  r#  r6  r:  rX  re  r#  r  r%  r   r   r   r   Ú<module>   sB   
(FP /,?,'/1     %