HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib64/python3.10/site-packages/bs4/tests/__pycache__/test_tree.cpython-310.pyc
o

�h��@s�dZddlmZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZmZmZmZmZddlmZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de!�Z"Gdd�de!�Z#Gdd �d e�Z$Gd!d"�d"e$�Z%Gd#d$�d$e$�Z&Gd%d&�d&e�Z'Gd'd(�d(e�Z(dS))a8Tests 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@�8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TestFindz�Basic tests of the find() method.

    find() just calls find_all() with limit=1, so it's not tested all
    that thouroughly here.
    cCs"|�d�}|�d�jdksJ�dS)Nz <a>1</a><b>2</b><a>3</a><b>4</b>�b�2)�soup�find�string��selfr�r�F/usr/local/CyberCP/lib/python3.10/site-packages/bs4/tests/test_tree.py�
test_find_tag-�
zTestFind.test_find_tagcCs"|�d�}|jdd�dksJ�dS)Nu<h1>Räksmörgås</h1>�
Räksmörgås�r)rrrrrr�test_unicode_text_find1rzTestFind.test_unicode_text_findcCs,|�d�}t|�d|jdd�jksJ�dS)Nu&<h1 id="Räksmörgås">here it is</h1>z
here it isr ��id)r�strr�textrrrr�test_unicode_attribute_find5s
z$TestFind.test_unicode_attribute_findcCs"|�d�}dt|���ksJ�dS)z)Test an optimization that finds all tags.�<a>foo</a><b>bar</b>�N�r�len�find_allrrrr�test_find_everything;s
zTestFind.test_find_everythingcCs$|�d�}dt|�d��ksJ�dS)z;Test an optimization that finds all tags with a given name.z<a>foo</a><b>bar</b><a>baz</a>r)�aNr*rrrr�test_find_everything_with_name@s
z'TestFind.test_find_everything_with_nameN)	�__name__�
__module__�__qualname__�__doc__rr"r'r-r/rrrrr&src@r)
�TestFindAllz%Basic tests of the find_all() method.cCsv|�d�}|jdd�dgksJ�|jddgd�ddgksJ�|jt�d�d�gd�ks-J�|jdd�gd�ks9J�dS)	z'You can search the tree for text nodes.u<html>Foo<b>bar</b>»</html>�barr!�Fooz.*)r6r5�»TN)rr,�re�compilerrrr�test_find_all_text_nodesHs

z$TestFindAll.test_find_all_text_nodescCst|�d�}|�|jddd�gd��|�|jddd�dg�|�|jddd�gd	��|�|jdd
d�gd	��dS)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�3rr>�
)r>rr?�4�5rN�r�assert_selectsr,rrrr�test_find_all_limitVs
��zTestFindAll.test_find_all_limitcCs:|�d�}|�|ddd�dg�|�|jdd�dg�dS)	Nz!<a>1</a><b>2<a id='foo'>3</a></b>r.rr<r>�foor#r?)rrDrrrrr�%test_calling_a_tag_is_calling_findallbs
z1TestFindAll.test_calling_a_tag_is_calling_findallcCs.|�d�}g}|�|�g|�|�ksJ�dS)N�<a></a>)r�appendr,)rr�lrrr�Ttest_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursiongs

z`TestFindAll.test_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursioncCsX|�d�}|�d�}t|d�sJ�|�d�}t|d�sJ�|jdd�}t|d�s*J�dS)z%All find_all calls return a ResultSetrHr.�sourceTrFr!N)rr,�hasattr)rr�resultrrr�test_find_all_resultsetqs


z#TestFindAll.test_find_all_resultsetN)	r0r1r2r3r:rErGrKrOrrrrr4Es
r4c@�eZdZdd�ZdS)�TestFindAllBasicNamespacescCs<|�d�}d|�d�jksJ�d|jddid�jksJ�dS)Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">rAzmathml:msqrtr.zsvg:fill�red��attrs)rrr�namerrrr�test_find_by_namespaced_name�s
z7TestFindAllBasicNamespaces.test_find_by_namespaced_nameN)r0r1r2rVrrrrrQ~�rQc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestFindAllByNamez&Test ways of finding tags by tag name.cC�|�d�|_dS)Nz�<a>First tag.</a>
                                  <b>Second tag.</b>
                                  <c>Third <a>Nested tag.</a> tag.</c>�r�tree�rrrr�setup_method��zTestFindAllByName.setup_methodcCs|�|j�d�ddg�dS�Nr.�
First tag.�Nested tag.�rDr[r,r\rrr�test_find_all_by_tag_name�s�z+TestFindAllByName.test_find_all_by_tag_namecCs\|�|jjddd�dg�|�|jjddd�ddg�|�|jjdt�d�d�ddg�dS)Nr.r`r!Tra�tag�rDr[r,r8r9r\rrr�test_find_all_by_name_and_text�s���z0TestFindAllByName.test_find_all_by_name_and_textcCs|�|jj�d�dg�dS)Nr.ra)rDr[�cr,r\rrr�!test_find_all_on_non_root_element�sz3TestFindAllByName.test_find_all_on_non_root_elementcCs|�|�d�ddg�dSr_)rDr[r\rrr�%test_calling_element_invokes_find_all�sz7TestFindAllByName.test_calling_element_invokes_find_allcCs |�|j�td��ddg�dSr_)rDr[r,r
r\rrr�test_find_all_by_tag_strainer���z/TestFindAllByName.test_find_all_by_tag_strainercCs |�|j�ddg�gd��dS)Nr.r�r`zSecond tag.rarbr\rrr�test_find_all_by_tag_names�rkz,TestFindAllByName.test_find_all_by_tag_namescCs"|�|j�ddd��gd��dS)NT)r.rrlrbr\rrr�test_find_all_by_tag_dict���z+TestFindAllByName.test_find_all_by_tag_dictcCs"|�|j�t�d��gd��dS)Nz^[ab]$rlrer\rrr�test_find_all_by_tag_re�roz)TestFindAllByName.test_find_all_by_tag_recCs,dd�}|�d�}|�|�|�ddg�dS)NcSs|j|�d�kS�Nr$)rU�get�rdrrr�id_matches_name�r^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>zMatch 1.zMatch 2.rC)rrtr[rrr�'test_find_all_with_tags_matching_method�s

�z9TestFindAllByName.test_find_all_with_tags_matching_methodcCsx|�d�}|�dd�}|�dt�d��}|�dddg�\}}d|jks%J�d|jks,J�d|jks3J�d|jks:J�dS)NzH<div class='a b'>1</div><div class='a c'>2</div><div class='a d'>3</div>�divza dza br?r>)rrr8r9r,r)rr�r1�r2�r3�r4rrr�%test_find_with_multi_valued_attribute�s�z7TestFindAllByName.test_find_with_multi_valued_attributeN)r0r1r2r3r]rcrfrhrirjrmrnrprur{rrrrrX�s
rXc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestFindAllByAttributecC�&|�d�}|�|jdd�ddg�dS)Nz�
                         <a id="first">Matching a.</a>
                         <a id="second">
                          Non-matching <b id="first">Matching b.</b>a.
                         </a>�firstr#zMatching a.zMatching b.rC�rr[rrr�test_find_all_by_attribute_name�s
�z6TestFindAllByAttribute.test_find_all_by_attribute_namecCstd�d�}d�d�}|�|�}|jg|j|d�ksJ�|jg|j|�d�d�ks*J�|jgs8J|j|dgd���dS)Nuםולש�utf8u<a title="םולש"></a>)�titlezsomething else)�encoderr.r,�decode)r�peace�datarrrr�%test_find_all_by_utf8_attribute_value�s


 z<TestFindAllByAttribute.test_find_all_by_utf8_attribute_valuecCsX|�d�}|�|jdd�dg�|�|jddid�dg�|�|jdd	id�d
g�dS)Na0
                         <a name="name1" class="class1">Name match.</a>
                         <a name="name2" class="class2">Class match.</a>
                         <a name="name3" class="class3">Non-match.</a>
                         <name1>A tag called 'name1'.</name1>
                         �name1�rUzA tag called 'name1'.rUrSzName match.�class�class2zClass match.rCrrrr�test_find_all_by_attribute_dict�s
���z6TestFindAllByAttribute.test_find_all_by_attribute_dictcCs�|�d�}|�|jddd�dg�|�|jddd�dg�|�|jdd	d�dg�|�|�dd�dg�|�|jdd
�ddg�|�|�dd�dg�|�|�dd	�dg�dS)Nz�
                         <a class="1">Class 1.</a>
                         <a class="2">Class 2.</a>
                         <b class="1">Class 1.</b>
                         <c class="3 4">Class 3 and 4.</c>
                         r.r>��class_zClass 1.rgr?zClass 3 and 4.rArSrCrrrr�test_find_all_by_class�s
	z-TestFindAllByAttribute.test_find_all_by_classcCst|�d�}|jdt�d�d�}|�|dg�|jdt�d�d�}|�|dg�|jdt�d�d�}|�|dg�dS)Nz#<gar class='foo bar'>Found it</gar>�gar�or��Found itr.zo b)rr,r8r9rD)rr[�frrr�0test_find_by_class_when_multiple_classes_presents
zGTestFindAllByAttribute.test_find_by_class_when_multiple_classes_presentcCsd|�d�}|�|�dt�d��dg�dd�}|�|�d|�g�dd�}|�|�d|�dg�dS)	Nz<a class='bar'>Found it</a>r.�bar�cSst|�dkS�Nr;�r+��valuerrr�big_attribute_value%�znTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.big_attribute_valuecSst|�dkSr�r�r�rrr�small_attribute_value*r�zpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_value�rrDr,r8r9)rrr�r�rrr�:test_find_all_with_non_dictionary_for_attrs_finds_by_class s
�zQTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_classcCs�|�d�}|�d�\}}||gsJ|�dd���|gs#J|�dd���|g|jddd�ks/J�|g|�dd�ks:J�g|�dd�ksDJ�dS)Nz*<a class="foo bar"></a><a class="foo"></a>r.rFr5zfoo barr�zbar foo�rr,)rrr.�a2rrr�:test_find_all_with_string_for_attrs_finds_multiple_classes0s
zQTestFindAllByAttribute.test_find_all_with_string_for_attrs_finds_multiple_classescCs0|�d�}tddid�}|�|�|�dg�dS)Nzi
                         <a id="first">Match.</a>
                         <a id="second">Non-match.</a>r$r~rSzMatch.)rr
rDr,)rr[�strainerrrr�'test_find_all_by_attribute_soupstrainer<s
z>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainercCs&|�d�}|�|jddd�dg�dS)N��<a id="1">ID present.</a>
                            <a>No ID present.</a>
                            <a id="">ID is empty.</a>r.r#zNo ID present.rCrrrr�$test_find_all_with_missing_attributeDs
z;TestFindAllByAttribute.test_find_all_with_missing_attributecCr})Nr�Tr#zID present.zID is empty.rCrrrr�$test_find_all_with_defined_attributeLs
�z;TestFindAllByAttribute.test_find_all_with_defined_attributecCs>|�d�}ddg}|�|jdd�|�|�|jdd�|�dS)Nz[<a id=1>Unquoted attribute.</a>
                            <a id="1">Quoted attribute.</a>zUnquoted attribute.zQuoted attribute.rr#r>rC)rr[�expectedrrr�$test_find_all_with_numeric_attributeUs
z;TestFindAllByAttribute.test_find_all_with_numeric_attributecCs*|�d�}|�|jgd�d�ddg�dS)Nz�<a id="1">1</a>
                            <a id="2">2</a>
                            <a id="3">3</a>
                            <a>No ID.</a>)r>r?rAr#r>r?rCrrrr�(test_find_all_with_list_attribute_values^s
�z?TestFindAllByAttribute.test_find_all_with_list_attribute_valuescCs,|�d�}|�|jt�d�d�ddg�dS)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#zOne a.zTwo as.r�rrrr�5test_find_all_with_regular_expression_attribute_valuehs
�zLTestFindAllByAttribute.test_find_all_with_regular_expression_attribute_valuecCsB|�d�}|j}|g|jddd�ksJ�g|jddd�ksJ�dS)Nz<b>foo</b><b>bar</b><a>foo</a>r.rFr!r5�rr.r,�rrr.rrr�'test_find_by_name_and_containing_stringu�
z>TestFindAllByAttribute.test_find_by_name_and_containing_stringcCs*|�d�}|�d�|jddd�ksJ�dS)Nz"<a>foo</a><a><b><c>foo</c></b></a>r.rFr!r�rrrr�=test_find_by_name_and_containing_string_when_string_is_buried|s
 zTTestFindAllByAttribute.test_find_by_name_and_containing_string_when_string_is_buriedcCsB|�d�}|j}|g|jddd�ksJ�g|jddd�ksJ�dS)Nz"<b id="1">foo</b><a id="2">foo</a>r)rF)r$rrr5r�r�rrr�,test_find_by_attribute_and_containing_string�r�zCTestFindAllByAttribute.test_find_by_attribute_and_containing_stringN)r0r1r2r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr|�s"		

r|c@�eZdZdZdd�ZdS)�
TestSmoothzTest Tag.smooth.cCs|�d�}|j}|�d�|�d�|�td��|�td��|�d�|��}t||d�}|�d�|�d	�|�|�d|jjksFJ�d
t|j	�ksOJ�|�
�dt|j	�ks\J�d|j	d
kseJ�d|jjksmJ�d|j	dksvJ�d|j	dksJ�dS)Nz<div>a</div>rrgz	Comment 1z	Comment 2�d�spanr>r���abcr�12rr))rrvrIr�default_builderrr�rr+�contents�smooth)rrrv�builderr�rrr�test_smooth�s(






zTestSmooth.test_smoothN)r0r1r2r3r�rrrrr��sr�c@r�)�	TestIndexzTest Tag.indexcCsp|�d�}|j}t|j�D]
\}}||�|�ksJ�q
t�t��|�d�Wd�dS1s1wYdS)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)rrv�	enumerater��index�pytest�raises�
ValueError)rr[rv�i�elementrrr�
test_index�s
	"�zTestIndex.test_indexN)r0r1r2r3r�rrrrr��sr�c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�TestParentOperationsz;Test navigation and searching through an element's parents.cCs|�d�|_|jj|_dS)Na1<ul id="empty"></ul>
                                 <ul id="top">
                                  <ul id="middle">
                                   <ul id="bottom">
                                    <b>Start here</b>
                                   </ul>
                                  </ul>)rr[r�startr\rrrr]�sz!TestParentOperations.setup_methodcCsF|jjddks
J�|jjjddksJ�|jjjjddks!J�dS)Nr$�bottom�middle�top)r��parentr\rrr�test_parent�sz TestParentOperations.test_parentcCs |jjd}|j|jksJ�dS)Nr)r[r�r�)r�top_tagrrr�%test_parent_of_top_tag_is_soup_object�sz:TestParentOperations.test_parent_of_top_tag_is_soup_objectcCsd|jjksJ�dS�N)r[r�r\rrr�test_soup_object_has_no_parent��z3TestParentOperations.test_soup_object_has_no_parentcCs6|�|j�d�gd��|�|jjddd�dg�dS)N�ul)r�r�r�r�r#)�assert_selects_idsr��find_parentsr\rrr�test_find_parents�s��z&TestParentOperations.test_find_parentscCs8|j�d�ddksJ�|jjddd�ddksJ�dS)Nr�r$r�r�r#)r��find_parentr\rrr�test_find_parent�s z%TestParentOperations.test_find_parentcCs"|jjdd�}|jjdksJ�dS)N�
Start herer!r)r[rr�rU�rr&rrr�test_parent_of_text_element��z0TestParentOperations.test_parent_of_text_elementcCs(|jjdd�}|�d�ddksJ�dS)Nr�r!r�r$r�)r[rr�r�rrr�test_text_element_find_parent�sz2TestParentOperations.test_text_element_find_parentcCs*dd�|jjD�}|sJdddkg��dS)NcSs&g|]}|durd|jvr|d�qSrqrS)�.0r�rrr�
<listcomp>�s�z>TestParentOperations.test_parent_generator.<locals>.<listcomp>r�r�r�)r��parents)rr�rrr�test_parent_generator�sz*TestParentOperations.test_parent_generatorN)
r0r1r2r3r]r�r�r�r�r�r�r�r�rrrrr��sr�c@rP)�
ProximityTestcCrY)Nzg<html id="start"><head></head><body><b id="1">One</b><b id="2">Two</b><b id="3">Three</b></body></html>rZr\rrrr]�s
�zProximityTest.setup_methodN�r0r1r2r]rrrrr��rWr�c�TeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�ZS)�TestNextOperationscstt|���|jj|_dSr�)�superr�r]r[rr�r\��	__class__rrr]szTestNextOperations.setup_methodcCs*|jjdksJ�|jjjddksJ�dS)N�Oner$r)r��next_elementr\rrr�	test_nextszTestNextOperations.test_nextcCs |jjdd�}|jdksJ�dS�N�Threer!)r[rr�)r�lastrrr�test_next_of_last_item_is_none
sz1TestNextOperations.test_next_of_last_item_is_nonecC�|jjdksJ�dSr�)r[r�r\rrr�test_next_of_root_is_none�z,TestNextOperations.test_next_of_root_is_nonecCsB|�|j�d�ddg�|jjdd�|�|jjdd�dg�dS)Nr�Twor�r;r#)rDr��
find_all_nextr\rrr�test_find_all_nextsz%TestNextOperations.test_find_all_nextcC�2|j�d�ddksJ�|jjdd�dksJ�dS)Nrr$rr�r!)r��	find_nextr\rrr�test_find_next�z!TestNextOperations.test_find_nextcCs<|jjdd�}|�d�jdksJ�|�|�d�ddg�dS)Nr�r!rr�r�)r[rr�rrDr�r�rrr�test_find_next_for_text_elementsz2TestNextOperations.test_find_next_for_text_elementcCsF|jjdd�}dd�|jD�}|\}}|ddksJ�|dks!J�dS)Nr�r!cS�g|]}|�qSrr�r��noderrrr�"�z:TestNextOperations.test_next_generator.<locals>.<listcomp>r$r?r�)r[r�
next_elements)rr��
successorsrdr�rrr�test_next_generator s
z&TestNextOperations.test_next_generator)r0r1r2r]r�r�r�r�r�r�r�
__classcell__rrr�rr�sr�cr�)�TestPreviousOperationsc�"tt|���|jjdd�|_dSr�)r�rr]r[r�endr\r�rrr]*r�z#TestPreviousOperations.setup_methodcCs*|jjddks
J�|jjjdksJ�dS)Nr$r?r�)r�previous_elementr\rrr�
test_previous.sz$TestPreviousOperations.test_previouscCs|j�d�}|jdks
J�dS)N�html)r[rr)rr~rrr�#test_previous_of_first_item_is_none2sz:TestPreviousOperations.test_previous_of_first_item_is_nonecCr�r�)r[rr\rrr�test_previous_of_root_is_none6r�z4TestPreviousOperations.test_previous_of_root_is_nonecCs4|�|j�d�gd��|�|jjdd�dg�dS)Nr�r�r�r�rr#r�)rDr�find_all_previousr\rrr�test_find_all_previous:s�z-TestPreviousOperations.test_find_all_previouscCr�)Nrr$r?r�r!)r�
find_previousr\rrr�test_find_previousBr�z)TestPreviousOperations.test_find_previouscCs<|jjdd�}|�d�jdksJ�|�|�d�gd��dS)Nr�r!rr)r[rrrrDrr�rrr�#test_find_previous_for_text_elementFs
�z:TestPreviousOperations.test_find_previous_for_text_elementcCsh|jjdd�}dd�|jD�}|\}}}}|ddksJ�|jdks$J�|jdks+J�|jd	ks2J�dS)
Nr�r!cSr�rrr�rrrr�Nr�zBTestPreviousOperations.test_previous_generator.<locals>.<listcomp>r$r>�body�headr)r[r�previous_elementsrU)rr��predecessorsrrrrrrr�test_previous_generatorLsz.TestPreviousOperations.test_previous_generator)r0r1r2r]rr	r
r
rrrrrrr�rr(src@rP)�SiblingTestcCs&d}t�d��d|�}|�|�|_dS)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*�)r8r9�subrr[)r�markuprrrr][szSiblingTest.setup_methodNr�rrrrrYrWrc�LeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�TestNextSiblingcr)Nr>r#)r�rr]r[rr�r\r�rrr]pr�zTestNextSibling.setup_methodcCr�r�)r[�next_siblingr\rrr�!test_next_sibling_of_root_is_nonetr�z1TestNextSibling.test_next_sibling_of_root_is_nonecC�B|jjddks
J�|jjjddksJ�|jjddksJ�dS)Nr$rr?�1.1)r�rr�r\rrr�test_next_siblingw�z!TestNextSibling.test_next_siblingcC�N|jjjdks	J�|jjdd�}|jdksJ�|jjdd�}|jdks%J�dS)Nrr#rA)r[rrr)r�nested_span�	last_spanrrr�test_next_sibling_may_not_exist~�
z/TestNextSibling.test_next_sibling_may_not_existcC�|j�d�ddksJ�dS)Nr�r$r)r��find_next_siblingr\rrr�test_find_next_sibling��z&TestNextSibling.test_find_next_siblingcC�4|�|j�d�gd��|�|jjdd�dg�dS)Nr�)rr?rAr?r#)r�r��find_next_siblingsr\rrr�test_next_siblings���z"TestNextSibling.test_next_siblingscC�v|�d�}|jdd�}|jjdksJ�|jjdksJ�|�|�d�dg�|jdd�dks/J�|jdd�dks9J�dS)N�Foo<b>bar</b>bazr6r!r�bazr5�nonesuch)rrrrUrDr,r(�rrr�rrr�"test_next_sibling_for_text_element��
z2TestNextSibling.test_next_sibling_for_text_element)r0r1r2r]rr r%r)r-r4rrrr�rrn�	rcr)�TestPreviousSiblingcr)NrAr#)r�r7r]r[rrr\r�rrr]�r�z TestPreviousSibling.setup_methodcCr�r�)r[�previous_siblingr\rrr�%test_previous_sibling_of_root_is_none�r�z9TestPreviousSibling.test_previous_sibling_of_root_is_nonecCr)Nr$r?rz3.1)rr8rr\rrr�test_previous_sibling�r!z)TestPreviousSibling.test_previous_siblingcCr")Nrr#r>)r[rr8r)rr#�
first_spanrrr�#test_previous_sibling_may_not_exist�r&z7TestPreviousSibling.test_previous_sibling_may_not_existcCr')Nr�r$r?)r�find_previous_siblingr\rrr�test_find_previous_sibling�r*z.TestPreviousSibling.test_find_previous_siblingcCr+)Nr�)r?rr>r>r#)r�r�find_previous_siblingsr\rrr�test_previous_siblings�r.z*TestPreviousSibling.test_previous_siblingscCr/)Nr0r1r!rr6r5r2)rrr8rUrDr?r=r3rrr�&test_previous_sibling_for_text_element�r5z:TestPreviousSibling.test_previous_sibling_for_text_element)r0r1r2r]r9r:r<r>r@rArrrr�rr7�r6r7c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zej�d#d$d%�d&d%�g�d'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�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)`�TestTreeModificationcCsl|�d�}d|jd<|��|�d�ksJ�|jd=|��|�d�ks$J�d|jd<|��|�d�ks4J�dS)	Nz<a id="1"></a>r)r$z<a id="2"></a>rHrF�id2z<a id2="foo"></a>)rr.r��document_forrrrr�test_attribute_modification�s


z0TestTreeModification.test_attribute_modificationcCslt�d��}|jd|d�}t||d�}t||d�}d|d<|j�d|�|j�d	|�|j��d
ks4J�dS)Nrz
<body></body>�r�r.�olzhttp://foo.com/�hrefrrs4<body><a href="http://foo.com/"></a><ol></ol></body>)r�lookuprrr�insertr�)rr�rr.rGrrr�test_new_tag_creation�sz*TestTreeModification.test_new_tag_creationcCs\d}|�|�}|jdd�}|j}|jdd��|j�|j|ks!J�|��|�d�ks,J�dS)NzT<p id="1">Don't leave me <b>here</b>.</p>
                <p id="2">Don't leave!</p>rr#zD<p id="1">Don't leave me .</p>
<p id="2">Don't leave!<b>here</b></p>)rrrrIr�r�rD)r�docr�second_para�boldrrr�!test_append_to_contents_moves_tag�s

�z6TestTreeModification.test_append_to_contents_moves_tagcCs0d}|�|�}|j}|�|j�}||ksJ�dS)Nz<a></a><b><c></c></b>)rr.�replace_withrg�rr&rr.�new_arrr�1test_replace_with_returns_thing_that_was_replaced�s

zFTestTreeModification.test_replace_with_returns_thing_that_was_replacedcCs,d}|�|�}|j}|��}||ksJ�dS)N�<a><b></b><c></c></a>)rr.�unwraprQrrr�+test_unwrap_returns_thing_that_was_replaced�s

z@TestTreeModification.test_unwrap_returns_thing_that_was_replacedcCs�|�d�}|j}|��d|jksJ�t�t��|��Wd�n1s'wYt�t��|�|j	�Wd�dS1sCwYdS)Nz<a><b>Foo</b></a><c>Bar</c>)
rr.�extractr�r�r�r�rUrPrgr�rrr�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_parentcCs:d}|�|�}|j}|j�|�|��|�|�ksJ�dS)Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)rrgrPr�rD)rr&rrgrrr�test_replace_tag_with_itselfs

z1TestTreeModification.test_replace_tag_with_itselfcCsLd}|�|�}t�t��|j�|j�Wd�dS1swYdS�N�<a><b></b></a>)rr�r�r�rrPr.�rr&rrrr�1test_replace_tag_with_its_parent_raises_exceptions

"�zFTestTreeModification.test_replace_tag_with_its_parent_raises_exceptioncCsNd}|�|�}t�t��|j�d|j�Wd�dS1s wYdS)Nr[r)rr�r�r�r.rJr\rrr�,test_insert_tag_into_itself_raises_exceptions

"�zATestTreeModification.test_insert_tag_into_itself_raises_exceptionc	Cs�|�d�}d}|�|�}|�d|�|jD]	}t|t�rJ�qt|j�\}}}}d|jks/J�d|jks6J�d|jks=J�d|jksDJ�dS)	z�Inserting one BeautifulSoup object into another actually inserts all
        of its children -- you'll never combine BeautifulSoup objects.
        z-<p>And now, a word:</p><p>And we're back.</p>z<p>p2</p><p>p3</p>rzAnd now, a word:�p2�p3zAnd we're back.N)rrJ�descendants�
isinstancer�list�childrenr)	rrr&�	to_insertr��p1r_r`�p4rrr�1test_insert_beautifulsoup_object_inserts_childrens


zFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrencCsX|�d�}|j}|jd}|�dd�|j\}}|�d�|�d�d|jjks*J�dS)Nz<p><a>one</a><b>three</b></p>rr�twor�three)rr.r�rJ�replaceWithrr)rrr.r�left�rightrrr�3test_replace_with_maintains_next_element_throughout.s




zHTestTreeModification.test_replace_with_maintains_next_element_throughoutcCsl|�d�}|jdd��d�|jdd�}|j}|j|ksJ�|j|ks%J�|jj|ks-J�|jdks4J�dS)Nz<b>Argh!</b>�Argh!r!�Hooray!)rrrPrrr�r�)rr�new_textrrrr�test_replace_final_node=s
z,TestTreeModification.test_replace_final_nodecCs�|�d�}|j�dd�|��|�d�ksJ�|jdd�}|jdks$J�|jj|ks,J�|jdks3J�|jj	|ks;J�|j	dksBJ�|j|j
ksJJ�dS)Nz<a><b>Argh!</b><c></c></a>rrpz!<a><b>Argh!Hooray!</b><c></c></a>r!ro)rrrJr�rDrrr�r8rrg)rrrqrrr�test_consecutive_text_nodesGs


�z0TestTreeModification.test_consecutive_text_nodescCsT|�d�}|j�dd�|j�dd�ddg|jjksJ�|jjdjdks(J�dS)NrHrr5rF)rr.rJr�r�rrrr�test_insert_string\s

z'TestTreeModification.test_insert_stringcCs�|��}|jd|d�}t||d�}|�dd�|j�d|�|��|�d�ks)J�|j}|j|ks3J�|j	|ks:J�|j
dd	�}|j|ksGJ�|j|ksNJ�|j
}|j|ksXJ�|j	|ks_J�|j
dd	�}|j|kslJ�|j|kssJ�|j|kszJ�dS)
Nz%<a><b>Find</b><c>lady!</c><d></d></a>rF�magictagr�therz=<a><b>Find</b><magictag>the</magictag><c>lady!</c><d></d></a>�Findr!)r�rrrJr.r�rDrrr8rr�rrgr�)rr�r�	magic_tag�b_tagr�c_tagrvrrr�test_insert_tages.�

�z$TestTreeModification.test_insert_tagcCs0d}|�|�}|j�|j�||��ksJ�dSrZ)rr.rIrr��rr�rrrr�*test_append_child_thats_already_at_the_end��
z?TestTreeModification.test_append_child_thats_already_at_the_endcCsJd}|�|�}|j|j|j|j|j|jg}|j�|�d|�	�ks#J�dS)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�rgrr.�extendr�)rr�rrJrrr�test_extend�s

z TestTreeModification.test_extend�get_tagscCs|Sr�rrsrrr�<lambda>�szTestTreeModification.<lambda>cCs|jSr�)r�rsrrrr��scCs`d}|�|�}|jddd�}|jddd�}||�}|�|�d|��ks&J�d|��ks.J�dS)NzS<body><div id="d1"><a>1</a><a>2</a><a>3</a><a>4</a></div><div id="d2"></div></body>rv�d1r#�d2z<div id="d1"></div>z3<div id="d2"><a>1</a><a>2</a><a>3</a><a>4</a></div>)rrr�r�)rr�r�rr�r��tagsrrr�&test_extend_with_another_tags_contents�s

z;TestTreeModification.test_extend_with_another_tags_contentscCs2d}|�|�}|j�d|j�d|��ksJ�dS)Nz<a><b></b><c></c><d></d></a>rz<a><d></d><b></b><c></c></a>)rr.rJr�r�r|rrr�$test_move_tag_to_beginning_of_parent�s
z9TestTreeModification.test_move_tag_to_beginning_of_parentcCs.|�d�}|j�dd�t|j�dksJ�dS)Nz<br/>r�Contentsz<br>Contents</br>)r�brrJr%rrrr�&test_insert_works_on_empty_element_tag�s
z;TestTreeModification.test_insert_works_on_empty_element_tagcCs�|�d�}|j�d�|j�d�|��|�d�ksJ�|j�|j�|��|�d�ks.J�|j}t�t��
|�|�Wd�n1sFwY|�	�t�t��
|�d�Wd�n1sdwY|�d�}|j�|�
d��dS)	Nr(�BAZ�QUUXzQUUX<a>foo</a>BAZ<b>bar</b>�QUUX<b>bar</b><a>foo</a>BAZ�nope�<a>r.)rr�
insert_beforer.r�rDr�r�r�rW�new_tag�rrrrrr�test_insert_before�s$


���
z'TestTreeModification.test_insert_beforecCsj|�d�}|j�ddd�|j�ddd�|��|�d�ks J�|j�|jd�|��|�d�ks3J�dS)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)rrr�r.r�rDrrrr�test_insert_multiple_before�s


�
�z0TestTreeModification.test_insert_multiple_beforecCs�|�d�}|j�d�|j�d�|��|�d�ksJ�|j�|j�|��|�d�ks.J�|j}t�t��
|�|�Wd�n1sFwY|�	�t�t��
|�d�Wd�n1sdwY|�d�}|j�
|�d��dS)	Nr(r�r�z<a>foo</a>QUUX<b>bar</b>BAZr�r�r�r.)rr�insert_afterr.r�rDr�r�r�rWr�r�r�rrr�test_insert_after�s$


���
z&TestTreeModification.test_insert_aftercCsj|�d�}|j�ddd�|j�ddd�|��|�d�ks J�|j�|jd�|��|�d�ks3J�dS)Nr(r�r�r�z$<a>foo</a>QUUX BAZ<b>bar</b>BAZ QUUXzFOO z(QUUX BAZ<b>bar</b><a>foo</a>FOO BAZ QUUX)rrr�r.r�rDrrrr�test_insert_multiple_after�s


�
�z/TestTreeModification.test_insert_multiple_aftercC�|�d�}|�d�}|�d�}t�t��
|�|�Wd�n1s$wYt�t��
|�|�Wd�n1s>wYt�t��|�|�Wd�dS1sYwYdS�Nrr.)rr��
new_stringr�r�r�r��NotImplementedError�rrrdrrrr�:test_insert_after_raises_exception_if_after_has_no_meaning��


��"�zOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningcCr�r�)rr�r�r�r�r�r�r�r�rrr�Ftest_insert_before_raises_notimplementederror_if_before_has_no_meaningr�z[TestTreeModification.test_insert_before_raises_notimplementederror_if_before_has_no_meaningcCsv|�d�}|�d�\}}|�|�|��|�d�ksJ�|jdks#J�|j|jks+J�|jdks2J�|jdks9J�dS)Nz;<p>There's <b>no</b> business like <b>show</b> business</p>rz0<p>There's  business like <b>no</b> business</p>�noz	 business)	rr,rPr�rDr��pr�r)rrr��showrrr�test_replace_withs�


�z&TestTreeModification.test_replace_withcCs�tdd�}t�t��
|�d�Wd�n1swY|�d�j}t�t��|j�|�Wd�n1s;wYt�t��|j�d|d�Wd�dS1sYwYdS)Nr.r�z
won't workr[�string1�string2)rr�r�r�rPrr.r)r�a_tagrrr�test_replace_with_errorss
��"�z-TestTreeModification.test_replace_with_errorscCs�d}|�|�}|�d�}d|_|�d�}|�d�}d}|j�||||�|��dks,J�|jj|ks4J�|jj|ks<J�|jj|ksDJ�|jj|ksLJ�dS)NrTr�z
Text In D Tagr�r�zRandom Textz;<a><b></b><d>Text In D Tag</d><e></e>Random Text<f></f></a>)rr�rrgrPr�rr�)rr�r�d_tag�e_tag�f_tag�a_stringrrr�test_replace_with_multiple-s



z/TestTreeModification.test_replace_with_multiplecC�0d}|�|�}|j�|j�d|��ksJ�dS)NrTz<a><c></c></a>)rrrPrgr�r|rrr�test_replace_first_child<r~z-TestTreeModification.test_replace_first_childcCr�)NrTr[)rrgrPrr�r|rrr�test_replace_last_childBr~z,TestTreeModification.test_replace_last_childcCs|�d�}|j}|j}|�|�|��|�d�ksJ�|jdks"J�|jdd�jdks-J�|j	dks4J�|j
dks;J�|jdksBJ�|j|jksJJ�|j	dksQJ�|jj|j
ksZJ�|j
dksaJ�|jdd�}|j}|j|ksqJ�|j
|ksxJ�|j	|ksJ�|j|ks�J�dS)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>rmr!�We�to)rrr�rPr�rDr�rr�rrr8r.r�r)rr�
remove_tag�move_tag�to_text�g_tagrrr�test_nested_tag_replace_withHs0�


�z1TestTreeModification.test_nested_tag_replace_withcCs6|�d�}|j��|jdksJ�|jjdksJ�dS)NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r�emrUr�r&rrrr�test_unwrapls

z TestTreeModification.test_unwrapcCsF|�d�}|j�|�d��}|��dksJ�|��|�d�ks!J�dS)NzI wish I was bold.r�<b>I wish I was bold.</b>)rr�wrapr�r�rD)rrr�rrr�	test_wrapts
zTestTreeModification.test_wrapcCs4|�d�}|jj�|j�|��|�d�ksJ�dS)Nz<b></b>I wish I was bold.r�)rrrr�r�rDrrrr�%test_wrap_extracts_tag_from_elsewherezs
z:TestTreeModification.test_wrap_extracts_tag_from_elsewherecCsH|�d�}|jj�|j�dt|jj�ksJ�|��|�d�ks"J�dS)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>)rrrr�r+r�r�rDrrrr�&test_wrap_puts_new_contents_at_the_ends

�z;TestTreeModification.test_wrap_puts_new_contents_at_the_endcCs�|�d�}t|jj�dksJ�|jdd���}|��dksJ�|��dks'J�t|jj�dks1J�|jdks8J�|jdks?J�|j	j	dksGJ�|jdd	�}|jd
d	�}|j	|ksZJ�|j
|ksaJ�|j|kshJ�|j|ksoJ�dS)NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>r;�navr#z6<html><body>Some content.  More content.</body></html>z<div id="nav">Nav crap</div>r)zSome content. r!z More content.)rr+rr�rrWr�r�rr�rr8)rr�	extracted�	content_1�	content_2rrr�test_extract�s"�z!TestTreeModification.test_extractcCsz|�d�}|jj}|jj}|�d�}|�d�}|j�|�|j�|�|��|��||jjks3J�||jjks;J�dS)Nr(rFr5)rr.rrr�rIrW)rr�foo_1�bar_1�foo_2�bar_2rrr�4test_extract_distinguishes_between_identical_strings�s


zITestTreeModification.test_extract_distinguishes_between_identical_stringscs8|�d���fdd���d�D�dt�j�ksJ�dS)Nzv
<html>
<head>
<script>foo</script>
</head>
<body>
 <script>bar</script>
 <a></a>
</body>
<script>baz</script>
</html>csg|]}�j���qSr)�scriptrW)r�r��rrrr��szKTestTreeModification.test_extract_multiples_of_same_tag.<locals>.<listcomp>r�z<body>

<a></a>
</body>)rr,r%rr\rr�r�"test_extract_multiples_of_same_tag�s
z7TestTreeModification.test_extract_multiples_of_same_tagcCs.|�d�}|�d���d|�d�ksJ�dS)Nz<html>
<body>hi</body>
</html>r)rrrWrrrr�Btest_extract_works_when_element_is_surrounded_by_identical_strings�s
�zWTestTreeModification.test_extract_works_when_element_is_surrounded_by_identical_stringscCsd|�d�}|j}|j��t|jj�dksJ�t|d�sJ�|j}|jdd�dt|j�ks0J�dS)zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>rr�T)�	decomposeN)rr.r��clearr+r�rMr�)rrr.r�rrr�
test_clear�s

zTestTreeModification.test_clearcCs~|�d�}|�d�\}}|j}|jj}||||fD]	}d|jks"J�q|��|||fD]	}d|jks5J�q,d|jks=J�dS)Nz;<p><a>String <em>Italicized</em></a></p><p>Another para</p>r�FT)rr,r.r�r�
decomposedr�)rrrfr_r.r&r�rrr�test_decompose�s
z#TestTreeModification.test_decomposecCsB|�d�}d|j_|jjdgksJ�d|j_|jjdgksJ�dS)zTag.string = 'string'z<a></a> <b><c></c></b>rFr5N)rr.rr�rrrrr�test_string_set�s

z$TestTreeModification.test_string_setcCs,|�d�}|jj|j_|j��dksJ�dS)Nz<a><b>foo</b><c>bar</c>s<a><b>bar</b><c>bar</c></a>)rrgrrr.r�rrrr�/test_string_set_does_not_affect_original_string�s
zDTestTreeModification.test_string_set_does_not_affect_original_stringcCs0|�d�}td�}||j_t|jjt�sJ�dS)NrHrF)rrr.rrb)rr�cdatarrr�)test_set_string_preserves_class_of_string�s
z>TestTreeModification.test_set_string_preserves_class_of_stringN)3r0r1r2rErKrOrSrVrXrYr]r^rhrnrrrsrtr{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�rrrrrB�sb	


	�

	
$	rBc@s.eZdZej�dgd��dd��Zdd�ZdS)�TestDeprecatedArguments�method_name)rr,r�r�r�r�rrr(r,r=r?cCs||�d�}t|j|�}tjdd��#}|dd�|\}|jtks!J�t|j�}|dks,J�Wd�dS1s7wYdS)Nz<a>some</a><b>markup</b>T��recordr�r&zOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.)	r�getattrr�warnings�catch_warnings�filename�__file__r%�message)rr�r�method�w�warning�msgrrr�test_find_type_method_string�s
	

"�z4TestDeprecatedArguments.test_find_type_method_stringcCsttjdd��*}tdd�}|jdksJ�|\}t|j�}|jtks"J�|dks(J�Wd�dS1s3wYdS)NTr�r&r�zXThe 'text' argument to the SoupStrainer constructor is deprecated. Use 'string' instead.)r�r�r
r&r%r�r�r�)rr�r�r�r�rrr�$test_soupstrainer_constructor_strings

"�z<TestDeprecatedArguments.test_soupstrainer_constructor_stringN)r0r1r2r�r�r�r�r�rrrrr��s�

r�))r3�pdbrr�r8r��bs4r�bs4.builderrr�bs4.elementrrrr	r
rrr
rrrrrrr4rQrXr|r�r�r�r�r�rrrr7rBr�rrrr�<module>s<
4
9N5,2(1--8