a
    ÷£Be¼  ã                   @   sˆ  d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZ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'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.
é    )Ú	set_traceN)ÚBeautifulSoup)Úbuilder_registryÚHTMLParserTreeBuilder)ÚCDataÚCommentÚDeclarationÚDoctypeÚ	FormatterÚNavigableStringÚScriptÚSoupStrainerÚ
StylesheetÚTagÚTemplateStringé   )ÚSoupTestc                   @   s8   e Zd Z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.

    find() just calls find_all() with limit=1, so it's not tested all
    that thouroughly here.
    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   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/bs4/tests/test_tree.pyÚtest_find_tag-   s    
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_find1   s    
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_find5   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_name@   s    
z'TestFind.test_find_everything_with_nameN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r%   r+   r-   r   r   r   r   r   &   s   r   c                   @   s8   e Zd Z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   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sZJ ‚|jdd�g d¢ksrJ ‚dS )	z'You can search the tree for text nodes.u   <html>Foo<b>bar</b>Â»</html>Úbarr   ÚFooz.*)r4   r3   õ   Â»TN)r   r*   ÚreÚcompiler   r   r   r   Útest_find_all_text_nodesH   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   r<   é
   )r<   r   r=   Ú4Ú5r   N©r   Úassert_selectsr*   r   r   r   r   Útest_find_all_limitV   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   r:   r<   Úfoor!   r=   )r   rB   r   r   r   r   r   Ú%test_calling_a_tag_is_calling_findallb   s    
z1TestFindAll.test_calling_a_tag_is_calling_findallc                 C   s.   |   d¡}g }| |¡ g | |¡ks*J ‚d S )Nú<a></a>)r   Úappendr*   )r   r   Úlr   r   r   ÚTtest_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursiong   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ƒsTJ ‚dS )z%All find_all calls return a ResultSetrF   r,   ÚsourceTrD   r   N)r   r*   Úhasattr)r   r   Úresultr   r   r   Útest_find_all_resultsetq   s    


z#TestFindAll.test_find_all_resultsetN)	r.   r/   r0   r1   r8   rC   rE   rI   rM   r   r   r   r   r2   E   s   
r2   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s8J ‚d S )Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">r?   zmathml:msqrtr,   zsvg:fillÚred©Úattrs)r   r   r   Únamer   r   r   r   Útest_find_by_namespaced_name€   s    
z7TestFindAllBasicNamespaces.test_find_by_namespaced_nameN)r.   r/   r0   rS   r   r   r   r   rN   ~   s   rN   c                   @   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d„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestFindAllByNamez&Test ways of finding tags by tag name.c                 C   s   |   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‰   s    zTestFindAllByName.setup_methodc                 C   s   |   | j d¡ddg¡ d S ©Nr,   ú
First tag.úNested tag.©rB   rV   r*   rW   r   r   r   Útest_find_all_by_tag_nameŽ   s    ÿ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,   rZ   r   Tr[   Útag©rB   rV   r*   r6   r7   rW   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,   r[   )rB   rV   Úcr*   rW   r   r   r   Ú!test_find_all_on_non_root_elementŸ   s    z3TestFindAllByName.test_find_all_on_non_root_elementc                 C   s   |   |  d¡ddg¡ d S rY   )rB   rV   rW   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 rY   )rB   rV   r*   r   rW   r   r   r   Útest_find_all_by_tag_strainer¦   s    þz/TestFindAllByName.test_find_all_by_tag_strainerc                 C   s    |   | j ddg¡g d¢¡ d S )Nr,   r   ©rZ   zSecond tag.r[   r\   rW   r   r   r   Útest_find_all_by_tag_names«   s    þz,TestFindAllByName.test_find_all_by_tag_namesc                 C   s"   |   | j dddœ¡g d¢¡ d S )NT)r,   r   re   r\   rW   r   r   r   Útest_find_all_by_tag_dict°   s    þz+TestFindAllByName.test_find_all_by_tag_dictc                 C   s"   |   | j t d¡¡g d¢¡ d S )Nz^[ab]$re   r_   rW   r   r   r   Útest_find_all_by_tag_reµ   s    þ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"   )rR   Úget©r^   r   r   r   Úid_matches_name½   s    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.rA   )r   rl   rV   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sJJ ‚d|jksXJ ‚d|jksfJ ‚d|jkstJ ‚d S )NzH<div class='a b'>1</div><div class='a c'>2</div><div class='a d'>3</div>Údivza dza br=   r<   )r   r   r6   r7   r*   r   )r   r   Úr1Úr2Zr3Zr4r   r   r   Ú%test_find_with_multi_valued_attributeÇ   s    ÿz7TestFindAllByName.test_find_with_multi_valued_attributeN)r.   r/   r0   r1   rX   r]   r`   rb   rc   rd   rf   rg   rh   rm   rq   r   r   r   r   rT   †   s   rT   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   s&   |   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.rA   ©r   rV   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s6J ‚|jg|j| d¡d�ksTJ ‚|jgspJ |j|dgd�ƒ‚d S )Nu   ×�×•×œ×©Úutf8u   <a title="×�×•×œ×©"></a>)Útitlezsomething else)Úencoder   r,   r*   Údecode)r   Z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>
                         Zname1©rR   zA tag called 'name1'.rR   rP   zName match.ÚclassZclass2zClass match.rA   rt   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,   r<   ©Úclass_zClass 1.ra   r=   zClass 3 and 4.r?   rP   rA   rt   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>ZgarÚor   úFound itr,   zo b)r   r*   r6   r7   rB   )r   rV   Ú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 ©Nr9   ©r)   ©Úvaluer   r   r   Úbig_attribute_value%  s    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_value*  s    zpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_value©r   rB   r*   r6   r7   )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s0J | dd¡ƒ‚|gsFJ | dd¡ƒ‚|g|jddd�ks^J ‚|g| dd¡kstJ ‚g | dd¡ksˆJ ‚d S )Nz*<a class="foo bar"></a><a class="foo"></a>r,   rD   r3   zfoo barr   zbar foo©r   r*   )r   r   r,   Za2r   r   r   Ú:test_find_all_with_string_for_attrs_finds_multiple_classes0  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"   rs   rP   zMatch.)r   r   rB   r*   )r   rV   Ústrainerr   r   r   Ú'test_find_all_by_attribute_soupstrainer<  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.rA   rt   r   r   r   Ú$test_find_all_with_missing_attributeD  s    
z;TestFindAllByAttribute.test_find_all_with_missing_attributec                 C   s&   |   d¡}|  |jdd�ddg¡ d S )Nr“   Tr!   zID present.zID is empty.rA   rt   r   r   r   Ú$test_find_all_with_defined_attributeL  s    
ÿ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!   r<   rA   )r   rV   Úexpectedr   r   r   Ú$test_find_all_with_numeric_attributeU  s    
z;TestFindAllByAttribute.test_find_all_with_numeric_attributec                 C   s*   |   d¡}|  |jg d¢d�ddg¡ d S )Nz‘<a id="1">1</a>
                            <a id="2">2</a>
                            <a id="3">3</a>
                            <a>No ID.</a>)r<   r=   r?   r!   r<   r=   rA   rt   r   r   r   Ú(test_find_all_with_list_attribute_values^  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�   rt   r   r   r   Ú5test_find_all_with_regular_expression_attribute_valueh  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,   rD   r   r3   ©r   r,   r*   ©r   r   r,   r   r   r   Ú'test_find_by_name_and_containing_stringu  s    
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,   rD   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'   rD   )r"   r   r   r3   rš   r›   r   r   r   Ú,test_find_by_attribute_and_containing_string€  s    
zCTestFindAllByAttribute.test_find_by_attribute_and_containing_stringN)r.   r/   r0   ru   r{   r~   r�   r…   rŽ   r�   r’   r”   r•   r—   r˜   r™   rœ   r�   rž   r   r   r   r   rr   Ô   s    		
rr   c                   @   s   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ksŒJ ‚d
t|j	ƒksžJ ‚| 
¡  dt|j	ƒks¸J ‚d|j	d ksÊJ ‚d|jjksÚJ ‚d|j	d ksìJ ‚d|j	d ksþJ ‚d S )Nz<div>a</div>r   ra   z	Comment 1z	Comment 2ÚdÚspanr<   r   é   é   Úabcr   Z12r   r'   )r   rn   rG   r   Údefault_builderr   r¡   r   r)   ÚcontentsZsmooth)r   r   rn   Úbuilderr¡   r   r   r   Útest_smooth‹  s(    






zTestSmooth.test_smoothN)r.   r/   r0   r1   r¨   r   r   r   r   rŸ   ˆ  s   rŸ   c                   @   s   e Zd ZdZdd„ ZdS )Ú	TestIndexzTest Tag.indexc                 C   sn   |   d¡}|j}t|jƒD ]\}}|| |¡ksJ ‚qt t¡� | d¡ W d   ƒ n1 s`0    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   rn   Ú	enumerater¦   ÚindexÚpytestÚraisesÚ
ValueError)r   rV   rn   ÚiÚelementr   r   r   Ú
test_index¶  s    
	zTestIndex.test_indexN)r.   r/   r0   r1   r±   r   r   r   r   r©   ´  s   r©   c                   @   sX   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d„ Zdd„ ZdS )ÚTestParentOperationsz;Test navigation and searching through an element's parents.c                 C   s   |   d¡| _| jj| _d S )Na1  <ul id="empty"></ul>
                                 <ul id="top">
                                  <ul id="middle">
                                   <ul id="bottom">
                                    <b>Start here</b>
                                   </ul>
                                  </ul>)r   rV   r   ÚstartrW   r   r   r   rX   Ê  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sBJ ‚d S )Nr"   ÚbottomÚmiddleÚtop)r³   ÚparentrW   r   r   r   Útest_parentÕ  s    z TestParentOperations.test_parentc                 C   s    | j jd }|j| j ksJ ‚d S )Nr   )rV   r¦   r·   )r   Z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ksJ ‚d S ©N)rV   r·   rW   r   r   r   Útest_soup_object_has_no_parentÞ  s    z3TestParentOperations.test_soup_object_has_no_parentc                 C   s6   |   | j d¡g d¢¡ |   | jjddd�dg¡ d S )NÚul)r´   rµ   r¶   rµ   r!   )Úassert_selects_idsr³   Úfind_parentsrW   r   r   r   Útest_find_parentsá  s    ÿÿz&TestParentOperations.test_find_parentsc                 C   s8   | j  d¡d dksJ ‚| j jddd�d dks4J ‚d S )Nr¼   r"   r´   r¶   r!   )r³   Úfind_parentrW   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   )rV   r   r·   rR   ©r   r$   r   r   r   Útest_parent_of_text_elementë  s    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´   )rV   r   rÀ   rÃ   r   r   r   Útest_text_element_find_parentï  s    z2TestParentOperations.test_text_element_find_parentc                 C   s*   dd„ | j jD ƒ}|s&J dddkgƒ‚d S )Nc                 S   s&   g | ]}|d urd|j v r|d ‘qS ri   rP   )Ú.0r·   r   r   r   Ú
<listcomp>ô  s   ÿz>TestParentOperations.test_parent_generator.<locals>.<listcomp>r´   rµ   r¶   )r³   Úparents)r   rÈ   r   r   r   Útest_parent_generatoró  s    z*TestParentOperations.test_parent_generatorN)r.   r/   r0   r1   rX   r¸   r¹   r»   r¿   rÁ   rÄ   rÅ   rÉ   r   r   r   r   r²   Ç  s   r²   c                   @   s   e Zd Zdd„ ZdS )ÚProximityTestc                 C   s   |   d¡| _d S )Nzg<html id="start"><head></head><body><b id="1">One</b><b id="2">Two</b><b id="3">Three</b></body></html>rU   rW   r   r   r   rX   û  s    ÿzProximityTest.setup_methodN©r.   r/   r0   rX   r   r   r   r   rÊ   ù  s   rÊ   c                       sT   e Zd Z‡ 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 )ÚTestNextOperationsc                    s   t t| ƒ ¡  | jj| _d S rº   )ÚsuperrÌ   rX   rV   r   r³   rW   ©Ú	__class__r   r   rX     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_elementrW   r   r   r   Ú	test_next  s    zTestNextOperations.test_nextc                 C   s    | j jdd�}|jd ksJ ‚d S ©NÚThreer   )rV   r   rÑ   )r   Úlastr   r   r   Útest_next_of_last_item_is_none
  s    z1TestNextOperations.test_next_of_last_item_is_nonec                 C   s   | j jd ksJ ‚d S rº   )rV   rÑ   rW   r   r   r   Útest_next_of_root_is_none  s    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Ô   r9   r!   )rB   r³   Úfind_all_nextrW   r   r   r   Útest_find_all_next  s    z%TestNextOperations.test_find_all_nextc                 C   s2   | j  d¡d dksJ ‚| j jdd�dks.J ‚d S )Nr   r"   r   rÔ   r   )r³   Ú	find_nextrW   r   r   r   Útest_find_next  s    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Ô   )rV   r   rÛ   r   rB   rÙ   rÃ   r   r   r   Útest_find_next_for_text_element  s    z2TestNextOperations.test_find_next_for_text_elementc                 C   sF   | j jdd�}dd„ |jD ƒ}|\}}|d dks6J ‚|dksBJ ‚d S )NrØ   r   c                 S   s   g | ]}|‘qS r   r   ©rÆ   Únoder   r   r   rÇ   "  ó    z:TestNextOperations.test_next_generator.<locals>.<listcomp>r"   r=   rÔ   )rV   r   Znext_elements)r   r³   Ú
successorsr^   r¦   r   r   r   Útest_next_generator   s
    z&TestNextOperations.test_next_generator)r.   r/   r0   rX   rÒ   rÖ   r×   rÚ   rÜ   rÝ   râ   Ú__classcell__r   r   rÎ   r   rÌ      s   rÌ   c                       sT   e Zd Z‡ 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 )ÚTestPreviousOperationsc                    s"   t t| ƒ ¡  | jjdd�| _d S rÓ   )rÍ   rä   rX   rV   r   ÚendrW   rÎ   r   r   rX   *  s    z#TestPreviousOperations.setup_methodc                 C   s*   | j jd dksJ ‚| j jjdks&J ‚d S )Nr"   r=   rØ   )rå   Úprevious_elementrW   r   r   r   Útest_previous.  s    z$TestPreviousOperations.test_previousc                 C   s   | j  d¡}|jd ksJ ‚d S )NÚhtml)rV   r   ræ   )r   rs   r   r   r   Ú#test_previous_of_first_item_is_none2  s    z:TestPreviousOperations.test_previous_of_first_item_is_nonec                 C   s   | j jd ksJ ‚d S rº   )rV   ræ   rW   r   r   r   Útest_previous_of_root_is_none6  s    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Ð   )rB   rå   Úfind_all_previousrW   r   r   r   Útest_find_all_previous:  s    ÿz-TestPreviousOperations.test_find_all_previousc                 C   s2   | j  d¡d dksJ ‚| j jdd�dks.J ‚d S )Nr   r"   r=   rÐ   r   )rå   Úfind_previousrW   r   r   r   Útest_find_previousB  s    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ë   )rV   r   rî   r   rB   rì   rÃ   r   r   r   Ú#test_find_previous_for_text_elementF  s
    ÿz:TestPreviousOperations.test_find_previous_for_text_elementc                 C   sh   | j jdd�}dd„ |jD ƒ}|\}}}}|d dks:J ‚|jdksHJ ‚|jdksVJ ‚|jd	ksdJ ‚d S )
NrÐ   r   c                 S   s   g | ]}|‘qS r   r   rÞ   r   r   r   rÇ   N  rà   zBTestPreviousOperations.test_previous_generator.<locals>.<listcomp>r"   r<   ÚbodyÚheadrè   )rV   r   Zprevious_elementsrR   )r   r³   Zpredecessorsr   rñ   rò   rè   r   r   r   Útest_previous_generatorL  s    z.TestPreviousOperations.test_previous_generator)r.   r/   r0   rX   rç   ré   rê   rí   rï   rð   ró   rã   r   r   rÎ   r   rä   (  s   rä   c                   @   s   e Zd Zdd„ ZdS )ÚSiblingTestc                 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*Ú )r6   r7   Úsubr   rV   )r   Úmarkupr   r   r   rX   [  s    zSiblingTest.setup_methodNrË   r   r   r   r   rô   Y  s   rô   c                       sL   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )ÚTestNextSiblingc                    s"   t t| ƒ ¡  | jjdd�| _d S )Nr<   r!   )rÍ   rø   rX   rV   r   r³   rW   rÎ   r   r   rX   p  s    zTestNextSibling.setup_methodc                 C   s   | j jd ksJ ‚d S rº   )rV   Únext_siblingrW   r   r   r   Ú!test_next_sibling_of_root_is_nonet  s    z1TestNextSibling.test_next_sibling_of_root_is_nonec                 C   sB   | 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   r=   ú1.1)r³   rù   rÑ   rW   r   r   r   Útest_next_siblingw  s    z!TestNextSibling.test_next_siblingc                 C   sN   | j jjd ksJ ‚| j jdd�}|jd ks.J ‚| j jdd�}|jd ksJJ ‚d S )Nrû   r!   r?   )rV   rè   rù   r   )r   Únested_spanZ	last_spanr   r   r   Útest_next_sibling_may_not_exist~  s
    z/TestNextSibling.test_next_sibling_may_not_existc                 C   s   | j  d¡d dksJ ‚d S )Nr¡   r"   r   )r³   Úfind_next_siblingrW   r   r   r   Útest_find_next_sibling‡  s    z&TestNextSibling.test_find_next_siblingc                 C   s4   |   | j d¡g d¢¡ |   | jjdd�dg¡ d S )Nr¡   )r   r=   r?   r=   r!   )r½   r³   Úfind_next_siblingsrW   r   r   r   Útest_next_siblingsŠ  s    ÿz"TestNextSibling.test_next_siblingsc                 C   sv   |   d¡}|jdd�}|jjdks&J ‚|jjdks6J ‚|  | d¡dg¡ |jdd�dks^J ‚|jdd�d ksrJ ‚d S )NúFoo<b>bar</b>bazr4   r   r   Úbazr3   Únonesuch)r   r   rù   rR   rB   r  rÿ   ©r   r   r³   r   r   r   Ú"test_next_sibling_for_text_element�  s    
z2TestNextSibling.test_next_sibling_for_text_element)r.   r/   r0   rX   rú   rü   rþ   r   r  r  rã   r   r   rÎ   r   rø   n  s   	rø   c                       sL   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )ÚTestPreviousSiblingc                    s"   t t| ƒ ¡  | jjdd�| _d S )Nr?   r!   )rÍ   r  rX   rV   r   rå   rW   rÎ   r   r   rX   �  s    z TestPreviousSibling.setup_methodc                 C   s   | j jd ksJ ‚d S rº   )rV   Úprevious_siblingrW   r   r   r   Ú%test_previous_sibling_of_root_is_none¡  s    z9TestPreviousSibling.test_previous_sibling_of_root_is_nonec                 C   sB   | 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=   r   z3.1)rå   r	  ræ   rW   r   r   r   Útest_previous_sibling¤  s    z)TestPreviousSibling.test_previous_siblingc                 C   sN   | j jjd ksJ ‚| j jdd�}|jd ks.J ‚| j jdd�}|jd ksJJ ‚d S )Nrû   r!   r<   )rV   rè   r	  r   )r   rý   Z
first_spanr   r   r   Ú#test_previous_sibling_may_not_exist«  s
    z7TestPreviousSibling.test_previous_sibling_may_not_existc                 C   s   | j  d¡d dksJ ‚d S )Nr¡   r"   r=   )rå   Úfind_previous_siblingrW   r   r   r   Útest_find_previous_sibling´  s    z.TestPreviousSibling.test_find_previous_siblingc                 C   s4   |   | j d¡g d¢¡ |   | jjdd�dg¡ d S )Nr¡   )r=   r   r<   r<   r!   )r½   rå   Úfind_previous_siblingsrW   r   r   r   Útest_previous_siblings·  s    ÿz*TestPreviousSibling.test_previous_siblingsc                 C   sv   |   d¡}|jdd�}|jjdks&J ‚|jjdks6J ‚|  | d¡dg¡ |jdd�dks^J ‚|jdd�d ksrJ ‚d S )Nr  r  r   r   r4   r3   r  )r   r   r	  rR   rB   r  r  r  r   r   r   Ú&test_previous_sibling_for_text_element½  s    
z:TestPreviousSibling.test_previous_sibling_for_text_element)r.   r/   r0   rX   r
  r  r  r  r  r  rã   r   r   rÎ   r   r  ›  s   	r  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ej d#d$d%„ d&d%„ g¡d'd(„ ƒZd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#dAdB„ Z$dCdD„ Z%dEdF„ Z&dGdH„ Z'dIdJ„ Z(dKdL„ Z)dMdN„ Z*dOdP„ Z+dQdR„ Z,dSdT„ Z-dUdV„ Z.dWdX„ Z/dYdZ„ Z0d[d\„ Z1d]d^„ Z2d_S )`ÚTestTreeModificationc                 C   sl   |   d¡}d|jd< | ¡ |  d¡ks*J ‚|jd= | ¡ |  d¡ksHJ ‚d|jd< | ¡ |  d¡kshJ ‚d S )	Nz<a id="1"></a>r'   r"   z<a id="2"></a>rF   rD   Zid2z<a id2="foo"></a>)r   r,   ry   Ú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shJ ‚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   rñ   Úinsertrx   )r   r§   r   r,   r  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sBJ ‚| ¡ |  d¡ksXJ ‚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   rG   r·   ry   r  )r   Údocr   Zsecond_paraÚboldr   r   r   Ú!test_append_to_contents_moves_tagÝ  s    

ÿz6TestTreeModification.test_append_to_contents_moves_tagc                 C   s0   d}|   |¡}|j}| |j¡}||ks,J ‚d S )Nz<a></a><b><c></c></b>)r   r,   Úreplace_withra   ©r   r$   r   r,   Z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ks&J ‚t t¡� | ¡  W d   ƒ n1 sN0    Y  t t¡� | |j	¡ W d   ƒ n1 s„0    Y  d S )Nz<a><b>Foo</b></a><c>Bar</c>)
r   r,   Úextractr·   r¬   r­   r®   r"  r  ra   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   s:   d}|   |¡}|j}|j |¡ | ¡ |  |¡ks6J ‚d S )Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)r   ra   r  ry   r  )r   r$   r   ra   r   r   r   Útest_replace_tag_with_itself  s
    
z1TestTreeModification.test_replace_tag_with_itselfc                 C   sJ   d}|   |¡}t t¡� |j |j¡ W d   ƒ n1 s<0    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_exception  s    
zFTestTreeModification.test_replace_tag_with_its_parent_raises_exceptionc                 C   sL   d}|   |¡}t t¡�  |j d|j¡ W d   ƒ n1 s>0    Y  d S )Nr(  r   )r   r¬   r­   r®   r,   r  r)  r   r   r   Ú,test_insert_tag_into_itself_raises_exception  s    
zATestTreeModification.test_insert_tag_into_itself_raises_exceptionc           	      C   sŒ   |   d¡}d}|   |¡}| d|¡ |jD ]}t|tƒr*J ‚q*t|jƒ\}}}}d|jks^J ‚d|jkslJ ‚d|jkszJ ‚d|jksˆJ ‚dS )	z”Inserting one BeautifulSoup object into another actually inserts all
        of its children -- you'll never combine BeautifulSoup objects.
        z-<p>And now, a word:</p><p>And we're back.</p>z<p>p2</p><p>p3</p>r   zAnd now, a word:Úp2Úp3zAnd we're back.N)r   r  ZdescendantsÚ
isinstancer   ÚlistÚchildrenr   )	r   r   r$   Z	to_insertr¯   Úp1r,  r-  Zp4r   r   r   Ú1test_insert_beautifulsoup_object_inserts_children  s    


zFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrenc                 C   sX   |   d¡}|j}|jd }| dd¡ |j\}}| d¡ | d¡ d|jjksTJ ‚d S )Nz<p><a>one</a><b>three</b></p>r   r   Útworõ   Úthree)r   r,   r¦   r  ÚreplaceWithr   r   )r   r   r,   r   ÚleftÚrightr   r   r   Ú3test_replace_with_maintains_next_element_throughout.  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sJJ ‚|jj|ksZJ ‚|jd kshJ ‚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_node=  s    
z,TestTreeModification.test_replace_final_nodec                 C   s˜   |   d¡}|j dd¡ | ¡ |  d¡ks.J ‚|jdd�}|jdksHJ ‚|jj|ksXJ ‚|jdksfJ ‚|jj	|ksvJ ‚|j	d ks„J ‚|j|j
ks”J ‚d S )Nz<a><b>Argh!</b><c></c></a>r   r:  z!<a><b>Argh!Hooray!</b><c></c></a>r   r9  )r   r   r  ry   r  r   ræ   rÑ   r	  rù   ra   )r   r   r;  r   r   r   Útest_consecutive_text_nodesG  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sPJ ‚d S )NrF   r   r3   rD   )r   r,   r  r¦   rÑ   r   r   r   r   Útest_insert_string\  s
    
z'TestTreeModification.test_insert_stringc                 C   sø   |   ¡ }| jd|d�}t||dƒ}| dd¡ |j d|¡ | ¡ |  d¡ksRJ ‚|j}|j|ksfJ ‚|j	|kstJ ‚|j
dd	�}|j|ksŽJ ‚|j|ksœJ ‚|j}|j|ks°J ‚|j	|ks¾J ‚|j
dd	�}|j|ksØJ ‚|j|ksæJ ‚|j|ksôJ ‚d S )
Nz%<a><b>Find</b><c>lady!</c><d></d></a>r  Zmagictagr   Úther   z=<a><b>Find</b><magictag>the</magictag><c>lady!</c><d></d></a>ZFindr   )r¥   r   r   r  r,   ry   r  r   rù   r	  r   rÑ   ræ   ra   r·   )r   r§   r   Z	magic_tagZb_tagr   Zc_tagr?  r   r   r   Útest_insert_tage  s.    ÿ
ÿ
z$TestTreeModification.test_insert_tagc                 C   s0   d}|   |¡}|j |j¡ || ¡ ks,J ‚d S r'  )r   r,   rG   r   ry   ©r   rz   r   r   r   r   Ú*test_append_child_thats_already_at_the_endƒ  s    
z?TestTreeModification.test_append_child_thats_already_at_the_endc                 C   sJ   d}|   |¡}|j|j|j|j|j|jg}|j |¡ d| 	¡ ksFJ ‚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    ra   r   r,   Úextendry   )r   rz   r   rH   r   r   r   Útest_extend‰  s
    
z TestTreeModification.test_extendÚget_tagsc                 C   s   | S rº   r   rk   r   r   r   Ú<lambda>‘  rà   zTestTreeModification.<lambda>c                 C   s   | j S rº   )r¦   rk   r   r   r   rH  ‘  rà   c                 C   s`   d}|   |¡}|jddd�}|jddd�}||ƒ}| |¡ d| ¡ ksLJ ‚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>rn   Ú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   rE  ry   )r   rG  rz   r   rI  rJ  Útagsr   r   r   Ú&test_extend_with_another_tags_contents�  s    

z;TestTreeModification.test_extend_with_another_tags_contentsc                 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,   r  r    ry   rA  r   r   r   Ú$test_move_tag_to_beginning_of_parent�  s    
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   ZContentsz<br>Contents</br>)r   Úbrr  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s8J ‚|j |j¡ | ¡ |  d¡ks\J ‚|j}t t¡� | |¡ W d   ƒ n1 sŒ0    Y  | 	¡  t t¡� | d¡ W d   ƒ n1 sÈ0    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   Úinsert_beforer,   ry   r  r¬   r­   r®   r$  Únew_tag©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sfJ ‚d S )Nr&   rP  ú rQ  z$QUUX BAZ<a>foo</a>BAZ QUUX<b>bar</b>ZFOOz'QUUX BAZ<b>bar</b>FOO<a>foo</a>BAZ QUUX)r   r   rU  r,   ry   r  r   r   r   r   Útest_insert_multiple_beforeÇ  s    

ÿ

ÿz0TestTreeModification.test_insert_multiple_beforec                 C   sò   |   d¡}|j d¡ |j d¡ | ¡ |  d¡ks8J ‚|j |j¡ | ¡ |  d¡ks\J ‚|j}t t¡� | |¡ W d   ƒ n1 sŒ0    Y  | 	¡  t t¡� | d¡ W d   ƒ n1 sÈ0    Y  |   d¡}|j 
| d¡¡ d S )	Nr&   rP  rQ  z<a>foo</a>QUUX<b>bar</b>BAZrR  rS  rT  r,   )r   r   Úinsert_afterr,   ry   r  r¬   r­   r®   r$  rU  rV  rW  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sfJ ‚d S )Nr&   rP  rY  rQ  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,   ry   r  r   r   r   r   Útest_insert_multiple_afterî  s    

ÿ

ÿz/TestTreeModification.test_insert_multiple_afterc                 C   s¾   |   d¡}| d¡}| d¡}t t¡� | |¡ W d   ƒ n1 sH0    Y  t t¡� | |¡ W d   ƒ n1 s|0    Y  t t¡� | |¡ W d   ƒ n1 s°0    Y  d S ©Nrõ   r,   )r   rV  Ú
new_stringr¬   r­   r®   r[  ÚNotImplementedError©r   r   r^   r   r   r   r   Ú:test_insert_after_raises_exception_if_after_has_no_meaningú  s    


((zOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningc                 C   s¾   |   d¡}| d¡}| d¡}t t¡� | |¡ W d   ƒ n1 sH0    Y  t t¡� | |¡ W d   ƒ n1 s|0    Y  t t¡� | |¡ W d   ƒ n1 s°0    Y  d S r^  )r   rV  r_  r¬   r­   r®   rU  r`  ra  r   r   r   ÚFtest_insert_before_raises_notimplementederror_if_before_has_no_meaning  s    


((z[TestTreeModification.test_insert_before_raises_notimplementederror_if_before_has_no_meaningc                 C   sv   |   d¡}| d¡\}}| |¡ | ¡ |  d¡ks8J ‚|jd ksFJ ‚|j|jksVJ ‚|jdksdJ ‚|jdksrJ ‚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  ry   r  r·   ÚprÑ   rù   )r   r   rd  Úshowr   r   r   Útest_replace_with  s    ÿ

ÿ
z&TestTreeModification.test_replace_withc                 C   s¾   t dd�}t t¡� | d¡ W d   ƒ n1 s40    Y  |  d¡j}t t¡� |j |¡ W d   ƒ n1 sv0    Y  t t¡�  |j d|d¡ W d   ƒ n1 s°0    Y  d S )Nr,   r|   z
won't workr(  Zstring1Zstring2)r   r¬   r­   r®   r  r   r,   r   )r   Za_tagr   r   r   Útest_replace_with_errors  s    
(*z-TestTreeModification.test_replace_with_errorsc                 C   sœ   d}|   |¡}| d¡}d|_| d¡}| d¡}d}|j ||||¡ | ¡ dksXJ ‚|jj|kshJ ‚|jj|ksxJ ‚|jj|ksˆJ ‚|jj|ks˜J ‚d S )Nr!  r    zText In D TagrD  r„   zRandom Textz;<a><b></b><d>Text In D Tag</d><e></e>Random Text<f></f></a>)r   rV  r   ra   r  ry   r   rÑ   )r   rz   r   Zd_tagZe_tagZf_tagZa_stringr   r   r   Útest_replace_with_multiple-  s    



z/TestTreeModification.test_replace_with_multiplec                 C   s0   d}|   |¡}|j |j¡ d| ¡ ks,J ‚d S )Nr!  z<a><c></c></a>)r   r   r  ra   ry   rA  r   r   r   Útest_replace_first_child<  s    
z-TestTreeModification.test_replace_first_childc                 C   s0   d}|   |¡}|j |j¡ d| ¡ ks,J ‚d S )Nr!  r(  )r   ra   r  r   ry   rA  r   r   r   Útest_replace_last_childB  s    
z,TestTreeModification.test_replace_last_childc                 C   s  |   d¡}|j}|j}| |¡ | ¡ |  d¡ks6J ‚|jd ksDJ ‚|jdd�jd ksZJ ‚|j	d kshJ ‚|j
d ksvJ ‚|jd ks„J ‚|j|jks”J ‚|j	dks¢J ‚|jj|jks´J ‚|j
d ksÂJ ‚|jdd�}|j}|j|ksâJ ‚|j
|ksðJ ‚|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>r7  r   ZWeÚto)r   r   r„   r  ry   r  r·   r   rÑ   ræ   rù   r	  r,   rD  rC  )r   r   Z
remove_tagZmove_tagZto_textZg_tagr   r   r   Útest_nested_tag_replace_withH  s0    ÿ

ÿ
z1TestTreeModification.test_nested_tag_replace_withc                 C   s6   |   d¡}|j ¡  |jd ks"J ‚|jjdks2J ‚d S )NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r   Úemr"  re  r$   rt   r   r   r   Útest_unwrapl  s    

z TestTreeModification.test_unwrapc                 C   sF   |   d¡}|j | d¡¡}| ¡ dks,J ‚| ¡ |  d¡ksBJ ‚d S )NzI wish I was bold.r   ú<b>I wish I was bold.</b>)r   r   ÚwraprV  ry   r  )r   r   rŠ   r   r   r   Ú	test_wrapt  s    
zTestTreeModification.test_wrapc                 C   s4   |   d¡}|jj |j¡ | ¡ |  d¡ks0J ‚d S )Nz<b></b>I wish I was bold.rp  )r   r   rù   rq  ry   r  r   r   r   r   Ú%test_wrap_extracts_tag_from_elsewherez  s    
z:TestTreeModification.test_wrap_extracts_tag_from_elsewherec                 C   sH   |   d¡}|jj |j¡ dt|jjƒks.J ‚| ¡ |  d¡ksDJ ‚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ù   rq  r)   r¦   ry   r  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sNJ ‚t|jjƒdksbJ ‚|jd kspJ ‚|jd ks~J ‚|j	j	d ksŽJ ‚|jdd	�}|jd
d	�}|j	|ks´J ‚|j
|ksÂJ ‚|j|ksÐJ ‚|j|ksÞJ ‚d S )NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>r9   Z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)   rñ   r¦   r   r$  ry   r·   ræ   rÑ   rù   r	  )r   r   Z	extractedZ	content_1Z	content_2r   r   r   Útest_extract‡  s"    ÿz!TestTreeModification.test_extractc                 C   sz   |   d¡}|jj}|jj}| d¡}| d¡}|j |¡ |j |¡ | ¡  | ¡  ||jjksfJ ‚||jjksvJ ‚d S )Nr&   rD   r3   )r   r,   r   r   r_  rG   r$  )r   r   Zfoo_1Zbar_1Zfoo_2Z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s4J ‚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Ç   ¼  rà   zKTestTreeModification.test_extract_multiples_of_same_tag.<locals>.<listcomp>rw  z<body>

<a></a>
</body>)r   r*   r#   rñ   rW   r   rx  r   Ú"test_extract_multiples_of_same_tag°  s    
z7TestTreeModification.test_extract_multiples_of_same_tagc                 C   s.   |   d¡}| d¡ ¡  d | d¡ks*J ‚d S )Nz<html>
<body>hi</body>
</html>rñ   )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s`J ‚dS )zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>r   r¦   T)Ú	decomposeN)r   r,   re  Úclearr)   r¦   rK   rn  )r   r   r,   rn  r   r   r   Ú
test_clearÉ  s    

zTestTreeModification.test_clearc                 C   s~   |   d¡}| d¡\}}|j}|jj}||||fD ]}d|jks2J ‚q2| ¡  |||fD ]}d|jksXJ ‚qXd|jkszJ ‚d S )Nz;<p><a>String <em>Italicized</em></a></p><p>Another para</p>re  FT)r   r*   r,   rn  r   Z
decomposedr{  )r   r   r1  r,  r,   r$   r¯   r   r   r   Útest_decomposeØ  s    
z#TestTreeModification.test_decomposec                 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>rD   r3   N)r   r,   r   r¦   r   r   r   r   r   Útest_string_setè  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   ra   r   r   r,   rx   r   r   r   r   Ú/test_string_set_does_not_affect_original_stringð  s    
zDTestTreeModification.test_string_set_does_not_affect_original_stringc                 C   s0   |   d¡}tdƒ}||j_t|jjtƒs,J ‚d S )NrF   rD   )r   r   r,   r   r.  )r   r   Úcdatar   r   r   Ú)test_set_string_preserves_class_of_stringõ  s    
z>TestTreeModification.test_set_string_preserves_class_of_stringN)3r.   r/   r0   r  r  r  r   r#  r%  r&  r*  r+  r2  r8  r<  r=  r>  r@  rB  rF  r¬   ÚmarkÚparametrizerL  rM  rO  rX  rZ  r\  r]  rb  rc  rg  rh  ri  rj  rk  rm  ro  rr  rs  rt  ru  rv  ry  rz  r}  r~  r  r€  r‚  r   r   r   r   r  È  s`   	


	ÿ

	$	r  c                   @   s.   e Zd Zej dg d¢¡dd„ ƒZdd„ ZdS )ÚTestDeprecatedArgumentsÚmethod_name)r   r*   rÀ   r¾   rÛ   rÙ   rî   rì   rÿ   r  r  r  c                 C   sz   |   d¡}t|j|ƒ}tjdd��D}|dd� |\}|jtksBJ ‚t|jƒ}|dksXJ ‚W d   ƒ n1 sl0    Y  d S )Nz<a>some</a><b>markup</b>T©Úrecordr÷   ©r$   zOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.)	r   Úgetattrr   ÚwarningsÚcatch_warningsÚfilenameÚ__file__r#   Úmessage)r   r†  r   ÚmethodÚwÚwarningÚmsgr   r   r   Útest_find_type_method_stringþ  s    	


z4TestDeprecatedArguments.test_find_type_method_stringc                 C   sr   t jdd��R}tdd�}|jdks&J ‚|\}t|jƒ}|jtksDJ ‚|dksPJ ‚W d   ƒ n1 sd0    Y  d S )NTr‡  r$   r‰  zXThe 'text' argument to the SoupStrainer constructor is deprecated. Use 'string' instead.)r‹  rŒ  r   r$   r#   r�  r�  rŽ  )r   r‘  r‘   r’  r“  r   r   r   Ú$test_soupstrainer_constructor_string  s    

z<TestDeprecatedArguments.test_soupstrainer_constructor_stringN)r.   r/   r0   r¬   rƒ  r„  r”  r•  r   r   r   r   r…  ü  s
   ÿ

r…  ))r1   Úpdbr   r¬   r6   r‹  Zbs4r   Zbs4.builderr   r   Zbs4.elementr   r   r   r	   r
   r   r   r   r   r   r   rõ   r   r   r2   rN   rT   rr   rŸ   r©   r²   rÊ   rÌ   rä   rô   rø   r  r  r…  r   r   r   r   Ú<module>   s:   
49N 5,2(1--    8