o
    MK&h"                     @   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                   @   sP   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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   F/var/www/html/venv/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(   )N"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_tagsc                 C   s<   |  d}d|dd jksJ d |dd ksJ d S )Nr1   r*   c                 S   s
   | j dkS )Nr*   r,   tr   r   r   <lambda>G   s   
 zETestFind.test_find_with_function_can_only_find_tags.<locals>.<lambda>c                 S   s   | dkS )Nr   r   r4   r   r   r   r6   H       )r   r   r,   r   r   r   r   *test_find_with_function_can_only_find_tagsE   s   
z3TestFind.test_find_with_function_can_only_find_tagsN)__name__
__module____qualname____doc__r   r   r   r%   r'   r/   r2   r8   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_tagsM   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.*)rC   rB      »TN)r   r$   recompiler   r   r   r   test_find_all_text_nodesS   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
   rK   
   )rK   r   rL   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
   rI   rK   foor   rL   )r   rQ   r   r   r   r   r   %test_calling_a_tag_is_calling_findallj   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_recursiono   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 ResultSetrU   r&   sourceTrS   r   N)r   r$   hasattrr   r   resultr   r   r   test_find_all_resultset   s   


z#TestFindAll.test_find_all_resultsetN)
r9   r:   r;   r<   rA   rG   rR   rT   rb   rg   r   r   r   r   r=   J   s    
r=   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">rN   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)r9   r:   r;   rl   r   r   r   r   rh      s    rh   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.rQ   rq   r$   rr   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&   rv   r   Trw   tagrQ   rq   r$   rE   rF   rr   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&   rw   )rQ   rq   cr$   rr   r   r   r   !test_find_all_on_non_root_element   rz   z3TestFindAllByName.test_find_all_on_non_root_elementc                 C   s   |  | dddg d S ru   )rQ   rq   rr   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 ru   )rQ   rq   r$   r	   rr   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   rv   zSecond tag.rw   rx   rr   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   rx   rr   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   r|   rr   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r{   r   r   r   id_matches_name   rt   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.rP   )r   r   rq   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 brL   rK   )r   r   rE   rF   r$   r   )r   r   r1r2r3r4r   r   r   %test_find_with_multi_valued_attribute   s   z7TestFindAllByName.test_find_with_multi_valued_attributern   N)r9   r:   r;   r<   rs   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   rm      s    
rm   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.rP   r   rq   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>
                         name1r3   zA tag called 'name1'.r,   rj   zName match.classclass2zClass match.rP   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&   rK   class_zClass 1.r~   rL   zClass 3 and 4.rN   rj   rP   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$   rE   rF   rQ   )r   rq   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 NrH   r#   valuer   r   r   big_attribute_value3     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_value8  r   zpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_valuer   rQ   r$   rE   rF   )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&   rS   rB   zfoo barr   zbar foor   r$   )r   r   r&   a2r   r   r   :test_find_all_with_string_for_attrs_finds_multiple_classes=  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   rj   zMatch.)r   r	   rQ   r$   )r   rq   strainerr   r   r   'test_find_all_by_attribute_soupstrainerI  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.rP   r   r   r   r   $test_find_all_with_missing_attributeQ     
z;TestFindAllByAttribute.test_find_all_with_missing_attributec                 C   r   )Nr   Tr   zID present.zID is empty.rP   r   r   r   r   $test_find_all_with_defined_attributeY  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   rK   rP   )r   rq   expectedr   r   r   $test_find_all_with_numeric_attributea  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>)rK   rL   rN   r   rK   rL   rP   r   r   r   r   (test_find_all_with_list_attribute_valuesj  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_valuev  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&   rS   r   rB   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&   rS   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!   rS   )r   r   r
   rB   r   r   r   r   r   ,test_find_by_attribute_and_containing_string  r   zCTestFindAllByAttribute.test_find_by_attribute_and_containing_stringN)r9   r:   r;   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   r~   z	Comment 1z	Comment 2dspanrK   r         abcr   12r
   r!   )r   r)   rX   r   default_builderr   r   r   r#   contentssmooth)r   r   r)   builderr   r   r   r   test_smooth  s(   






zTestSmooth.test_smoothN)r9   r:   r;   r<   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   rq   r)   ielementr   r   r   
test_index  s   
	"zTestIndex.test_indexN)r9   r:   r;   r<   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.rn   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   rq   r   startrr   r   r   r   rs     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   parentrr   r   r   r   test_parent  s   z TestParentOperations.test_parentc                 C   s    | j jd }|j| j ksJ d S )Nr   )rq   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)rq   r   rr   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_parentsrr   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_parentrr   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   )rq   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   )rq   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   rj   .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   rj   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   )r9   r:   r;   r<   rs   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 )ProximityTestrn   Nc                 C   ro   )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>rp   rr   r   r   r   rs     s   
zProximityTest.setup_methodr   r9   r:   r;   rs   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 )TestNextOperationsrn   Nc                    s   t t|   | jj| _d S r   )superr  rs   rq   r   r   rr   	__class__r   r   rs     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_elementrr   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   )rq   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   )rq   r  rr   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  rH   r   )rQ   r   find_all_nextrr   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_nextrr   r   r   r   test_find_next1     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  )rq   r   r  r   rQ   r  r   r   r   r   test_find_next_for_text_element5     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   <      z;TestNextOperations.test_next_generators.<locals>.<listcomp>r   rL   r  c                 S   r  r   r   r   r   r   r   r   B  r"  r
   r   )rq   r   next_elementsself_and_next_elements)r   r   
successorsr{   r   successors2r   r   r   test_next_generators:  s   z'TestNextOperations.test_next_generatorsr   )r9   r:   r;   rs   r  r  r  r  r  r  r'  __classcell__r   r   r
  r   r    s    r  c                       r  )TestPreviousOperationsrn   Nc                    "   t t|   | jjdd| _d S r  )r	  r)  rs   rq   r   endrr   r
  r   r   rs   H  r   z#TestPreviousOperations.setup_methodc                 C   s*   | j jd dks
J | j jjdksJ d S )Nr   rL   r  )r+  previous_elementrr   r   r   r   test_previousL  s   z$TestPreviousOperations.test_previousc                 C   s   | j d}|jd u sJ d S )Nhtml)rq   r   r,  )r   r   r   r   r   #test_previous_of_first_item_is_noneP  s   z:TestPreviousOperations.test_previous_of_first_item_is_nonec                 C   r  r   )rq   r,  rr   r   r   r   test_previous_of_root_is_noneT  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  )rQ   r+  find_all_previousrr   r   r   r   test_find_all_previousX  s   z-TestPreviousOperations.test_find_all_previousc                 C   r  )Nr   r   rL   r  r   )r+  find_previousrr   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   r1  )rq   r   r4  r   rQ   r2  r   r   r   r   #test_find_previous_for_text_elementc  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   )rK   r7  r8  r   )rq   r   r   previous_elementsself_and_previous_elements)r   r   r   r   r   test_previous_generatorsh  s   z/TestPreviousOperations.test_previous_generatorsr   )r9   r:   r;   rs   r-  r/  r0  r3  r5  r6  r;  r(  r   r   r
  r   r)  G  s    r)  c                   @   r  )SiblingTestrn   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* )rE   rF   subr   rq   )r   markupr   r   r   rs   o  s   zSiblingTest.setup_methodr   r  r   r   r   r   r<  n  r  r<  c                       r  )TestNextSiblingrn   Nc                    r*  )NrK   r   )r	  r@  rs   rq   r   r   rr   r
  r   r   rs     r   zTestNextSibling.setup_methodc                 C   r  r   )rq   next_siblingrr   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   rL   1.1)r   rA  r  rr   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 )NrD  r   rN   )rq   r.  rA  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.   rr   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   rL   rN   rL   r   )r   r   r@   rr   r   r   r   test_next_siblings  s   z"TestNextSibling.test_next_siblingsc                 C   ,   |  | jjg d |  | jjg d d S )NrP  )rK   r   rL   rN   )r   r   next_siblingsself_and_next_siblingsrr   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>bazrC   r   r   bazrB   nonesuch)r   r   rA  r,   rQ   r@   r.   r   r   r   r   r   r   "test_next_sibling_for_text_element     
z2TestNextSibling.test_next_sibling_for_text_elementr   )r9   r:   r;   rs   rB  rE  rJ  rM  rQ  rU  r\  r(  r   r   r
  r   r@    s    	r@  c                       r  )TestPreviousSiblingrn   Nc                    r*  )NrN   r   )r	  r^  rs   rq   r   r+  rr   r
  r   r   rs     r   z TestPreviousSibling.setup_methodc                 C   r  r   )rq   previous_siblingrr   r   r   r   %test_previous_sibling_of_root_is_none  r   z9TestPreviousSibling.test_previous_sibling_of_root_is_nonec                 C   rC  )Nr   rL   r   z3.1)r+  r_  r,  rr   r   r   r   test_previous_sibling  rF  z)TestPreviousSibling.test_previous_siblingc                 C   rG  )NrD  r   rK   )rq   r.  r_  r   )r   rH  
first_spanr   r   r   #test_previous_sibling_may_not_exist  rK  z7TestPreviousSibling.test_previous_sibling_may_not_existc                 C   rL  )Nr   r   rL   )r+  r-   rr   r   r   r   test_find_previous_sibling  rN  z.TestPreviousSibling.test_find_previous_siblingc                 C   rO  )Nr   rL   r   rK   rK   r   )r   r+  r?   rr   r   r   r   test_previous_siblings  s   z*TestPreviousSibling.test_previous_siblingsc                 C   rR  )Nre  )rN   rL   r   rK   )r   r+  previous_siblingsself_and_previous_siblingsrr   r   r   r   !test_previous_siblings_generators  rV  z5TestPreviousSibling.test_previous_siblings_generatorsc                 C   rW  )NrX  rY  r   r   rC   rB   rZ  )r   r   r_  r,   rQ   r?   r-   r[  r   r   r   &test_previous_sibling_for_text_element  r]  z:TestPreviousSibling.test_previous_sibling_for_text_elementr   )r9   r:   r;   rs   r`  ra  rc  rd  rf  ri  rj  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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>rU   rS   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   r>   insertr   )r   r   r   r&   rp  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   rX   r   r   rm  )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   rO   rL   rN   67893456789)
r   r   rX   new_tagr,   rs  insert_beforeinsert_afterextendget_text)	r   r   r.  ry  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_withr~   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  r~   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   r~   r  r   rm  )r   r   r   r~   rf   r   r   r   test_replace_tag_with_itself5  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_exception=  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&   rs  r  r   r   r   ,test_insert_tag_into_itself_raises_exceptionC  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   rs  r  r   listchildren)r   r   r  r  p1p4r   r   r   test_insert_multiple_elementsI  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 )	zInserting 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   rs  r   descendants
isinstancer   r  r  )	r   r   r   	to_insertr  r  r   r  r  r   r   r   1test_insert_beautifulsoup_object_inserts_childrenU  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
   twor=  three)r   r&   rs  r   r  r   r   )r   r   r&   leftrightr   r   r   3test_replace_with_maintains_next_element_throughoutj  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_nodex  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   rs  r   rm  r   r,  r  r_  rA  r~   )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 )NrU   r   rB   rS   )r   r&   rs  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   rX   r   re   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>ro  magictagr   ther
   z=<a><b>Find</b><magictag>the</magictag><c>lady!</c><d></d></a>Findr   )r   r   r   rs  r&   r   rm  r   rA  r_  r   r  r,  r~   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&   rs  r~   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&   rX   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   r~   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 )NrU   r   r~   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   r6         zTestTreeModification.<lambda>c                 C   s   | j S r   )r   r   r   r   r   r6     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   r6     r7   z<a></a><b>1</b>c                 C   s   dS )Nabcder   r  r   r   r   r6     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>TrV   zIA single non-Tag item was passed into Tag.extend. Use Tag.append instead.)r   rY   rZ   r   r  r)   decode_contentsr[   r\   r   r]   )	r   string_sourcerf   r   r   r_   r   r`   ra   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&   rs  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   brrs  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   r  r&   r   rm  r   r   r   r  r  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   r  r&   r   rm  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   rm  r   r   r   r  r  r  r  r   r   r   test_insert_after1  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   rm  r   r   r   r   test_insert_multiple_afterI  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 Nr=  r&   )r   r  
new_stringr   r   r   r  NotImplementedErrorr   r   r{   r   r   r   r   :test_insert_after_raises_exception_if_after_has_no_meaningU     


"zOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningc                 C   r  r  )r   r  r  r   r   r   r  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   rm  r   r*   r  rA  )r   r   r  showr   r   r   test_replace_withk  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&   r3   z
won't workr  string1string2)r   r   r   r   r  r   r&   r   )r   a_tagr   r   r   test_replace_with_errorsx  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   r  r   r~   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  r~   r   r  r   r   r   test_replace_first_child  r  z-TestTreeModification.test_replace_first_childc                 C   r  )Nr  r  )r   r~   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sJ 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   rm  r   r   r  r,  rA  r_  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   wrapr  r   rm  )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   rA  r   r   rm  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   rA  r   r#   r   r   rm  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>rH   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  r   r   r,  r  rA  r_  )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    rS   rB   )r   r&   r   r  rX   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   r>   rr   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>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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   rd   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>)rS  zH<div><em>child1</em><p id="start"><a>Second <em>child</em></a></p></div>)r#  r  )r  r  )r9  r=  )rg  zF<div><p id="start"><a>Second <em>child</em></a></p><p>child3</p></div>)r   r=  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_iteration0  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_decomposeU  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_stringe  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>rS   rB   N)r   r&   r   r   r   r   r   r   r   test_string_setn  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   r~   r   r   r&   r   r   r   r   r   /test_string_set_does_not_affect_original_stringv  s   
zDTestTreeModification.test_string_set_does_not_affect_original_stringc                 C   s0   |  d}td}||j_t|jjtsJ d S )NrU   rS   )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);r9   r:   r;   rn  rt  rx  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   rk    s    	

	




	%
	rk  )r   r$   r   r   r  r  r4  r2  r.   r@   r-   r?   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>TrV   r?  )r   zOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.)	r   r  r   rY   rZ   r[   r\   r   r]   r   r  r   methodr_   r`   ra   r   r   r   test_find_type_method_string  s   



"z4TestDeprecatedArguments.test_find_type_method_stringN)r9   r:   r;   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$  TrV   u)_classzN'_class' is an unusual attribute name and is a common misspelling for 'class_')r   r  r   rY   rZ   r[   r\   r  r]   r   r   r%  r   r   r   test_suspicious_syntax_warning  s   



"z+TestWarnings.test_suspicious_syntax_warningN)r9   r:   r;   r   r   r!  r(  r-  r   r   r   r   r*    r)  r*  )$r<   r   rE   rY   bs4r   bs4.builderr   bs4.elementr   r   r   r   r   
bs4.filterr	   r=  r   r   r=   rh   rm   r   r   r   r   r  r  r)  r<  r@  r^  rk  r(  r#  r*  r   r   r   r   <module>   sB   
,FP /,?,'/1     %