
    (ph"                        S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
JrJrJr  SSKJr  SSKJr   " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S \5      r " S! S"\5      r " S# S$\5      r " S% S&\5      r / S'Qr! " S( S)\5      r" " S* S+\5      r#g),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                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)TestFind   z&Basic tests of the find() method.
    c                 h    U R                  S5      nUR                  S5      R                  S:X  d   eg )Nz <a>1</a><b>2</b><a>3</a><b>4</b>b2)soupfindstringselfr   s     F/var/www/html/venv/lib/python3.13/site-packages/bs4/tests/test_tree.pytest_find_tagTestFind.test_find_tag"   s-    yy;<yy~$$+++    c                 P    U R                  S5      nUR                  SS9S:X  d   eg )Nu   <h1>Räksmörgås</h1>   Räksmörgåsr   )r   r   r   s     r   test_unicode_text_findTestFind.test_unicode_text_find&   s*    yy12yyy0OCCCr   c                 z    U R                  S5      n[        U5        SUR                  SS9R                  :X  d   eg )Nu&   <h1 id="Räksmörgås">here it is</h1>z
here it isr   id)r   strr   textr   s     r   test_unicode_attribute_find$TestFind.test_unicode_attribute_find*   s7    yyABD	tyyOy<AAAAAr   c                 d    U R                  S5      nS[        UR                  5       5      :X  d   eg)z)Test an optimization that finds all tags.<a>foo</a><b>bar</b>   Nr   lenfind_allr   s     r   test_find_everythingTestFind.test_find_everything/   s*    yy/0C((((r   c                 f    U R                  S5      nS[        UR                  S5      5      :X  d   eg)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   s     r   test_find_everything_with_name'TestFind.test_find_everything_with_name4   s-    yy9:Cc*++++r   c                 "   U R                  S5      nSUR                  5       R                  :X  d   eSUR                  S5      R                  5       R                  :X  d   eSUR                  S5      R	                  5       R                  :X  d   eg )Nz<div></div><p></p>divpr   r   namefind_previous_siblingfind_next_siblingr   s     r   test_find_with_no_arguments$TestFind.test_find_with_no_arguments9   sv    yy-.		(((((		#<<>CCCCCdii&88:?????r   c                 "   U R                  S5      nSUR                  5       R                  :X  d   eSUR                  S5      R                  5       R                  :X  d   eSUR                  S5      R	                  5       R                  :X  d   eg )N"text<div>text</div>text<p>text</p>r5   r6   r7   r   s     r   +test_find_with_no_arguments_only_finds_tags4TestFind.test_find_with_no_arguments_only_finds_tags?   sv    yy=>		(((((		#<<>CCCCCdii&88:?????r   c                     U R                  S5      nSUR                  S 5      R                  :X  d   eS UR                  S 5      :X  d   eg )Nr>   r6   c                      U R                   S:H  $ )Nr6   r8   ts    r   <lambda>ETestFind.test_find_with_function_can_only_find_tags.<locals>.<lambda>G   s    !&&#+r   c                     U S:H  $ )Nr%    rD   s    r   rF   rG   H   s    1f9r   )r   r   r8   r   s     r   *test_find_with_function_can_only_find_tags3TestFind.test_find_with_function_can_only_find_tagsE   sG    yy=>dii 56;;;;;tyy!45555r   rI   N)__name__
__module____qualname____firstlineno____doc__r   r   r&   r.   r2   r;   r?   rJ   __static_attributes__rI   r   r   r   r      s3    ,DB
)
,
@@6r   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)TestFindAllJ   z%Basic tests of the find_all() method.c                 0   U R                  S5      nS[        UR                  R                  5       5      :X  d   eS[        UR	                  S5      R                  5       5      :X  d   eS[        UR	                  S5      R                  5       5      :X  d   eg )Nz/<body>text<div>text</div>text<p>text</p></body>r*   r   r6   r5   )r   r,   bodyr-   r   find_previous_siblingsfind_next_siblingsr   s     r   /test_find_all_with_no_arguments_only_finds_tags;TestFindAll.test_find_all_with_no_arguments_only_finds_tagsM   sz    yyJKC		**,----C		#==?@@@@C		%(;;=>>>>r   c                    U R                  S5      nUR                  SS9S/:X  d   eUR                  SS/S9SS/:X  d   eUR                  [        R                  " S5      S9/ SQ:X  d   eUR                  SS9/ SQ:X  d   eg)	z'You can search the tree for text nodes.u   <html>Foo<b>bar</b>»</html>barr   Fooz.*)r]   r\      »TN)r   r-   recompiler   s     r   test_find_all_text_nodes$TestFindAll.test_find_all_text_nodesS   s    yy9:}}E}*ug555 }}UEN}3u~EEE}}BJJt$4}59OOOO}}D})-CCCCr   c                 4   U R                  S5      nU R                  UR                  SSS9/ SQ5        U R                  UR                  SSS9S/5        U R                  UR                  SSS9/ S	Q5        U R                  UR                  SS
S9/ S	Q5        g)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>r1      limit)1r   3r   rg   
   )rg   r   rh   45r   Nr   assert_selectsr-   r   s     r   test_find_all_limitTestFindAll.test_find_all_limit`   s    yyCDDMM#QM7IDMM#QM7#?DMM#RM8:ST 	DMM#QM79RSr   c                     U R                  S5      nU R                  U" SSS9S/5        U R                  UR                  SS9S/5        g )	Nz!<a>1</a><b>2<a id='foo'>3</a></b>r1   r   re   rg   foor"   rh   )r   rm   r   r   s     r   %test_calling_a_tag_is_calling_findall1TestFindAll.test_calling_a_tag_is_calling_findallj   sG    yy<=DA.6DFFeF,se4r   c                 F   U R                  S5      n/ nUR                  U5        [        R                  " SS9 n/ UR	                  U5      :X  d   eUu  nUR
                  [        :X  d   e[        UR                  5      nUS:X  d   e S S S 5        g ! , (       d  f       g = f)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msgs         r   Ttest_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursion`TestFindAll.test_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursiono   s     yy#w $$D1Qw////IW##x///goo&Cabb 211s   AB
B c                     U R                  S5      nUR                  S5      n[        US5      (       d   eUR                  S5      n[        US5      (       d   eUR                  SS9n[        US5      (       d   eg)z%All find_all calls return a ResultSetru   r1   sourceTrq   r   N)r   r-   hasattrr   r   results      r   test_find_all_resultset#TestFindAll.test_find_all_resultset   su    yy#s#vx((((t$vx((((e,vx((((r   rI   N)rL   rM   rN   rO   rP   rY   ra   rn   rr   r   r   rQ   rI   r   r   rS   rS   J   s%    /?DT5
(
)r   rS   c                       \ rS rSrS rSrg)TestFindAllBasicNamespaces   c                     U R                  S5      nSUR                  S5      R                  :X  d   eSUR                  SS0S9R                  :X  d   eg )Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">rj   zmathml:msqrtr1   zsvg:fillredattrs)r   r   r   r8   r   s     r   test_find_by_namespaced_name7TestFindAllBasicNamespaces.test_find_by_namespaced_name   sR    yyKLdii/66666diiz5&9i:?????r   rI   N)rL   rM   rN   rO   r   rQ   rI   r   r   r   r      s    @r   r   c                   ^    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rSrg)TestFindAllByName   z&Test ways of finding tags by tag name.Nc                 0    U R                  S5      U l        g )Nz<a>First tag.</a>
                                  <b>Second tag.</b>
                                  <c>Third <a>Nested tag.</a> tag.</c>r   treer   s    r   setup_methodTestFindAllByName.setup_method   s    II J K	r   c                 ^    U R                  U R                  R                  S5      SS/5        g Nr1   
First tag.Nested tag.rm   r   r-   r   s    r   test_find_all_by_tag_name+TestFindAllByName.test_find_all_by_tag_name   s&    DII..s3lM5RSr   c                 2   U R                  U R                  R                  SSS9S/5        U R                  U R                  R                  SSS9SS/5        U R                  U R                  R                  S[        R                  " S5      S9SS/5        g )Nr1   r   r   Tr   tagrm   r   r-   r_   r`   r   s    r   test_find_all_by_name_and_text0TestFindAllByName.test_find_all_by_name_and_text   s    IIs<8<.	
 	IIs40<2O	
 	IIs2::e+<==)	
r   c                 p    U R                  U R                  R                  R                  S5      S/5        g )Nr1   r   )rm   r   cr-   r   s    r   !test_find_all_on_non_root_element3TestFindAllByName.test_find_all_on_non_root_element   s'    DIIKK005Gr   c                 J    U R                  U R                  S5      SS/5        g r   )rm   r   r   s    r   %test_calling_element_invokes_find_all7TestFindAllByName.test_calling_element_invokes_find_all   s    DIIcN\=,IJr   c                 p    U R                  U R                  R                  [        S5      5      SS/5        g r   )rm   r   r-   r
   r   s    r   test_find_all_by_tag_strainer/TestFindAllByName.test_find_all_by_tag_strainer   s.    II|C01L-3P	
r   c                 b    U R                  U R                  R                  SS/5      / SQ5        g )Nr1   r   r   zSecond tag.r   r   r   s    r   test_find_all_by_tag_names,TestFindAllByName.test_find_all_by_tag_names   s)    IISz*,X	
r   c                 d    U R                  U R                  R                  SSS.5      / SQ5        g )NT)r1   r   r   r   r   s    r   test_find_all_by_tag_dict+TestFindAllByName.test_find_all_by_tag_dict   s*    IIT568	
r   c                     U R                  U R                  R                  [        R                  " S5      5      / SQ5        g )Nz^[ab]$r   r   r   s    r   test_find_all_by_tag_re)TestFindAllByName.test_find_all_by_tag_re   s.    IIrzz(348	
r   c                 r    S nU R                  S5      nU R                  UR                  U5      SS/5        g )Nc                 >    U R                   U R                  S5      :H  $ )Nr#   )r8   getr   s    r   id_matches_nameRTestFindAllByName.test_find_all_with_tags_matching_method.<locals>.id_matches_name   s    88swwt},,r   z<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.rl   )r   r   r   s      r   'test_find_all_with_tags_matching_method9TestFindAllByName.test_find_all_with_tags_matching_method   s<    	- yy 6 7 	DMM/:Z<TUr   c                 R   U R                  S5      nUR                  SS5      nUR                  S[        R                  " S5      5      nUR	                  SSS/5      u  pESUR
                  :X  d   eSUR
                  :X  d   eSUR
                  :X  d   eSUR
                  :X  d   eg )NzH<div class='a b'>1</div><div class='a c'>2</div><div class='a d'>3</div>r5   za dza brh   rg   )r   r   r_   r`   r-   r   )r   r   r1r2r3r4s         r   %test_find_with_multi_valued_attribute7TestFindAllByName.test_find_with_multi_valued_attribute   s    yyV
 YYue$YYubjj01uuen5biibiibiibiir   r   returnN)rL   rM   rN   rO   rP   r   r   r   r   r   r   r   r   r   r   r   rQ   rI   r   r   r   r      sA    0K
T
HK






V
 r   r   c                   t    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSrg)TestFindAllByAttribute   c                 h    U R                  S5      nU R                  UR                  SS9SS/5        g )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.rl   r   r   s     r   test_find_all_by_attribute_name6TestFindAllByAttribute.test_find_all_by_attribute_name   s9     yy ! "
 	DMMWM5}7UVr   c                 X   SR                  S5      nSR                  S5      nU R                  U5      nUR                  /UR                  US9:X  d   eUR                  /UR                  UR	                  S5      S9:X  d   eUR                  /(       d   UR                  US/S95       eg )Nu   םולשutf8u   <a title="םולש"></a>)titlezsomething else)encoder   r1   r-   decode)r   peacedatar   s       r   %test_find_all_by_utf8_attribute_value<TestFindAllByAttribute.test_find_all_by_utf8_attribute_value   s    !!&))008yyx4==u=5555x4==u||F/C=DDDDxGe5E-FGGxr   c                     U R                  S5      nU R                  UR                  SS9S/5        U R                  UR                  SS0S9S/5        U R                  UR                  SS	0S9S
/5        g )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>
                         name1rC   zA tag called 'name1'.r8   r   zName match.classclass2zClass match.rl   r   s     r   test_find_all_by_attribute_dict6TestFindAllByAttribute.test_find_all_by_attribute_dict   s}     yy   	DMMwM7:Q9RSDMM0AMB]OTDMM(0CMD~FVWr   c                     U R                  S5      nU R                  UR                  SSS9S/5        U R                  UR                  SSS9S/5        U R                  UR                  SS	S9S/5        U R                  UR                  SS5      S/5        U R                  UR                  SS
9SS/5        U R                  UR                  SS5      S/5        U R                  UR                  SS	5      S/5        g )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>
                         r1   rg   class_zClass 1.r   rh   zClass 3 and 4.rj   r   rl   r   s     r   test_find_all_by_class-TestFindAllByAttribute.test_find_all_by_class  s    yy   	DMM#cM:ZLIDMM#cM:=M<NODMM#cM:=M<NO 	DMM#s3j\BDMMM4z:6NODMM#s36F5GHDMM#s36F5GHr   c                 p   U R                  S5      nUR                  S[        R                  " S5      S9nU R	                  US/5        UR                  S[        R                  " S5      S9nU R	                  US/5        UR                  S[        R                  " S5      S9nU R	                  US/5        g )Nz#<gar class='foo bar'>Found it</gar>garor   Found itr1   zo b)r   r-   r_   r`   rm   )r   r   fs      r   0test_find_by_class_when_multiple_classes_presentGTestFindAllByAttribute.test_find_by_class_when_multiple_classes_present   s    yy>?MM%

3M8A
|,MM%

3M8A
|, MM%

5(9M:A
|,r   c                 *   U R                  S5      nU R                  UR                  S[        R                  " S5      5      S/5        S nU R                  UR                  SU5      / 5        S nU R                  UR                  SU5      S/5        g )Nz<a class='bar'>Found it</a>r1   bar   c                     [        U 5      S:  $ Nrd   r,   values    r   big_attribute_valuenTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.big_attribute_value3  s    u:>!r   c                     [        U 5      S:*  $ r   r   r   s    r   small_attribute_valuepTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_value8  s    u:?"r   r   rm   r-   r_   r`   )r   r   r   r   s       r   :test_find_all_with_non_dictionary_for_attrs_finds_by_classQTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.  s    yy67DMM#rzz$/?@:,O	" 	DMM#/BCRH	# 	DMM#/DE
|Tr   c                 X   U R                  S5      nUR                  S5      u  p#X#/(       d   UR                  SS5      5       eU/(       d   UR                  SS5      5       eU/UR                  SSS9:X  d   eU/UR                  SS5      :X  d   e/ UR                  SS5      :X  d   eg )Nz*<a class="foo bar"></a><a class="foo"></a>r1   rq   r\   zfoo barr   zbar foor   r-   )r   r   r1   a2s       r   :test_find_all_with_string_for_attrs_finds_multiple_classesQTestFindAllByAttribute.test_find_all_with_string_for_attrs_finds_multiple_classes=  s    yyEFc"w1c511ws-DMM#u--s sdmmC	m::::sdmmC3333T]]3	2222r   c                     U R                  S5      n[        SS0S9nU R                  UR                  U5      S/5        g )Nzi
                         <a id="first">Match.</a>
                         <a id="second">Non-match.</a>r#   r   r   zMatch.)r   r
   rm   r-   )r   r   strainers      r   'test_find_all_by_attribute_soupstrainer>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainerI  s@    yy : ;  tWo6DMM(3hZ@r   c                 h    U R                  S5      nU R                  UR                  SS S9S/5        g )N<a id="1">ID present.</a>
                            <a>No ID present.</a>
                            <a id="">ID is empty.</a>r1   r"   zNo ID present.rl   r   s     r   $test_find_all_with_missing_attribute;TestFindAllByAttribute.test_find_all_with_missing_attributeQ  s:     yy 9 : 	DMM#$M7:J9KLr   c                 h    U R                  S5      nU R                  UR                  SS9SS/5        g )Nr  Tr"   zID present.zID is empty.rl   r   s     r   $test_find_all_with_defined_attribute;TestFindAllByAttribute.test_find_all_with_defined_attributeY  s9     yy 9 : 	DMMTM2]N4STr   c                     U R                  S5      nSS/nU R                  UR                  SS9U5        U R                  UR                  SS9U5        g )Nz[<a id=1>Unquoted attribute.</a>
                            <a id="1">Quoted attribute.</a>zUnquoted attribute.zQuoted attribute.r   r"   rg   rl   )r   r   expecteds      r   $test_find_all_with_numeric_attribute;TestFindAllByAttribute.test_find_all_with_numeric_attributea  sY    yy ? @ *+>?DMMQM/:DMMSM18<r   c                     U R                  S5      nU R                  UR                  / SQS9SS/5        U R                  UR                  / S9/ 5        g )Nz<a id="1">1</a>
                            <a id="2">2</a>
                            <a id="3">3</a>
                            <a>No ID.</a>)rg   rh   rj   r"   rg   rh   rl   r   s     r   (test_find_all_with_list_attribute_values?TestFindAllByAttribute.test_find_all_with_list_attribute_valuesj  sU     yy - . 	DMM_M=SzJ 	DMMRM0"5r   c                     U R                  S5      nU R                  UR                  [        R                  " S5      S9SS/5        g )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   s     r   5test_find_all_with_regular_expression_attribute_valueLTestFindAllByAttribute.test_find_all_with_regular_expression_attribute_valuev  sB     yy - . 	DMMRZZ-?M@8YBWXr   c                     U R                  S5      nUR                  nU/UR                  SSS9:X  d   e/ UR                  SSS9:X  d   eg )Nz<b>foo</b><b>bar</b><a>foo</a>r1   rq   r   r\   r   r1   r-   r   r   r1   s      r   'test_find_by_name_and_containing_string>TestFindAllByAttribute.test_find_by_name_and_containing_string  sR    yy9:FFsdmmCm6666T]]3u]5555r   c                 p    U R                  S5      nUR                  S5      UR                  SSS9:X  d   eg )Nz"<a>foo</a><a><b><c>foo</c></b></a>r1   rq   r   r  r   s     r   =test_find_by_name_and_containing_string_when_string_is_buriedTTestFindAllByAttribute.test_find_by_name_and_containing_string_when_string_is_buried  s5    yy=>}}S!T]]3u]%EEEEr   c                     U R                  S5      nUR                  nU/UR                  SSS9:X  d   e/ UR                  SSS9:X  d   eg )Nz"<b id="1">foo</b><a id="2">foo</a>r*   rq   )r#   r   r   r\   r  r  s      r   ,test_find_by_attribute_and_containing_stringCTestFindAllByAttribute.test_find_by_attribute_and_containing_string  sR    yy=>FFsdmmqm7777T]]a]6666r   rI   N)rL   rM   rN   rO   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r!  r$  rQ   rI   r   r   r   r      s\    WHX$I(-U
3AMU=
6
Y6F7r   r   c                       \ rS rSrSrS rSrg)
TestSmoothi  zTest Tag.smooth.c                 "   U R                  S5      nUR                  nUR                  S5        UR                  S5        UR                  [        S5      5        UR                  [        S5      5        UR                  S5        U R	                  5       n[        XS5      nUR                  S5        UR                  S	5        UR                  U5        S UR                  R                  L d   eS
[        UR                  5      :X  d   eUR                  5         S[        UR                  5      :X  d   eSUR                  S   :X  d   eSUR                  R                  :X  d   eSUR                  S   :X  d   eSUR                  S   :X  d   eg )Nz<div>a</div>r   r   z	Comment 1z	Comment 2dspanrg   r         abcr   12r   r*   )r   r5   rx   r   default_builderr	   r*  r   r,   contentssmooth)r   r   r5   builderr*  s        r   test_smoothTestSmooth.test_smooth  sG   yy(hh

3

3

7;'(

7;'(

3&&(4&)CC

4 sxx&&&C%%%%

C%%%%
 Q''' sxx&&&
 cll1o---cll1o---r   rI   N)rL   rM   rN   rO   rP   r3  rQ   rI   r   r   r'  r'    s
    &.r   r'  c                       \ rS rSrSrS rSrg)	TestIndexi  zTest Tag.indexc                 0   U R                  S5      nUR                  n[        UR                  5       H  u  p4X2R	                  U5      :X  a  M   e   [
        R                  " [        5         UR	                  S5        S S S 5        g ! , (       d  f       g = f)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   r5   	enumerater0  indexpytestraises
ValueError)r   r   r5   ielements        r   
test_indexTestIndex.test_index  sm    yy & ' hh#CLL1JA		'**** 2]]:&JJqM '&&s   ,B
BrI   N)rL   rM   rN   rO   rP   r?  rQ   rI   r   r   r6  r6    s
    r   r6  c                   X    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rSrg)TestParentOperationsi  z;Test navigation and searching through an element's parents.Nc                 f    U R                  S5      U l        U R                  R                  U l        g )Na<  <ul id="empty"></ul>
                                 <ul id="top">
                                  <ul id="middle">
                                   <ul id="bottom">
                                    <b id="start">Start here</b>
                                   </ul>
                                  </ul>)r   r   r   startr   s    r   r   !TestParentOperations.setup_method  s(    II + ,	 YY[[
r   c                     U R                   R                  S   S:X  d   eU R                   R                  R                  S   S:X  d   eU R                   R                  R                  R                  S   S:X  d   eg )Nr#   bottommiddletop)rD  parentr   s    r   test_parent TestParentOperations.test_parent  sk    zz  &(222zz  ''-999zz  ''..t4===r   c                 n    U R                   R                  S   nUR                  U R                   :X  d   eg )Nr   )r   r0  rJ  )r   top_tags     r   %test_parent_of_top_tag_is_soup_object:TestParentOperations.test_parent_of_top_tag_is_soup_object  s,    ))$$Q'~~***r   c                 :    S U R                   R                  L d   eg N)r   rJ  r   s    r   test_soup_object_has_no_parent3TestParentOperations.test_soup_object_has_no_parent  s    tyy'''''r   c                     U R                  U R                  R                  S5      / SQ5        U R                  U R                  R                  SSS9S/5        U R                  R                  SS9/ :X  d   eg )NulrG  rH  rI  rH  r"   rD  )assert_selects_idsrD  find_parentsr   s    r   test_find_parents&TestParentOperations.test_find_parents  sm    JJ##D)+F	
 	

 7 7 7 JXJWzz&&'&2b888r   c                     U R                   R                  SSS9S   S:X  d   eU R                   R                  SS9b   eg )NrV  rI  r"   r#   rD  )rD  find_parentr   s    r   test_find_parent%TestParentOperations.test_find_parent  sG    zz%%du%5d;uDDDzz%%%1999r   c                 n    U R                   R                  SS9nUR                  R                  S:X  d   eg )N
Start herer   r   )r   r   rJ  r8   r   r%   s     r   test_parent_of_text_element0TestParentOperations.test_parent_of_text_element  s.    yy~~\~2{{3&&&r   c                 j    U R                   R                  SS9nUR                  S5      S   S:X  d   eg )Nra  r   rV  r#   rG  )r   r   r]  rb  s     r   test_text_element_find_parent2TestParentOperations.test_text_element_find_parent  s4    yy~~\~2%d+x777r   c                     U R                   R                   Vs/ s H  nUc  M  SUR                  ;   d  M  US   PM!     nnU/ SQ:X  d   eg s  snf )Nr#   rW  )rD  parentsr   )r   rJ  ri  s      r   test_parent_generator*TestParentOperations.test_parent_generator  s^     **,,
, &*fll&: F4L, 	 

 5555
   AA	Ac                     U R                   R                   Vs/ s H  nUc  M  SUR                  ;   d  M  US   PM!     nnU/ SQ:X  d   eg s  snf )Nr#   )rD  rG  rH  rI  )rD  self_and_parentsr   )r   rJ  resultss      r   test_self_and_parent_generator3TestParentOperations.test_self_and_parent_generator  s^     **55
5 &*fll&: F4L5 	 

 >>>>
rl  )rD  r   r   )rL   rM   rN   rO   rP   r   rK  rO  rS  rZ  r^  rc  rf  rj  rp  rQ   rI   r   r   rB  rB    s7    E!>
+(9:'86?r   rB  c                       \ rS rSrSS jrSrg)ProximityTesti  Nc                 0    U R                  S5      U l        g )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>r   r   s    r   r   ProximityTest.setup_method  s    II P
	r   r   r   rL   rM   rN   rO   r   rQ   rI   r   r   rs  rs    s    
r   rs  c                   V   ^  \ rS rSrSU 4S jjrS rS rS rS rS r	S r
S	 rS
rU =r$ )TestNextOperationsi  c                 `   > [         [        U ]  5         U R                  R                  U l        g rR  )superrx  r   r   r   rD  r   	__class__s    r   r   TestNextOperations.setup_method  s      $46YY[[
r   c                     U R                   R                  S:X  d   eU R                   R                  R                  S   S:X  d   eg )NOner#   r   )rD  next_elementr   s    r   	test_nextTestNextOperations.test_next   s=    zz&&%///zz&&33D9S@@@r   c                 T    U R                   R                  SS9nUR                  b   eg NThreer   )r   r   r  )r   lasts     r   test_next_of_last_item_is_none1TestNextOperations.test_next_of_last_item_is_none$  s(    yy~~W~-  (((r   c                 6    U R                   R                  b   eg rR  )r   r  r   s    r   test_next_of_root_is_none,TestNextOperations.test_next_of_root_is_none(  s    yy%%---r   c                     U R                  U R                  R                  S5      SS/5        U R                  R                  SS9  U R                  U R                  R                  SS9S/5        g )Nr   Twor  rd   r"   )rm   rD  find_all_nextr   s    r   test_find_all_next%TestNextOperations.test_find_all_next,  s_    DJJ44S9E7;KL

  A &DJJ444:WIFr   c                     U R                   R                  S5      S   S:X  d   eU R                   R                  SS9S:X  d   eg )Nr   r#   r   r  r   )rD  	find_nextr   s    r   test_find_next!TestNextOperations.test_find_next1  sD    zz##C(.#555zz##7#3w>>>r   c                     U R                   R                  SS9nUR                  S5      R                  S:X  d   eU R	                  UR                  S5      SS/5        g )Nr  r   r   r  r  )r   r   r  r   rm   r  rb  s     r   test_find_next_for_text_element2TestNextOperations.test_find_next_for_text_element5  sS    yy~~U~+~~c"))U222D..s3eW5EFr   c                    U R                   R                  SS9nUR                   Vs/ s H  o"PM     nnUu  pEUS   S:X  d   eUS:X  d   eUR                   Vs/ s H  o"PM     nnUSS  U:X  d   eUS   U:X  d   eg s  snf s  snf )Nr  r   r#   rh   r  r   r   )r   r   next_elementsself_and_next_elements)r   rD  node
successorsr   r0  successors2s          r   test_next_generators'TestNextOperations.test_next_generators:  s    		e,',':':;':td':
;"4yC7"""(-(D(DE(Dt(DE12*,,,1~&&& < Fs   A>BrD  r   )rL   rM   rN   rO   r   r  r  r  r  r  r  r  rQ   __classcell__r|  s   @r   rx  rx    s3    !A).G
?G

' 
'r   rx  c                   V   ^  \ rS rSrSU 4S jjrS rS rS rS rS r	S r
S	 rS
rU =r$ )TestPreviousOperationsiG  c                 f   > [         [        U ]  5         U R                  R	                  SS9U l        g r  )rz  r  r   r   r   endr{  s    r   r   #TestPreviousOperations.setup_methodH  s'    $d8:99>>>1r   c                     U R                   R                  S   S:X  d   eU R                   R                  R                  S:X  d   eg )Nr#   rh   r  )r  previous_elementr   s    r   test_previous$TestPreviousOperations.test_previousL  s=    xx((.#555xx((99UBBBr   c                 X    U R                   R                  S5      nUR                  b   eg )Nhtml)r   r   r  )r   r   s     r   #test_previous_of_first_item_is_none:TestPreviousOperations.test_previous_of_first_item_is_noneP  s&    		v&%%---r   c                 6    U R                   R                  b   eg rR  )r   r  r   s    r   test_previous_of_root_is_none4TestPreviousOperations.test_previous_of_root_is_noneT  s    yy))111r   c                     U R                  U R                  R                  S5      / SQ5        U R                  U R                  R                  SS9S/5        g )Nr   r  r  r  r   r"   r  )rm   r  find_all_previousr   s    r   test_find_all_previous-TestPreviousOperations.test_find_all_previousX  sH     	DHH66s;=TUDHH66!6<ugFr   c                     U R                   R                  S5      S   S:X  d   eU R                   R                  SS9S:X  d   eg )Nr   r#   rh   r  r   )r  find_previousr   s    r   test_find_previous)TestPreviousOperations.test_find_previous_  sD    xx%%c*40C777xx%%U%3u<<<r   c                     U R                   R                  SS9nUR                  S5      R                  S:X  d   eU R	                  UR                  S5      / SQ5        g )Nr  r   r   r  )r   r   r  r   rm   r  rb  s     r   #test_find_previous_for_text_element:TestPreviousOperations.test_find_previous_for_text_elementc  sQ    yy~~W~-!!#&--888D22379PQr   c                     U R                   R                  SSS9nU R                  UR                  / SQ5        U R                  UR                  / SQ5        g )Nr   r  r   )bodytagheadtagrD  )rg   r  r  rD  )r   r   rX  previous_elementsself_and_previous_elements)r   rD  s     r   test_previous_generators/TestPreviousOperations.test_previous_generatorsh  sF    		s51 7 79XY @ @Bfgr   r  r   )rL   rM   rN   rO   r   r  r  r  r  r  r  r  rQ   r  r  s   @r   r  r  G  s5    2C.2G=R
h hr   r  c                       \ rS rSrSS jrSrg)SiblingTestin  Nc                     Sn[         R                  " S5      R                  SU5      nU R                  U5      U l        g )Na  <html>
                    <span id="1">
                     <span id="1.1"></span>
                    </span>
                    <span id="2">
                     <span id="2.1"></span>
                    </span>
                    <span id="3">
                     <span id="3.1"></span>
                    </span>
                    <span id="4"></span>
                    </html>z\n\s* )r_   r`   subr   r   )r   markups     r   r   SiblingTest.setup_methodo  s6     H%))"f5IIf%	r   r   r   rv  rI   r   r   r  r  n  s    &r   r  c                   V   ^  \ rS rSrSU 4S jjrS rS rS rS rS r	S r
S	 rS
rU =r$ )TestNextSiblingi  c                 f   > [         [        U ]  5         U R                  R	                  SS9U l        g )Nrg   r"   )rz  r  r   r   r   rD  r{  s    r   r   TestNextSibling.setup_method  s&    ot13YY^^s^+
r   c                 6    U R                   R                  b   eg rR  )r   next_siblingr   s    r   !test_next_sibling_of_root_is_none1TestNextSibling.test_next_sibling_of_root_is_none  s    yy%%---r   c                     U R                   R                  S   S:X  d   eU R                   R                  R                  S   S:X  d   eU R                   R                  S   S:X  d   eg )Nr#   r   rh   1.1)rD  r  r  r   s    r   test_next_sibling!TestNextSibling.test_next_sibling  sa    zz&&t,333zz&&33D9S@@@ zz&&t,555r   c                     U R                   R                  R                  b   eU R                   R                  SS9nUR                  b   eU R                   R                  SS9nUR                  b   eg )Nr  r"   rj   )r   r  r  r   )r   nested_span	last_spans      r   test_next_sibling_may_not_exist/TestNextSibling.test_next_sibling_may_not_exist  sh    yy~~**222iinnn.''///IINNcN*	%%---r   c                 L    U R                   R                  S5      S   S:X  d   eg )Nr*  r#   r   )rD  r:   r   s    r   test_find_next_sibling&TestNextSibling.test_find_next_sibling  s$    zz++F3D9S@@@r   c                     U R                  U R                  R                  S5      / SQ5        U R                  U R                  R                  SS9S/5        g )Nr*  r   rh   rj   rh   r"   )rX  rD  rX   r   s    r   test_next_siblings"TestNextSibling.test_next_siblings  sE    

 = =f EW

 = = = EuMr   c                     U R                  U R                  R                  / SQ5        U R                  U R                  R                  / SQ5        g )Nr  )rg   r   rh   rj   )rX  rD  next_siblingsself_and_next_siblingsr   s    r   test_next_siblings_generators-TestNextSibling.test_next_siblings_generators  s7    

 8 8/J

 A ACWXr   c                 F   U R                  S5      nUR                  SS9nUR                  R                  S:X  d   eUR                  R                  S:X  d   eU R	                  UR                  S5      S/5        UR                  SS9S:X  d   eUR                  SS9b   eg )NFoo<b>bar</b>bazr]   r   r   bazr\   nonesuch)r   r   r  r8   rm   rX   r:   r   r   rD  s      r   "test_next_sibling_for_text_element2TestNextSibling.test_next_sibling_for_text_element  s    yy+,			'!!&&#---!!..%777E44S9E7C&&e&4===&&j&9AAAr   r  r   )rL   rM   rN   rO   r   r  r  r  r  r  r  r  rQ   r  r  s   @r   r  r    s5    ,.6.AN
YB Br   r  c                   V   ^  \ rS rSrSU 4S jjrS rS rS rS rS r	S r
S	 rS
rU =r$ )TestPreviousSiblingi  c                 f   > [         [        U ]  5         U R                  R	                  SS9U l        g )Nrj   r"   )rz  r  r   r   r   r  r{  s    r   r    TestPreviousSibling.setup_method  s'    !45799>>S>)r   c                 6    U R                   R                  b   eg rR  )r   previous_siblingr   s    r   %test_previous_sibling_of_root_is_none9TestPreviousSibling.test_previous_sibling_of_root_is_none  s    yy))111r   c                     U R                   R                  S   S:X  d   eU R                   R                  R                  S   S:X  d   eU R                   R                  S   S:X  d   eg )Nr#   rh   r   z3.1)r  r  r  r   s    r   test_previous_sibling)TestPreviousSibling.test_previous_sibling  sa    xx((.#555xx((99$?3FFF xx((.%777r   c                     U R                   R                  R                  b   eU R                   R                  SS9nUR                  b   eU R                   R                  SS9nUR                  b   eg )Nr  r"   rg   )r   r  r  r   )r   r  
first_spans      r   #test_previous_sibling_may_not_exist7TestPreviousSibling.test_previous_sibling_may_not_exist  sh    yy~~..666iinnn.++333YY^^s^+
**222r   c                 L    U R                   R                  S5      S   S:X  d   eg )Nr*  r#   rh   )r  r9   r   s    r   test_find_previous_sibling.TestPreviousSibling.test_find_previous_sibling  s$    xx--f5d;sBBBr   c                     U R                  U R                  R                  S5      / SQ5        U R                  U R                  R                  SS9S/5        g )Nr*  rh   r   rg   rg   r"   )rX  r  rW   r   s    r   test_previous_siblings*TestPreviousSibling.test_previous_siblings  sJ    HH++F3_	
 	 ? ?3 ? G#Or   c                     U R                  U R                  R                  / SQ5        U R                  U R                  R                  / SQ5        g )Nr  )rj   rh   r   rg   )rX  r  previous_siblingsself_and_previous_siblingsr   s    r   !test_previous_siblings_generators5TestPreviousSibling.test_previous_siblings_generators  s7     : :OL C CEYZr   c                 F   U R                  S5      nUR                  SS9nUR                  R                  S:X  d   eUR                  R                  S:X  d   eU R	                  UR                  S5      S/5        UR                  SS9S:X  d   eUR                  SS9b   eg )Nr  r  r   r   r]   r\   r  )r   r   r  r8   rm   rW   r9   r  s      r   &test_previous_sibling_for_text_element:TestPreviousSibling.test_previous_sibling_for_text_element  s    yy+,			'%%**c111%%66%???E88=wG**%*8EAAA****=EEEr   r  r   )rL   rM   rN   rO   r   r  r  r  r  r  r  r  rQ   r  r  s   @r   r  r    s5    *283CP[F Fr   r  c                   (   \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS r\R6                  R9                  SS S /5      S 5       r\R6                  R9                  SS S/S S /45      S! 5       rS" rS# r S$ r!S% r"S& r#S' r$S( r%S) r&S* r'S+ r(S, r)S- r*S. r+S/ r,S0 r-S1 r.S2 r/S3 r0S4 r1S5 r2S6 r3S7 r4S8 r5\R6                  R9                  S9/ S:Q5      S; 5       r6S< r7S= r8S> r9S? r:S@ r;SAr<gB)CTestTreeModificationi  c                 Z   U R                  S5      nSUR                  S'   UR                  5       U R                  S5      :X  d   eUR                  S	 UR                  5       U R                  S5      :X  d   eSUR                  S'   UR                  5       U R                  S5      :X  d   eg )	Nz<a id="1"></a>r*   r#   z<a id="2"></a>ru   rq   id2z<a id2="foo"></a>)r   r1   r   document_forr   s     r   test_attribute_modification0TestTreeModification.test_attribute_modification  s    yy)*t{{} 1 12B CCCCFF4L{{} 1 1) <<<<u{{} 1 12E FFFFr   c                 D   [         R                  " S5      " 5       nU R                  SUS9n[        X!S5      n[        X!S5      nSUS'   UR                  R                  SU5        UR                  R                  S	U5        UR                  R                  5       S
:X  d   eg )Nr  z<body></body>r2  r1   olzhttp://foo.com/hrefr   r   s4   <body><a href="http://foo.com/"></a><ol></ol></body>)r   lookupr   r	   rV   insertr   )r   r2  r   r1   r  s        r   test_new_tag_creation*TestTreeModification.test_new_tag_creation  s    "))&13yy'y:s#%%&			A		BIIFG	
Gr   c                    SnU R                  U5      nUR                  SS9nUR                  nUR                  SS9R                  UR                  5        UR                  U:X  d   eUR                  5       U R                  S5      :X  d   eg )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   rJ  r   r  )r   docr   second_parabolds        r   !test_append_to_contents_moves_tag6TestTreeModification.test_append_to_contents_moves_tag  s    /yy~ii3i'vv 			S	  ( {{k))){{} 1 1X!
 
 	
 
r   c                    U R                  S5      nUR                  S5      nUR                  UR                  S5      5      nUR                  S:X  d   eUR                  SUR                  S5      5      u  nUR                  S:X  d   eUR                  S5      nUS:X  d   eUR                  SS5      nUSS/:X  d   eUR                  S	S
5      nUS	S
/:X  d   eUR                  SS/5      nUSS/:X  d   eUR                  5       S:X  d   eg )Nz<html></html>r  headr   r   rk   rh   rj   67893456789)
r   r   rx   new_tagr8   r  insert_beforeinsert_afterextendget_text)	r   r   r  r&  r   text5text34text67text89s	            r   &test_insertion_returns_inserted_things;TestTreeModification.test_insertion_returns_inserted_things
  s   yy)yy {{4<</0yyF"""++ag!67zzW$$$S!||$$S#.#s#####C-#s###sCj)#s###~~9,,,r   c                     SnU R                  U5      nUR                  nUR                  UR                  5      nX4:X  d   eg )Nz<a></a><b><c></c></b>)r   r1   replace_withr   r   r%   r   r1   new_as        r   1test_replace_with_returns_thing_that_was_replacedFTestTreeModification.test_replace_with_returns_thing_that_was_replaced  s9    &yyFFtvv&zzr   c                 p    SnU R                  U5      nUR                  nUR                  5       nX4:X  d   eg )N<a><b></b><c></c></a>)r   r1   unwrapr9  s        r   +test_unwrap_returns_thing_that_was_replaced@TestTreeModification.test_unwrap_returns_thing_that_was_replaced$  s2    &yyFF
zzr   c                    U R                  S5      nUR                  nUR                  5         S UR                  L d   e[        R
                  " [        5         UR                  5         S S S 5        [        R
                  " [        5         UR                  UR                  5        S S S 5        g ! , (       d  f       NM= f! , (       d  f       g = f)Nz<a><b>Foo</b></a><c>Bar</c>)
r   r1   extractrJ  r:  r;  r<  r?  r8  r   r  s      r   Itest_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parent^TestTreeModification.test_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parent+  s    yy67FF			qxx]]:&HHJ ']]:&NN466" '& '&&&s   B1C1
B?
Cc                     SnU R                  U5      nUR                  nUR                  R                  U5      nXC:X  d   eUR                  5       U R	                  U5      :X  d   eg )Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)r   r   r8  r   r  )r   r%   r   r   r   s        r   test_replace_tag_with_itself1TestTreeModification.test_replace_tag_with_itself5  sZ    >yyFF$$Q'{{{{} 1 1$ 7777r   c                     SnU R                  U5      n[        R                  " [        5         UR                  R                  UR                  5        S S S 5        g ! , (       d  f       g = fN<a><b></b></a>)r   r:  r;  r<  r   r8  r1   r   r%   r   s      r   1test_replace_tag_with_its_parent_raises_exceptionFTestTreeModification.test_replace_tag_with_its_parent_raises_exception=  sB    yy]]:&FF' '&&s   &A
A+c                     SnU R                  U5      n[        R                  " [        5         UR                  R                  SUR                  5        S S S 5        g ! , (       d  f       g = f)NrK  r   )r   r:  r;  r<  r1   r  rL  s      r   ,test_insert_tag_into_itself_raises_exceptionATestTreeModification.test_insert_tag_into_itself_raises_exceptionC  sB    yy]]:&FFMM!TVV$ '&&s   'A
A,c           	         U R                  S5      nUR                  SUR                  SSS9UR                  SSS95      u  p#SUR                  :X  d   eSUR                  :X  d   e[	        UR
                  5      u  pBp5SUR                  :X  d   eSUR                  :X  d   eSUR                  :X  d   eSUR                  :X  d   eg )	N-<p>And now, a word:</p><p>And we're back.</p>r   r6   p2r   p3And now, a word:And we're back.)r   r  r,  r   listchildren)r   r   rT  rU  p1p4s         r   test_insert_multiple_elements2TestTreeModification.test_insert_multiple_elementsI  s    yyHIQS >SY]@^_ryy   ryy   dmm,!RYY...ryy   ryy    BII---r   c                    U R                  S5      nSnU R                  U5      nUR                  SU5      u  pESUR                  :X  d   eSUR                  :X  d   eUR                   H  n[	        U[
        5      (       d  M   e   [        UR                  5      u  ptpXSUR                  :X  d   eSUR                  :X  d   eSUR                  :X  d   eSUR                  :X  d   eg)	zInserting one BeautifulSoup object into another actually inserts all
of its children -- you'll never combine BeautifulSoup objects.
rS  z<p>p2</p><p>p3</p>r   rT  rU  rV  rW  N)r   r  r   descendants
isinstancer   rX  rY  )	r   r   r%   	to_insertrT  rU  r=  rZ  r[  s	            r   1test_insert_beautifulsoup_object_inserts_childrenFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrenU  s     yyHI#IIdO	Q	*ryy   ryy   !!A!!]3333 " dmm,!RYY...ryy   ryy    BII---r   c                     U R                  S5      nUR                  nUR                  SS5        UR                  u  p4UR	                  S5        UR	                  S5        SUR
                  R                  :X  d   eg )Nz<p><a>one</a><b>three</b></p>r   twor  three)r   r1   r  r0  r8  r   r   )r   r   r1   leftrights        r   3test_replace_with_maintains_next_element_throughoutHTestTreeModification.test_replace_with_maintains_next_element_throughoutj  si    yy89FF	E jj"2 $&&--'''r   c                 6   U R                  S5      nUR                  SS9R                  S5        UR                  SS9nUR                  nUR                  U:X  d   eUR
                  U:X  d   eUR                  R                  U:X  d   eUR                  b   eg )Nz<b>Argh!</b>Argh!r   Hooray!)r   r   r8  r   r  rJ  r  )r   r   new_textr   s       r   test_replace_final_node,TestTreeModification.test_replace_final_nodex  s    yy(			!..y999I9.FF((A---!###((55AAA$$,,,r   c                    U R                  S5      nUR                  R                  SS5        UR                  5       U R	                  S5      :X  d   eUR                  SS9nUR                  S:X  d   eUR                  R                  U:X  d   eUR                  S:X  d   eUR                  R                  U:X  d   eUR                  b   eUR                  UR                  :X  d   eg )Nz<a><b>Argh!</b><c></c></a>r   rm  z!<a><b>Argh!Hooray!</b><c></c></a>r   rl  )r   r   r  r   r  r   r  r  r  r  r   )r   r   rn  s      r   test_consecutive_text_nodes0TestTreeModification.test_consecutive_text_nodes  s     yy56a#{{} 1 12U VVVV99I9.((G333((55AAA((G333((55AAA$$,,,$$...r   c                 $   U R                  S5      nUR                  R                  SS5        UR                  R                  SS5        SS/UR                  R                  :X  d   eUR                  R                  S   R                  S:X  d   eg )Nru   r   r\   rq   )r   r1   r  r0  r  r   s     r   test_insert_string'TestTreeModification.test_insert_string  so    yy#aau~000vvq!..%777r   c                     U R                  S5      nUR                  R                  S5      nUS:X  d   eUR                  R                  5       S:X  d   eg )Nz<b>1</b>r   z	<b>12</b>)r   r   rx   r   r   s      r   test_append TestTreeModification.test_append  sF    yy$s#}}vv}}+---r   c                    U R                  5       nU R                  SUS9n[        X!S5      nUR                  SS5        UR                  R                  SU5        UR                  5       U R                  S5      :X  d   eUR                  nUR                  U:X  d   eUR                  U:X  d   eUR                  SS	9nUR                  U:X  d   eUR                  U:X  d   eUR                  nUR                  U:X  d   eUR                  U:X  d   eUR                  SS	9nUR                  U:X  d   eUR                  U:X  d   eUR                  U:X  d   eg )
Nz%<a><b>Find</b><c>lady!</c><d></d></a>r  magictagr   ther   z=<a><b>Find</b><magictag>the</magictag><c>lady!</c><d></d></a>Findr   )r/  r   r	   r  r1   r   r  r   r  r  r   r  r  r   rJ  )r   r2  r   	magic_tagb_tagr   c_tagr|  s           r   test_insert_tag$TestTreeModification.test_insert_tag  s_   &&(yy@'yRz2	E"a#{{} 1 1K!
 
 	
 

 !!Y...))U222zzz(  I---))T111%%...%%222nnEn*zzY&&&5(((%%,,,r   c                     SnU R                  U5      nUR                  R                  SUR                  5        XR	                  5       :X  d   eg )Nz<a>b<c></c>d</a>r   )r   r1   r  r   r   r   r   r   s      r   %test_insert_into_the_current_location:TestTreeModification.test_insert_into_the_current_location  s<    !yya {{}$$$r   c                     SnU R                  U5      nUR                  R                  UR                  5        XR	                  5       :X  d   eg rJ  )r   r1   rx   r   r   r  s      r   *test_append_child_thats_already_at_the_end?TestTreeModification.test_append_child_thats_already_at_the_end  s:    yydff{{}$$$r   c                    SnU R                  U5      nUR                  UR                  UR                  UR                  UR
                  UR                  /nUR                  R                  U5        SUR                  5       :X  d   eg )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   r1   r/  r   r   r   r   elementss       r   #test_extend_with_a_list_of_elements8TestTreeModification.test_extend_with_a_list_of_elements  sb    ByyFFDFFDFFDFFDFFDFFChBdkkmSSSr   c                     SnU R                  U5      nSS[        S5      S/nUR                  R                  U5        SUR	                  5       :X  d   eg )Nru   r   r   r)  r  z<a>bcde</a>)r   r   r1   r/  r   r  s       r   "test_extend_with_a_list_of_strings7TestTreeModification.test_extend_with_a_list_of_strings  sK    yyoc2C8h---r   get_tagsc                     U $ rR  rI   r   s    r   rF   TestTreeModification.<lambda>  s    cr   c                     U R                   $ rR  )r0  r   s    r   rF   r    s    s||r   c                     SnU R                  U5      nUR                  SSS9nUR                  SSS9nU" U5      nUR                  U5        SUR                  5       :X  d   eSUR                  5       :X  d   eg )NzS<body><div id="d1"><a>1</a><a>2</a><a>3</a><a>4</a></div><div id="d2"></div></body>r5   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  tagss          r   &test_extend_with_another_tags_contents;TestTreeModification.test_extend_with_another_tags_contents  st    dyyYYuY&YYuY&|
		$$		333D		SSSr   zstring_source,resultc                 .    U R                   R                  $ rR  )r1   r   r   s    r   rF   r    s    $&&--r   z<a></a><b>1</b>c                     g)NabcderI   r  s    r   rF   r    s    'r   z<a>1</a><b>abcde</b>c                 |   SnU R                  U5      n[        R                  " SS9 nU" U5      nUR                  R	                  U5        UR
                  R                  5       U:X  d   eUu  nUR                  [        :X  d   e[        UR                  5      nUS:X  d   e S S S 5        g ! , (       d  f       g = f)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/  r5   decode_contentsr{   r|   r$   r}   )	r   string_sourcer   r   r   r   r   r   r   s	            r   )test_extend_with_a_single_non_tag_element>TestTreeModification.test_extend_with_a_single_non_tag_element  s     ,yy$$D1Q"4(FFFMM&!88++-777IW##x///goo&C^__ 211s   A;B--
B;c                     SnU R                  U5      nUR                  R                  SUR                  5        SUR	                  5       :X  d   eg )Nz<a><b></b><c></c><d></d></a>r   z<a><d></d><b></b><c></c></a>)r   r1   r  r)  r   r  s      r   $test_move_tag_to_beginning_of_parent9TestTreeModification.test_move_tag_to_beginning_of_parent  s>    -yya ->>>r   c                     U R                  S5      nUR                  R                  SS5        [        UR                  5      S:X  d   eg )Nz<br/>r   Contentsz<br>Contents</br>)r   brr  r$   r   s     r   &test_insert_works_on_empty_element_tag;TestTreeModification.test_insert_works_on_empty_element_tag  s;    
 yy!q*%477|2222r   c                 2   U R                  S5      nUR                  R                  S5        UR                  R                  S5        UR	                  5       U R                  S5      :X  d   eUR                  R                  UR                  5        UR	                  5       U R                  S5      :X  d   eUR                  n[        R                  " [        5         UR                  U5        S S S 5        UR                  5         [        R                  " [        5         UR                  S5        S S S 5        U R                  S5      nUR                  R                  UR                  S5      5        g ! , (       d  f       N= f! , (       d  f       N[= f)	Nr)   BAZQUUXzQUUX<a>foo</a>BAZ<b>bar</b>QUUX<b>bar</b><a>foo</a>BAZnope<a>r1   )r   r   r-  r1   r   r  r:  r;  r<  rC  r,  r   r   r   s      r   test_insert_before'TestTreeModification.test_insert_before  s   yy/0U#V${{} 1 12O PPPPTVV${{} 1 12O PPPP FF]]:&OOA ' 	
		]]:&OOF# ' yyT\\#./ '&
 '&   E7!F7
F
Fc                 z   U R                  S5      nUR                  R                  SSS5        UR                  R                  SSS5        UR	                  5       U R                  S5      :X  d   eUR                  R                  UR                  S5        UR	                  5       U R                  S5      :X  d   eg )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-  r1   r   r  r   s     r   test_insert_multiple_before0TestTreeModification.test_insert_multiple_before$  s    yy/0UC0VS%0{{} 1 12!
 
 	
 
 	TVVU+{{} 1 15!
 
 	
 
r   c                 2   U R                  S5      nUR                  R                  S5        UR                  R                  S5        UR	                  5       U R                  S5      :X  d   eUR                  R                  UR                  5        UR	                  5       U R                  S5      :X  d   eUR                  n[        R                  " [        5         UR                  U5        S S S 5        UR                  5         [        R                  " [        5         UR                  S5        S S S 5        U R                  S5      nUR                  R                  UR                  S5      5        g ! , (       d  f       N= f! , (       d  f       N[= f)	Nr)   r  r  z<a>foo</a>QUUX<b>bar</b>BAZr  r  r  r1   )r   r   r.  r1   r   r  r:  r;  r<  rC  r-  r,  r  s      r   test_insert_after&TestTreeModification.test_insert_after1  s   yy/0E"F#{{} 1 12O PPPPDFF#{{} 1 12O PPPP FF]]:&NN1 ' 	
		]]:&NN6" ' yyT\\#./ '&
 '&r  c                 z   U R                  S5      nUR                  R                  SSS5        UR                  R                  SSS5        UR	                  5       U R                  S5      :X  d   eUR                  R                  UR                  S5        UR	                  5       U R                  S5      :X  d   eg )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.  r1   r   r  r   s     r   test_insert_multiple_after/TestTreeModification.test_insert_multiple_afterI  s    yy/0E3/FC/{{} 1 12!
 
 	
 
 	DFFF+{{} 1 16!
 
 	
 
r   c                    U R                  S5      nUR                  S5      nUR                  S5      n[        R                  " [
        5         UR                  U5        S S S 5        [        R                  " [        5         UR                  U5        S S S 5        [        R                  " [
        5         UR                  U5        S S S 5        g ! , (       d  f       Nw= f! , (       d  f       NT= f! , (       d  f       g = fNr  r1   )r   r,  
new_stringr:  r;  r<  r.  NotImplementedErrorr   r   r   r   s       r   :test_insert_after_raises_exception_if_after_has_no_meaningOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningU  s    yy}ll3$]]:&$ ']]./c" 0]]:&S! '&	 '&//&&$   CC"6C3
C"
C03
Dc                    U R                  S5      nUR                  S5      nUR                  S5      n[        R                  " [
        5         UR                  U5        S S S 5        [        R                  " [        5         UR                  U5        S S S 5        [        R                  " [
        5         UR                  U5        S S S 5        g ! , (       d  f       Nw= f! , (       d  f       NT= f! , (       d  f       g = fr  )r   r,  r  r:  r;  r<  r-  r  r  s       r   Ftest_insert_before_raises_notimplementederror_if_before_has_no_meaning[TestTreeModification.test_insert_before_raises_notimplementederror_if_before_has_no_meaning`  s    yy}ll3$]]:&  % ']]./s# 0]]:&c" '&	 '&//&&r  c                 V   U R                  S5      nUR                  S5      u  p#UR                  U5        UR                  5       U R	                  S5      :X  d   eUR
                  b   eUR
                  UR                  :X  d   eUR                  S:X  d   eUR                  S:X  d   eg )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-   r8  r   r  rJ  r6   r  r  )r   r   r  shows       r   test_replace_with&TestTreeModification.test_replace_withk  s    yyVW==%"{{} 1 1>!
 
 	
 
 {{"""yyDFF"""$&&&+---r   c                    [        SS9n[        R                  " [        5         UR	                  S5        S S S 5        U R                  S5      R                  n[        R                  " [        5         UR                  R	                  U5        S S S 5        [        R                  " [        5         UR                  R	                  SUS5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N`= f! , (       d  f       g = f)Nr1   rC   z
won't workrK  string1string2)r	   r:  r;  r<  r8  r   r1   r   )r   a_tags     r   test_replace_with_errors-TestTreeModification.test_replace_with_errorsx  s    ]]:&|, ' 		*+--]]:&GG  ' ' ]]:&GG  E9= '& '&
 '& '&s#   C3C)1C:
C&)
C7:
Dc                    SnU R                  U5      nUR                  S5      nSUl        UR                  S5      nUR                  S5      nSnUR                  R	                  X4Xe5        UR                  5       S:X  d   eUR                  R                  U:X  d   eUR                  R                  U:X  d   eUR                  R                  U:X  d   eUR                  R                  U:X  d   eg )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   r8  r   r   r  )r   r   r   d_tage_tagf_taga_strings          r   test_replace_with_multiple/TestTreeModification.test_replace_with_multiple  s    &yyS!&S!S! E(:KKMLM	
M vv""e+++||((E111!!((H444!!..%777r   c                     SnU R                  U5      nUR                  R                  UR                  5        SUR	                  5       :X  d   eg )Nr>  z<a><c></c></a>)r   r   r8  r   r   r  s      r   test_replace_first_child-TestTreeModification.test_replace_first_child  >    &yyDFF#4;;=000r   c                     SnU R                  U5      nUR                  R                  UR                  5        SUR	                  5       :X  d   eg )Nr>  rK  )r   r   r8  r   r   r  s      r   test_replace_last_child,TestTreeModification.test_replace_last_child  r  r   c                    U R                  S5      nUR                  nUR                  nUR                  U5        UR	                  5       U R                  S5      :X  d   eUR                  b   eUR                  SS9R                  b   eUR                  b   eUR                  b   eUR                  b   eUR                  UR                  :X  d   eUR                  S:X  d   eUR                  R                  UR                  :X  d   eUR                  b   eUR                  SS9nUR                  nUR                  U:X  d   eUR                  U:X  d   eUR                  U:X  d   eUR                  U:X  d   eg )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>rh  r   Weto)r   r   r   r8  r   r  rJ  r   r  r  r  r  r1   r  r  )r   r   
remove_tagmove_tagto_textg_tags         r   test_nested_tag_replace_with1TestTreeModification.test_nested_tag_replace_with  s   yyc
 VV
66){{} 1 1;!
 
 	
 

   (((g.;;CCC**222&&...**222 $&&(((((D000$$11TVV;;;$$,,, ))4)(##u,,,##u,,,%%000%%000r   c                     U R                  S5      nUR                  R                  5         UR                  b   eUR                  R                  S:X  d   eg )NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r   emr?  r6   r%   r   s     r   test_unwrap TestTreeModification.test_unwrap  sJ    yy   	wwvv{{????r   c                     U R                  S5      nUR                  R                  UR                  S5      5      nUR	                  5       S:X  d   eUR	                  5       U R                  S5      :X  d   eg )NzI wish I was bold.r   <b>I wish I was bold.</b>)r   r   wrapr,  r   r  )r   r   r   s      r   	test_wrapTestTreeModification.test_wrap  sc    yy-.  c!23||~!<<<<{{} 1 12M NNNNr   c                     U R                  S5      nUR                  R                  R                  UR                  5        UR	                  5       U R                  S5      :X  d   eg )Nz<b></b>I wish I was bold.r  )r   r   r  r  r   r  r   s     r   %test_wrap_extracts_tag_from_elsewhere:TestTreeModification.test_wrap_extracts_tag_from_elsewhere  sM    yy45  ({{} 1 12M NNNNr   c                    U R                  S5      nUR                  R                  R                  UR                  5        S[	        UR                  R
                  5      :X  d   eUR                  5       U R                  S5      :X  d   eg )Nz+<b>I like being bold.</b>I wish I was bold.r*   z+<b>I like being bold.I wish I was bold.</b>)r   r   r  r  r,   r0  r   r  r   s     r   &test_wrap_puts_new_contents_at_the_end;TestTreeModification.test_wrap_puts_new_contents_at_the_end  sp    yyFG  (C(((({{} 1 19!
 
 	
 
r   c                    U R                  S5      n[        UR                  R                  5      S:X  d   eUR	                  SS9R                  5       nUR                  5       S:X  d   eUR                  5       S:X  d   e[        UR                  R                  5      S:X  d   eUR                  b   eUR                  b   eUR                  R                  b   eUR	                  SS	9nUR	                  S
S	9nUR                  U:X  d   eUR                  U:X  d   eUR                  U:X  d   eUR                  U:X  d   eg )NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>rd   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,   rV   r0  r   rC  r   rJ  r  r  r  r  )r   r   	extracted	content_1	content_2s        r   test_extract!TestTreeModification.test_extract  sG   yy`
 499%%&!+++III'//1	{{} XXXX!%CCCC 499%%&!+++'''))111%%22::: II%5I6	II%5I6	%%222%%222))Y666))Y666r   c                    U R                  S5      nUR                  R                  nUR                  S5      nUR                  S5      nUR                  R	                  U5        UR
                  R	                  U5        UR                  5         UR                  5         X1R                  R                  :X  d   eXAR
                  R                  :X  d   eg )Nr)   rq   r\   )r   r1   r   r  rx   r   rC  )r   r   foo_1foo_2bar_2s        r   4test_extract_distinguishes_between_identical_stringsITestTreeModification.test_extract_distinguishes_between_identical_strings  s    yy/0&&ee
 	%%%%%%r   c                     U R                  S5      nUR                  S5       Vs/ s H  o!R                  R                  5       PM       nS[	        UR
                  5      :X  d   eg s  snf )Nzv
<html>
<head>
<script>foo</script>
</head>
<body>
 <script>bar</script>
 <a></a>
</body>
<script>baz</script>
</html>scriptz<body>

<a></a>
</body>)r   r-   r  rC  r$   rV   )r   r   r=  s      r   "test_extract_multiples_of_same_tag7TestTreeModification.test_extract_multiples_of_same_tag  s[    yy 
 
 )-h(?@(?1			(?@+s499~=== 	As   #A&c                     U R                  S5      nUR                  S5      R                  5         S UR                  S5      L d   eg )Nz<html>
<body>hi</body>
</html>rV   )r   r   rC  r   s     r   Btest_extract_works_when_element_is_surrounded_by_identical_stringsWTestTreeModification.test_extract_works_when_element_is_surrounded_by_identical_strings  s=    yyAB		&!!#tyy((((r   c                 N   U R                  S5      nUR                  nUR                  R                  5         [	        UR                  R
                  5      S:X  d   e[        US5      (       d   eUR                  nUR                  SS9  S[	        UR
                  5      :X  d   eg)zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>r   r0  T)	decomposeN)r   r1   r6   clearr,   r0  r   r  )r   r   r1   r  s       r   
test_clearTestTreeModification.test_clear"  s    yyOPFF466??#q(((q*%%%% TT	$C$$$$r   zmethod_name,expected_result))r_  9<div><em>child1</em><p id="start"></p><p>child3</p></div>)r  zH<div><em>child1</em><p id="start"><a>Second <em>child</em></a></p></div>)r  r  )rY  r  )r  r  )r	  zF<div><p id="start"><a>Second <em>child</em></a></p><p>child3</p></div>)ri  r  c                     U R                  S5      n[        UR                  U5      nU H  nUR                  5         M     X#R	                  5       :X  d   eg )NzU<div><em>child1</em><p id='start'><a>Second <em>child</em></a></p><p>child3</p></div>)r   getattrr6   rC  r   )r   method_nameexpected_resultr   iteratorr=  s         r   test_extract_during_iteration2TestTreeModification.test_extract_during_iteration0  sL    : yyc
 466;/AIIK ++-///r   c                 B   U R                  S5      nUR                  S5      u  p#UR                  nUR                  R                  nX#XE4 H  nSUR
                  L a  M   e   UR                  5         X$U4 H  nSUR
                  L a  M   e   SUR
                  L d   eg )Nz;<p><a>String <em>Italicized</em></a></p><p>Another para</p>r6   FT)r   r-   r1   r  r   
decomposedr  )r   r   rZ  rT  r1   r%   r=  s          r   test_decompose#TestTreeModification.test_decomposeU  s    yyVWs#DDuu||!"AALL((( # 	A1<<'''  %%%r   c                     U R                  S5      nUR                  nUR                  R                  nSUR                  L d   eUR                  5         SUR                  L d   eSUR                  5       :X  d   eg )Nz'<div><p>String 1</p><p>String 2</p></p>FTz!<div><p></p><p>String 2</p></div>)r   r5   r6   r   r"  r  r   )r   r   r5   r%   s       r   test_decompose_string*TestTreeModification.test_decompose_stringe  si    yyBChhuu||'''t&&&2cjjlBBBr   c                     U R                  S5      nSUR                  l        UR                  R                  S/:X  d   eSUR                  l        UR                  R                  S/:X  d   eg)zTag.string = 'string'z<a></a> <b><c></c></b>rq   r\   N)r   r1   r   r0  r   r   s     r   test_string_set$TestTreeModification.test_string_setn  sW    yy12vv5')))vv5')))r   c                     U R                  S5      nUR                  R                  UR                  l        UR                  R                  5       S:X  d   eg )Nz<a><b>foo</b><c>bar</c>s   <a><b>bar</b><c>bar</c></a>)r   r   r   r   r1   r   r   s     r   /test_string_set_does_not_affect_original_stringDTestTreeModification.test_string_set_does_not_affect_original_stringv  s=    yy23vv}}"@@@@r   c                     U R                  S5      n[        S5      nX!R                  l        [	        UR                  R                  [        5      (       d   eg )Nru   rq   )r   r   r1   r   r`  )r   r   cdatas      r   )test_set_string_preserves_class_of_string>TestTreeModification.test_set_string_preserves_class_of_string{  s=    yy#e$&&--////r   rI   N)=rL   rM   rN   rO   r  r  r#  r5  r;  r@  rD  rG  rM  rP  r\  rb  ri  ro  rr  ru  rx  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,  r0  rQ   rI   r   r   r  r    s   G

"-&#8(%
..*(-/&8.-:%%T. [[Z/;S)TUT VT [['):;!#9:	
?302
00

	"	#.>8$11#1J@OO

72& >)
% [[%	
2
032
0& C*A
0r   r  )r   r-   r]  rY  r  r  r  r  r:   rX   r9   rW   c                   X    \ rS rSr\R
                  R                  S\5      S 5       rSr	g)TestDeprecatedArgumentsi  r  c                 *   U R                  S5      n[        UR                  U5      n[        R                  " SS9 nU" SS9  Uu  nUR
                  [        :X  d   e[        UR                  5      nUS:X  d   e S S S 5        g ! , (       d  f       g = f)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   r   s          r   test_find_type_method_string4TestDeprecatedArguments.test_find_type_method_string  s    yy34-$$D1Q!IW##x///goo&Cdee 211s   >B
BrI   N)
rL   rM   rN   rO   r:  r2  r3  all_find_type_methodsr:  rQ   rI   r   r   r5  r5    s'    [[],AB Cr   r5  c                   X    \ rS rSr\R
                  R                  S\5      S 5       rSr	g)TestWarningsi  r  c                 l   U R                  S5      n[        UR                  U5      n[        R                  " SS9 nU" SS9  Uu  nUR
                  [        :X  d   e[        UR                  [        5      (       d   e[        UR                  5      nSU;   d   e S S S 5        g ! , (       d  f       g = f)Nr7  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$   r8  s          r   test_suspicious_syntax_warning+TestWarnings.test_suspicious_syntax_warning  s    yy34-$$D1Q#IW##x///goo/PQQQQgoo&C` 211s   AB%%
B3rI   N)
rL   rM   rN   rO   r:  r2  r3  r<  rB  rQ   rI   r   r   r>  r>    s'    [[],AB Cr   r>  )$rP   r:  r_   ry   bs4r   bs4.builderr   bs4.elementr   r   r   r   r	   
bs4.filterr
   r  r   r   rS   r   r   r   r'  r6  rB  rs  rx  r  r  r  r  r  r<  r5  r>  rI   r   r   <module>rH     s    	   (  $
*6x *6XC)( C)L@ @M  M `k7X k7\). ).X (<?8 <?~
H 
)' )'X$h] $hN&( &(,Bk ,B^.F+ .Fb]
08 ]
0@  h  8 r   