3
d                 @   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 )TestFindzBasic 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"   | j d}|jdjdkstd S )Nz <a>1</a><b>2</b><a>3</a><b>4</b>b2)soupfindstringAssertionError)selfr    r   =/tmp/pip-build-8z3xcdsh/beautifulsoup4/bs4/tests/test_tree.pytest_find_tag-   s    
zTestFind.test_find_tagc             C   s"   | j d}|jdddkstd S )Nu   <h1>Räksmörgås</h1>u   Räksmörgås)r   )r   r   r   )r   r   r   r   r   test_unicode_text_find1   s    
zTestFind.test_unicode_text_findc             C   s,   | j d}t| d|jddjks(td S )Nu&   <h1 id="Räksmörgås">here it is</h1>z
here it isu   Räksmörgås)id)r   strr   textr   )r   r   r   r   r   test_unicode_attribute_find5   s    
z$TestFind.test_unicode_attribute_findc             C   s"   | j d}dt|j kstdS )z)Test an optimization that finds all tags.z<a>foo</a><b>bar</b>   N)r   lenfind_allr   )r   r   r   r   r   test_find_everything;   s    
zTestFind.test_find_everythingc             C   s$   | j d}dt|jdks t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#   aN)r   r$   r%   r   )r   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   sz   | j d}|jdddgks t|jddgdddgks<t|jtjdddddgks\t|jdddddgksvtdS )	z'You can search the tree for text nodes.u   <html>Foo<b>bar</b>»</html>bar)r   Fooz.*   »TN)r   r%   r   recompile)r   r   r   r   r   test_find_all_text_nodesH   s
    
 z$TestFindAll.test_find_all_text_nodesc             C   s   | j d}| j|jddddddg | j|jddddg | j|jdd	ddddd
dg | j|jddddddd
dg 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   
   45r   N)r   assert_selectsr%   )r   r   r   r   r   test_find_all_limitV   s    
zTestFindAll.test_find_all_limitc             C   s:   | j d}| j|ddddg | j|jdddg d S )	Nz!<a>1</a><b>2<a id='foo'>3</a></b>r'   r   )r5   r6   foo)r   r7   )r   r;   r   )r   r   r   r   r   %test_calling_a_tag_is_calling_findallb   s    
z1TestFindAll.test_calling_a_tag_is_calling_findallc             C   s.   | j d}g }|j| g |j|ks*td S )Nz<a></a>)r   appendr%   r   )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   | j d}|jd}t|ds"t|jd}t|ds:t|jdd}t|dsTtdS )z%All find_all calls return a ResultSetz<a></a>r'   sourceTr=   )r   N)r   r%   hasattrr   )r   r   resultr   r   r   test_find_all_resultsetq   s    


z#TestFindAll.test_find_all_resultsetN)	r)   r*   r+   r,   r3   r<   r>   rA   rE   r   r   r   r   r-   E   s   
r-   c               @   s   e Zd Zdd ZdS )TestFindAllBasicNamespacesc             C   s<   | j d}d|jdjkstd|jddidjks8td S )Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">r9   zmathml:msqrtr'   zsvg:fillZred)attrs)r   r   r   r   name)r   r   r   r   r   test_find_by_namespaced_name   s    
z7TestFindAllBasicNamespaces.test_find_by_namespaced_nameN)r)   r*   r+   rI   r   r   r   r   rF   ~   s   rF   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   | j 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 | jjdddg d S )Nr'   z
First tag.zNested tag.)r;   rK   r%   )r   r   r   r   test_find_all_by_tag_name   s    z+TestFindAllByName.test_find_all_by_tag_namec             C   s\   | j | jjddddg | j | jjdddddg | j | jjdtjddddg d S )Nr'   z
First tag.)r   TzNested tag.tag)r;   rK   r%   r1   r2   )r   r   r   r   test_find_all_by_name_and_text   s    z0TestFindAllByName.test_find_all_by_name_and_textc             C   s   | j | jjjddg d S )Nr'   zNested tag.)r;   rK   cr%   )r   r   r   r   !test_find_all_on_non_root_element   s    z3TestFindAllByName.test_find_all_on_non_root_elementc             C   s   | j | jdddg d S )Nr'   z
First tag.zNested tag.)r;   rK   )r   r   r   r   %test_calling_element_invokes_find_all   s    z7TestFindAllByName.test_calling_element_invokes_find_allc             C   s    | j | jjtdddg d S )Nr'   z
First tag.zNested tag.)r;   rK   r%   r   )r   r   r   r   test_find_all_by_tag_strainer   s    z/TestFindAllByName.test_find_all_by_tag_strainerc             C   s"   | j | jjddgdddg d S )Nr'   r   z
First tag.zSecond tag.zNested tag.)r;   rK   r%   )r   r   r   r   test_find_all_by_tag_names   s    z,TestFindAllByName.test_find_all_by_tag_namesc             C   s$   | j | jjddddddg d S )NT)r'   r   z
First tag.zSecond tag.zNested tag.)r;   rK   r%   )r   r   r   r   test_find_all_by_tag_dict   s    z+TestFindAllByName.test_find_all_by_tag_dictc             C   s$   | j | jjtjddddg d S )Nz^[ab]$z
First tag.zSecond tag.zNested tag.)r;   rK   r%   r1   r2   )r   r   r   r   test_find_all_by_tag_re   s    z)TestFindAllByName.test_find_all_by_tag_rec             C   s,   dd }| j d}| j|j|ddg d S )Nc             S   s   | j | jdkS )Nr   )rH   get)rN   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.)r   r;   r%   )r   rX   rK   r   r   r   'test_find_all_with_tags_matching_method   s
    z9TestFindAllByName.test_find_all_with_tags_matching_methodc             C   sx   | j d}|jdd}|jdtjd}|jdddg\}}d|jksJtd|jksXtd|jksftd|jkstt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 br7   r6   )r   r   r1   r2   r%   r   r   )r   r   Zr1Zr2Zr3Zr4r   r   r   %test_find_with_multi_valued_attribute   s    z7TestFindAllByName.test_find_with_multi_valued_attributeN)r)   r*   r+   r,   rL   rM   rO   rQ   rR   rS   rT   rU   rV   rY   r[   r   r   r   r   rJ      s   rJ   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&   | j d}| j|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>first)r   zMatching a.zMatching b.)r   r;   r%   )r   rK   r   r   r   test_find_all_by_attribute_name   s    z6TestFindAllByAttribute.test_find_all_by_attribute_namec             C   st   dj d}dj d}| j|}|jg|j|dks6t|jg|j|jddksTt|jgspt|j|dgdd S )Nu   םולשutf8u   <a title="םולש"></a>)titlezsomething else)encoder   r'   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   | j d}| j|jdddg | j|jddiddg | j|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)rH   zA tag called 'name1'.rH   )rG   zName match.classZclass2zClass match.)r   r;   r%   )r   rK   r   r   r   test_find_all_by_attribute_dict   s    z6TestFindAllByAttribute.test_find_all_by_attribute_dictc             C   s   | j d}| j|jddddg | j|jddddg | j|jdd	ddg | j|jdddg | j|jdd
ddg | j|jdddg | j|j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'   r6   )class_zClass 1.rP   r7   zClass 3 and 4.r9   )rG   )r   r;   r%   )r   rK   r   r   r   test_find_all_by_class   s    z-TestFindAllByAttribute.test_find_all_by_classc             C   st   | j d}|jdtjdd}| j|dg |jdtjdd}| j|dg |jdtjdd}| j|dg d S )Nz#<gar class='foo bar'>Found it</gar>Zgaro)rg   zFound itr'   zo b)r   r%   r1   r2   r;   )r   rK   fr   r   r   0test_find_by_class_when_multiple_classes_present  s    
zGTestFindAllByAttribute.test_find_by_class_when_multiple_classes_presentc             C   sd   | j d}| j|jdtjddg dd }| j|jd|g  dd }| j|jd|dg d S )	Nz<a class='bar'>Found it</a>r'   bazFound itc             S   s   t | dkS )Nr4   )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 )Nr4   )r$   )rm   r   r   r   small_attribute_value*  s    zpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_value)r   r;   r%   r1   r2   )r   r   rn   ro   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   | j d}|jd\}}||gs0t|jdd|gsFt|jdd|g|jdddks^t|g|jddksttg |jddkstd S )Nz*<a class="foo bar"></a><a class="foo"></a>r'   r=   r.   zfoo bar)rg   zbar foo)r   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   | j d}tddid}| j|j|dg d S )Nzi
                         <a id="first">Match.</a>
                         <a id="second">Non-match.</a>r   r]   )rG   zMatch.)r   r   r;   r%   )r   rK   strainerr   r   r   'test_find_all_by_attribute_soupstrainer<  s    z>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainerc             C   s&   | j d}| j|jdd ddg d S )Nz<a id="1">ID present.</a>
                            <a>No ID present.</a>
                            <a id="">ID is empty.</a>r'   )r   zNo ID present.)r   r;   r%   )r   rK   r   r   r   $test_find_all_with_missing_attributeD  s    z;TestFindAllByAttribute.test_find_all_with_missing_attributec             C   s&   | j d}| j|jddddg d S )Nz<a id="1">ID present.</a>
                            <a>No ID present.</a>
                            <a id="">ID is empty.</a>T)r   zID present.zID is empty.)r   r;   r%   )r   rK   r   r   r   $test_find_all_with_defined_attributeL  s    z;TestFindAllByAttribute.test_find_all_with_defined_attributec             C   s>   | j d}ddg}| j|jdd| | j|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   r6   )r   r;   r%   )r   rK   expectedr   r   r   $test_find_all_with_numeric_attributeU  s
    z;TestFindAllByAttribute.test_find_all_with_numeric_attributec             C   s,   | j d}| j|jdddg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>r6   r7   r9   )r   )r   r;   r%   )r   rK   r   r   r   (test_find_all_with_list_attribute_values^  s    z?TestFindAllByAttribute.test_find_all_with_list_attribute_valuesc             C   s,   | j d}| j|jtj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%   r1   r2   )r   rK   r   r   r   5test_find_all_with_regular_expression_attribute_valueh  s    zLTestFindAllByAttribute.test_find_all_with_regular_expression_attribute_valuec             C   sB   | j d}|j}|g|jdddks(tg |jdddks>td S )Nz<b>foo</b><b>bar</b><a>foo</a>r'   r=   )r   r.   )r   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*   | j d}|jd|jdddks&td S )Nz"<a>foo</a><a><b><c>foo</c></b></a>r'   r=   )r   )r   r%   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   | j d}|j}|g|jdddks(tg |jdddks>td S )Nz"<b id="1">foo</b><a id="2">foo</a>r#   r=   )r   r   r   r.   )r   r'   r%   r   )r   r   r'   r   r   r   ,test_find_by_attribute_and_containing_string  s    
zCTestFindAllByAttribute.test_find_by_attribute_and_containing_stringN)r)   r*   r+   r^   rd   rf   rh   rk   rp   rq   rs   rt   ru   rw   rx   ry   rz   r{   r|   r   r   r   r   r\      s    		
r\   c               @   s   e Zd ZdZdd ZdS )
TestSmoothzTest Tag.smooth.c             C   s  | j d}|j}|jd |jd |jtd |jtd |jd | j }t||d}|jd |jd	 |j| d |jjkstd
t	|j
kst|j  dt	|j
kstd|j
d kstd|jjkstd|j
d kstd|j
d kstd S )Nz<div>a</div>r   rP   z	Comment 1z	Comment 2dspanr6   r         abcr   Z12r   r#   )r   rZ   r?   r   default_builderr   r   r   r   r$   contentsZsmooth)r   r   rZ   builderr   r   r   r   test_smooth  s(    






zTestSmooth.test_smoothN)r)   r*   r+   r,   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   s^   | j d}|j}x(t|jD ]\}}||j|kstqW tjt |jd W d Q R X 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   rZ   	enumerater   indexr   pytestraises
ValueError)r   rK   rZ   ielementr   r   r   
test_index  s    zTestIndex.test_indexN)r)   r*   r+   r,   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   | j 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   rK   r   start)r   r   r   r   rL     s    z!TestParentOperations.setup_methodc             C   sF   | j jd dkst| j jjd dks*t| j jjjd dksBtd S )Nr   bottommiddletop)r   parentr   )r   r   r   r   test_parent  s    z TestParentOperations.test_parentc             C   s    | j jd }|j| j kstd S )Nr   )rK   r   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td S )N)rK   r   r   )r   r   r   r   test_soup_object_has_no_parent  s    z3TestParentOperations.test_soup_object_has_no_parentc             C   s8   | j | jjddddg | j | jjddddg d S )Nulr   r   r   )r   )assert_selects_idsr   find_parents)r   r   r   r   test_find_parents  s    z&TestParentOperations.test_find_parentsc             C   s8   | j jdd dkst| j jdddd dks4td S )Nr   r   r   r   )r   )r   find_parentr   )r   r   r   r   test_find_parent  s    z%TestParentOperations.test_find_parentc             C   s"   | j jdd}|jjdkstd S )Nz
Start here)r   r   )rK   r   r   rH   r   )r   r!   r   r   r   test_parent_of_text_element  s    z0TestParentOperations.test_parent_of_text_elementc             C   s(   | j jdd}|jdd dks$td S )Nz
Start here)r   r   r   r   )rK   r   r   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&tdddkgd S )Nc             S   s&   g | ]}|d k	rd|j kr|d qS )Nr   )rG   ).0r   r   r   r   
<listcomp>  s    z>TestParentOperations.test_parent_generator.<locals>.<listcomp>r   r   r   )r   parentsr   )r   r   r   r   r   test_parent_generator  s    z*TestParentOperations.test_parent_generatorN)r)   r*   r+   r,   rL   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   | j 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>)r   rK   )r   r   r   r   rL     s    zProximityTest.setup_methodN)r)   r*   r+   rL   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j| _d S )N)superr   rL   rK   r   r   )r   )	__class__r   r   rL     s    zTestNextOperations.setup_methodc             C   s*   | j jdkst| j jjd dks&td S )NOner   r   )r   next_elementr   )r   r   r   r   	test_next  s    zTestNextOperations.test_nextc             C   s    | j jdd}|jd kstd S )NThree)r   )rK   r   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td S )N)rK   r   r   )r   r   r   r   test_next_of_root_is_none  s    z,TestNextOperations.test_next_of_root_is_nonec             C   sB   | j | jjdddg | jjdd | j | jjdddg d S )Nr   Twor   r4   )r   )r;   r   find_all_next)r   r   r   r   test_find_all_next  s    z%TestNextOperations.test_find_all_nextc             C   s2   | j jdd dkst| j jdddks.td S )Nr   r   r   r   )r   )r   	find_nextr   )r   r   r   r   test_find_next  s    z!TestNextOperations.test_find_nextc             C   s<   | j jdd}|jdjdks"t| j|jdddg d S )Nr   )r   r   r   r   )rK   r   r   r   r   r;   r   )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s6t|dksBtd S )Nr   )r   c             S   s   g | ]}|qS r   r   )r   noder   r   r   r   "  s    z:TestNextOperations.test_next_generator.<locals>.<listcomp>r   r7   r   )rK   r   Znext_elementsr   )r   r   
successorsrN   r   r   r   r   test_next_generator   s
    z&TestNextOperations.test_next_generator)r)   r*   r+   rL   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jdd| _d S )Nr   )r   )r   r   rL   rK   r   end)r   )r   r   r   rL   *  s    z#TestPreviousOperations.setup_methodc             C   s*   | j jd dkst| j jjdks&td S )Nr   r7   r   )r   previous_elementr   )r   r   r   r   test_previous.  s    z$TestPreviousOperations.test_previousc             C   s   | j jd}|jd kstd S )Nhtml)rK   r   r   r   )r   r]   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td S )N)rK   r   r   )r   r   r   r   test_previous_of_root_is_none6  s    z4TestPreviousOperations.test_previous_of_root_is_nonec             C   s6   | j | jjddddg | j | jjdddg d S )Nr   r   r   r   r   )r   )r;   r   find_all_previous)r   r   r   r   test_find_all_previous:  s    z-TestPreviousOperations.test_find_all_previousc             C   s2   | j jdd dkst| j jdddks.td S )Nr   r   r7   r   )r   )r   find_previousr   )r   r   r   r   test_find_previousB  s    z)TestPreviousOperations.test_find_previousc             C   s>   | j jdd}|jdjdks"t| j|jddddg d S )Nr   )r   r   r   r   )rK   r   r   r   r   r;   r   )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:t|jdksHt|jdksVt|jd	ksdtd S )
Nr   )r   c             S   s   g | ]}|qS r   r   )r   r   r   r   r   r   N  s    zBTestPreviousOperations.test_previous_generator.<locals>.<listcomp>r   r6   bodyheadr   )rK   r   Zprevious_elementsr   rH   )r   r   Zpredecessorsr   r   r   r   r   r   r   test_previous_generatorL  s    z.TestPreviousOperations.test_previous_generator)r)   r*   r+   rL   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 jdjd|}| j|| _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* )r1   r2   subr   rK   )r   markupr   r   r   rL   [  s    zSiblingTest.setup_methodN)r)   r*   r+   rL   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jdd| _d S )Nr6   )r   )r   r   rL   rK   r   r   )r   )r   r   r   rL   p  s    zTestNextSibling.setup_methodc             C   s   | j jd kstd S )N)rK   next_siblingr   )r   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t| j jjd dks*t| j jd dks>td S )Nr   r   r7   z1.1)r   r   r   r   )r   r   r   r   test_next_siblingw  s    z!TestNextSibling.test_next_siblingc             C   sN   | j jjd kst| j jdd}|jd ks.t| j jdd}|jd ksJtd S )Nz1.1)r   r9   )rK   r   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 jdd dkstd S )Nr   r   r   )r   find_next_siblingr   )r   r   r   r   test_find_next_sibling  s    z&TestNextSibling.test_find_next_siblingc             C   s6   | j | jjddddg | j | jjdddg d S )Nr   r   r7   r9   )r   )r   r   find_next_siblings)r   r   r   r   test_next_siblings  s    z"TestNextSibling.test_next_siblingsc             C   sv   | j d}|jdd}|jjdks&t|jjdks6t| j|jddg |jdddks^t|jddd ksrtd S )NzFoo<b>bar</b>bazr/   )r   r   bazr.   nonesuch)r   r   r   rH   r   r;   r   r   )r   r   r   r   r   r   "test_next_sibling_for_text_element  s    
z2TestNextSibling.test_next_sibling_for_text_element)r)   r*   r+   rL   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jdd| _d S )Nr9   )r   )r   r   rL   rK   r   r   )r   )r   r   r   rL     s    z TestPreviousSibling.setup_methodc             C   s   | j jd kstd S )N)rK   previous_siblingr   )r   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t| j jjd dks*t| j jd dks>td S )Nr   r7   r   z3.1)r   r   r   r   )r   r   r   r   test_previous_sibling  s    z)TestPreviousSibling.test_previous_siblingc             C   sN   | j jjd kst| j jdd}|jd ks.t| j jdd}|jd ksJtd S )Nz1.1)r   r6   )rK   r   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 jdd dkstd S )Nr   r   r7   )r   find_previous_siblingr   )r   r   r   r   test_find_previous_sibling  s    z.TestPreviousSibling.test_find_previous_siblingc             C   s6   | j | jjddddg | j | jjdddg d S )Nr   r7   r   r6   )r   )r   r   find_previous_siblings)r   r   r   r   test_previous_siblings  s    z*TestPreviousSibling.test_previous_siblingsc             C   sv   | j d}|jdd}|jjdks&t|jjdks6t| j|jddg |jdddks^t|jddd ksrtd S )NzFoo<b>bar</b>bazr   )r   r   r/   r.   r   )r   r   r   rH   r   r;   r   r   )r   r   r   r   r   r   &test_previous_sibling_for_text_element  s    
z:TestPreviousSibling.test_previous_sibling_for_text_element)r)   r*   r+   rL   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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   | j d}d|jd< |j | jdks*t|jd= |j | jdksHtd|jd< |j | jdkshtd S )	Nz<a id="1"></a>r#   r   z<a id="2"></a>z<a></a>r=   Zid2z<a id2="foo"></a>)r   r'   rb   document_forr   )r   r   r   r   r   test_attribute_modification  s    


z0TestTreeModification.test_attribute_modificationc             C   sl   t jd }| jd|d}t||d}t||d}d|d< |jjd| |jjd	| |jj d
ksht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   insertra   r   )r   r   r   r'   r   r   r   r   test_new_tag_creation  s    z*TestTreeModification.test_new_tag_creationc             C   s\   d}| j |}|jdd}|j}|jddj|j |j|ksBt|j | jdksXt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   r?   r   r   rb   r   )r   docr   Zsecond_paraZboldr   r   r   !test_append_to_contents_moves_tag  s    

z6TestTreeModification.test_append_to_contents_moves_tagc             C   s0   d}| j |}|j}|j|j}||ks,td S )Nz<a></a><b><c></c></b>)r   r'   replace_withrP   r   )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 |}|j}|j }||ks(td S )Nz<a><b></b><c></c></a>)r   r'   unwrapr   )r   r!   r   r'   r   r   r   r   +test_unwrap_returns_thing_that_was_replaced  s
    
z@TestTreeModification.test_unwrap_returns_thing_that_was_replacedc             C   sj   | j d}|j}|j  d |jks&ttjt |j  W d Q R X tjt |j	|j
 W d Q R X d S )Nz<a><b>Foo</b></a><c>Bar</c>)r   r'   extractr   r   r   r   r   r   r   rP   )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   s:   d}| j |}|j}|jj| |j | j|ks6td S )Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)r   rP   r   rb   r   r   )r   r!   r   rP   r   r   r   test_replace_tag_with_itself  s
    
z1TestTreeModification.test_replace_tag_with_itselfc          	   C   s6   d}| j |}tjt |jj|j W d Q R X d S )Nz<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   s8   d}| j |}tjt |jjd|j W d Q R X d S )Nz<a><b></b></a>r   )r   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   | j d}d}| j |}|jd| x|jD ]}t|t s,tq,W t|j\}}}}d|jksdtd|jksrtd|jkstd|jkstdS )	zInserting 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   r   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   | j d}|j}|jd }|jdd |j\}}|jd |jd d|jjksTtd S )Nz<p><a>one</a><b>three</b></p>r   r   Ztwor   Zthree)r   r'   r   r   replaceWithr   r   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   | j d}|jddjd |jdd}|j}|j|ks<t|j|ksJt|jj|ksZt|jd kshtd S )Nz<b>Argh!</b>zArgh!)r   zHooray!)r   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   | j d}|jjdd |j | jdks.t|jdd}|jdksHt|jj|ksXt|j	dksft|j	j
|ksvt|j
d kst|j|jkstd S )Nz<a><b>Argh!</b><c></c></a>r   zHooray!z!<a><b>Argh!Hooray!</b><c></c></a>)r   zArgh!)r   r   r   rb   r   r   r   r   r   r   r   rP   )r   r   r  r   r   r   test_consecutive_text_nodesG  s    

z0TestTreeModification.test_consecutive_text_nodesc             C   sT   | j d}|jjdd |jjdd ddg|jjks:t|jjd jdksPtd S )Nz<a></a>r   r.   r=   )r   r'   r   r   r   r   )r   r   r   r   r   test_insert_string\  s
    
z'TestTreeModification.test_insert_stringc             C   s   | j  }| jd|d}t||d}|jdd |jjd| |j | jdksRt|j}|j	|ksft|j
|kstt|jdd	}|j|kst|j|kst|j}|j	|kst|j
|kst|jdd	}|j|kst|j|kst|j|kst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Find)r   )r   r   r   r   r'   rb   r   r   r   r   r   r   r   r   rP   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j|j ||j ks,td S )Nz<a><b></b></a>)r   r'   r?   r   rb   r   )r   rc   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|jg}|jj| d|j	 ksFt
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   grj   er~   rP   r   r'   extendrb   r   )r   rc   r   r@   r   r   r   test_extend  s
    
z TestTreeModification.test_extendget_tagsc             C   s   | S )Nr   )rN   r   r   r   <lambda>  s    zTestTreeModification.<lambda>c             C   s   | j S )N)r   )rN   r   r   r   r    s    c             C   s`   d}| j |}|jddd}|jddd}||}|j| d|j ksLtd|j ks\t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>rZ   d1)r   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  rb   r   )r   r  rc   r   r  r  tagsr   r   r   &test_extend_with_another_tags_contents  s    

z;TestTreeModification.test_extend_with_another_tags_contentsc             C   s2   d}| j |}|jjd|j d|j ks.t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~   rb   r   )r   rc   r   r   r   r   $test_move_tag_to_beginning_of_parent  s    
z9TestTreeModification.test_move_tag_to_beginning_of_parentc             C   s.   | j d}|jjdd t|jdks*td S )Nz<br/>r   ZContentsz<br>Contents</br>)r   brr   r    r   )r   r   r   r   r   &test_insert_works_on_empty_element_tag  s    
z;TestTreeModification.test_insert_works_on_empty_element_tagc             C   s   | j d}|jjd |jjd |j | jdks8t|jj|j |j | jdks\t|j}tjt	 |j| W d Q R X |j
  tjt	 |jd W d Q R X | j d}|jj|jd d S )	Nz<a>foo</a><b>bar</b>BAZQUUXzQUUX<a>foo</a>BAZ<b>bar</b>zQUUX<b>bar</b><a>foo</a>BAZnopez<a>r'   )r   r   insert_beforer'   rb   r   r   r   r   r   r   new_tag)r   r   r   r   r   r   test_insert_before  s    


z'TestTreeModification.test_insert_beforec             C   sj   | j d}|jjddd |jjddd |j | jdks@t|jj|jd |j | jdksftd S )Nz<a>foo</a><b>bar</b>r   r  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   r  r'   rb   r   r   )r   r   r   r   r   test_insert_multiple_before  s    


z0TestTreeModification.test_insert_multiple_beforec             C   s   | j d}|jjd |jjd |j | jdks8t|jj|j |j | jdks\t|j}tjt	 |j| W d Q R X |j
  tjt	 |jd W d Q R X | j d}|jj|jd d S )	Nz<a>foo</a><b>bar</b>r  r  z<a>foo</a>QUUX<b>bar</b>BAZzQUUX<b>bar</b><a>foo</a>BAZr  z<a>r'   )r   r   insert_afterr'   rb   r   r   r   r   r   r   r  r  )r   r   r   r   r   r   test_insert_after  s    


z&TestTreeModification.test_insert_afterc             C   sj   | j d}|jjddd |jjddd |j | jdks@t|jj|jd |j | jdksftd S )Nz<a>foo</a><b>bar</b>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'   rb   r   r   )r   r   r   r   r   test_insert_multiple_after  s    


z/TestTreeModification.test_insert_multiple_afterc             C   s   | j d}|jd}|jd}tjt |j| W d Q R X tjt |j| W d Q R X tjt |j| W d Q R X d S )Nr   r'   )r   r  
new_stringr   r   r   r  NotImplementedError)r   r   rN   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   | j d}|jd}|jd}tjt |j| W d Q R X tjt |j| W d Q R X tjt |j| W d Q R X d S )Nr   r'   )r   r  r"  r   r   r   r  r#  )r   r   rN   r   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   | j d}|jd\}}|j| |j | jdks8t|jd ksFt|j|jksVt|jdksdt|j	dksrt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   rb   r   r   r   pr   r   )r   r   r&  showr   r   r   test_replace_with  s    

z&TestTreeModification.test_replace_withc             C   s   t dd}tjt |jd W d Q R X | jdj}tjt |jj| W d Q R X tjt |jjd|d W d Q R X d S )Nr'   )rH   z
won't workz<a><b></b></a>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}| j |}|jd}d|_|jd}|jd}d}|jj|||| |j dksXt|jj|ksht|jj|ksxt|jj|kst|jj|kstd S )Nz<a><b></b><c></c></a>r~   zText In D Tagr  rj   zRandom Textz;<a><b></b><d>Text In D Tag</d><e></e>Random Text<f></f></a>)	r   r  r   rP   r   rb   r   r   r   )r   rc   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j|j d|j ks,td S )Nz<a><b></b><c></c></a>z<a><c></c></a>)r   r   r   rP   rb   r   )r   rc   r   r   r   r   test_replace_first_child<  s    
z-TestTreeModification.test_replace_first_childc             C   s0   d}| j |}|jj|j d|j ks,td S )Nz<a><b></b><c></c></a>z<a><b></b></a>)r   rP   r   r   rb   r   )r   rc   r   r   r   r   test_replace_last_childB  s    
z,TestTreeModification.test_replace_last_childc             C   s  | j d}|j}|j}|j| |j | jdks6t|jd ksDt|jddj	d ksZt|j
d ksht|jd ksvt|jd kst|j|jkst|j
dkst|j	j	|jkst|jd kst|jdd}|j}|j	|kst|j|kst|j
|kst|j|kst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   ZWeZto)r   r   rj   r   rb   r   r   r   r   r   r   r   r   r'   r  r
  )r   r   Z
remove_tagZmove_tagZto_textZg_tagr   r   r   test_nested_tag_replace_withH  s,    

z1TestTreeModification.test_nested_tag_replace_withc             C   s6   | j d}|jj  |jd ks"t|jjdks2td S )NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r   emr   r   r'  r!   )r   rK   r   r   r   test_unwrapl  s
    
z TestTreeModification.test_unwrapc             C   sF   | j d}|jj|jd}|j dks,t|j | jdksBtd S )NzI wish I was bold.r   z<b>I wish I was bold.</b>)r   r   wrapr  rb   r   r   )r   r   rm   r   r   r   	test_wrapt  s    
zTestTreeModification.test_wrapc             C   s4   | j d}|jjj|j |j | jdks0td S )Nz<b></b>I wish I was bold.z<b>I wish I was bold.</b>)r   r   r   r1  rb   r   r   )r   r   r   r   r   %test_wrap_extracts_tag_from_elsewherez  s    
z:TestTreeModification.test_wrap_extracts_tag_from_elsewherec             C   sH   | j d}|jjj|j dt|jjks.t|j | jdksDt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   r1  r$   r   r   rb   r   )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   | j d}t|jjdkst|jddj }|j dks>t|j dksNtt|jjdksbt|jd kspt|j	d ks~t|j
j
d kst|jdd	}|jd
d	}|j
|kst|j|kst|j	|kst|j|kstd S )NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>r4   nav)r   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   rb   r   r   r   r   r   )r   r   Z	extractedZ	content_1Z	content_2r   r   r   test_extract  s     z!TestTreeModification.test_extractc             C   sz   | j d}|jj}|jj}|jd}|jd}|jj| |jj| |j  |j  ||jjksft||jjksvtd S )Nz<a>foo</a><b>bar</b>r=   r.   )r   r'   r   r   r"  r?   r   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   | j d  fdd jdD  dt jks4td S )Nzv
<html>
<head>
<script>foo</script>
</head>
<body>
 <script>bar</script>
 <a></a>
</body>
<script>baz</script>
</html>c                s   g | ]} j j qS r   )scriptr   )r   r   )r   r   r   r     s    zKTestTreeModification.test_extract_multiples_of_same_tag.<locals>.<listcomp>r8  z<body>

<a></a>
</body>)r   r%   r    r   r   )r   r   )r   r   "test_extract_multiples_of_same_tag  s    
z7TestTreeModification.test_extract_multiples_of_same_tagc             C   s.   | j d}|jdj  d |jdks*td S )Nz<html>
<body>hi</body>
</html>r   )r   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   | j d}|j}|jj  t|jjdks.tt|ds<t|j}|jdd dt|jks`tdS )zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>r   r   T)	decomposeN)	r   r'   r'  clearr$   r   r   rC   r/  )r   r   r'   r/  r   r   r   
test_clear  s    

zTestTreeModification.test_clearc             C   s   | j d}|jd\}}|j}|jj}x"||||gD ]}d|jks4tq4W |j  x |||gD ]}d|jks^tq^W d|jkstd S )Nz;<p><a>String <em>Italicized</em></a></p><p>Another para</p>r'  FT)r   r%   r'   r/  r   Z
decomposedr   r;  )r   r   r   r   r'   r!   r   r   r   r   test_decompose  s    
z#TestTreeModification.test_decomposec             C   sB   | j d}d|j_|jjdgks$td|j_|jjdgks>tdS )zTag.string = 'string'z<a></a> <b><c></c></b>r=   r.   N)r   r'   r   r   r   r   )r   r   r   r   r   test_string_set  s
    
z$TestTreeModification.test_string_setc             C   s,   | j d}|jj|j_|jj dks(td S )Nz<a><b>foo</b><c>bar</c>s   <a><b>bar</b><c>bar</c></a>)r   rP   r   r   r'   ra   r   )r   r   r   r   r   /test_string_set_does_not_affect_original_string  s    
zDTestTreeModification.test_string_set_does_not_affect_original_stringc             C   s0   | j d}td}||j_t|jjts,td S )Nz<a></a>r=   )r   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*   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.  r0  r2  r3  r4  r6  r7  r9  r:  r=  r>  r?  r@  rB  r   r   r   r   r     s\   	


		$	r   c               @   sB   e Zd Zejjddddddddd	d
dddgdd Zdd ZdS )TestDeprecatedArgumentsmethod_namer   r%   r   r   r   r   r   r   r   r   r   r   c          
   C   sf   | j d}t|j|}tjdd:}|dd |\}|jtksBtt|j	}|dksXtW d Q R X 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   r    message)r   rF  r   methodwwarningmsgr   r   r   test_find_type_method_string  s    	


z4TestDeprecatedArguments.test_find_type_method_stringc          
   C   s^   t jddH}tdd}|jdks&t|\}t|j}|jtksDt|dksPtW d Q R X d S )NT)rG  r!   )r!   zXThe 'text' argument to the SoupStrainer constructor is deprecated. Use 'string' instead.)	rI  rJ  r   r!   r   r    rM  rK  rL  )r   rO  rr   rP  rQ  r   r   r   $test_soupstrainer_constructor_string  s    

z<TestDeprecatedArguments.test_soupstrainer_constructor_stringN)r)   r*   r+   r   rC  rD  rR  rS  r   r   r   r   rE    s   rE  ))r,   pdbr   r   r1   rI  Zbs4r   Zbs4.builderr   r   Zbs4.elementr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r-   rF   rJ   r\   r}   r   r   r   r   r   r   r   r   r   rE  r   r   r   r   <module>
   s:   49N 5,2(1--    8