
    h"                        d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZ  G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z g d'Z! G d( d)e      Z" G d* d+e      Z#y),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                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestFindz&Basic tests of the find() method.
    c                 f    | j                  d      }|j                  d      j                  dk(  sJ y )Nz <a>1</a><b>2</b><a>3</a><b>4</b>b2)soupfindstringselfr   s     {/var/labsstorage/home/kalaiyarasan.offl.2004/htdocs/course/socket/myenv/lib/python3.12/site-packages/bs4/tests/test_tree.pytest_find_tagzTestFind.test_find_tag"   s-    yy;<yy~$$+++    c                 T    | j                  d      }|j                  d      dk(  sJ y )Nu   <h1>Räksmörgås</h1>   Räksmörgåsr   )r   r   r   s     r   test_unicode_text_findzTestFind.test_unicode_text_find&   s*    yy12yyy0OCCCr   c                 ~    | j                  d      }t        |       d|j                  d      j                  k(  sJ y )Nu&   <h1 id="Räksmörgås">here it is</h1>z
here it isr   id)r   strr   textr   s     r   test_unicode_attribute_findz$TestFind.test_unicode_attribute_find*   s7    yyABD	tyyOy<AAAAAr   c                 b    | j                  d      }dt        |j                               k(  sJ y)z)Test an optimization that finds all tags.<a>foo</a><b>bar</b>   Nr   lenfind_allr   s     r   test_find_everythingzTestFind.test_find_everything/   s*    yy/0C((((r   c                 d    | j                  d      }dt        |j                  d            k(  sJ y)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_namez'TestFind.test_find_everything_with_name4   s-    yy9:Cc*++++r   c                    | j                  d      }d|j                         j                  k(  sJ d|j                  d      j                         j                  k(  sJ d|j                  d      j	                         j                  k(  sJ y )Nz<div></div><p></p>divpr   r   namefind_previous_siblingfind_next_siblingr   s     r   test_find_with_no_argumentsz$TestFind.test_find_with_no_arguments9   sv    yy-.		(((((		#<<>CCCCCdii&88:?????r   c                    | j                  d      }d|j                         j                  k(  sJ d|j                  d      j                         j                  k(  sJ d|j                  d      j	                         j                  k(  sJ y )N"text<div>text</div>text<p>text</p>r/   r0   r1   r   s     r   +test_find_with_no_arguments_only_finds_tagsz4TestFind.test_find_with_no_arguments_only_finds_tags?   sv    yy=>		(((((		#<<>CCCCCdii&88:?????r   c                     | j                  d      }d|j                  d       j                  k(  sJ d |j                  d       k(  sJ y )Nr7   r0   c                      | j                   dk(  S )Nr0   r2   ts    r   <lambda>zETestFind.test_find_with_function_can_only_find_tags.<locals>.<lambda>G   s    !&&#+ r   c                     | dk(  S )Nr"    r<   s    r   r>   zETestFind.test_find_with_function_can_only_find_tags.<locals>.<lambda>H   s
    1f9 r   )r   r   r2   r   s     r   *test_find_with_function_can_only_find_tagsz3TestFind.test_find_with_function_can_only_find_tagsE   sG    yy=>dii 56;;;;;tyy!45555r   N)__name__
__module____qualname____doc__r   r   r#   r*   r-   r5   r8   rA   r@   r   r   r   r      s3    ,DB
)
,
@@6r   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestFindAllz%Basic tests of the find_all() method.c                 *   | j                  d      }dt        |j                  j                               k(  sJ dt        |j	                  d      j                               k(  sJ dt        |j	                  d      j                               k(  sJ y )Nz/<body>text<div>text</div>text<p>text</p></body>r&   r   r0   r/   )r   r(   bodyr)   r   find_previous_siblingsfind_next_siblingsr   s     r   /test_find_all_with_no_arguments_only_finds_tagsz;TestFindAll.test_find_all_with_no_arguments_only_finds_tagsM   sz    yyJKC		**,----C		#==?@@@@C		%(;;=>>>>r   c                    | j                  d      }|j                  d      dgk(  sJ |j                  ddg      ddgk(  sJ |j                  t        j                  d            g dk(  sJ |j                  d      g dk(  sJ y)	z'You can search the tree for text nodes.u   <html>Foo<b>bar</b>»</html>barr   Fooz.*)rO   rN      »TN)r   r)   recompiler   s     r   test_find_all_text_nodesz$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                 L   | j                  d      }| j                  |j                  dd      g d       | j                  |j                  dd      dg       | j                  |j                  dd      g d	       | j                  |j                  dd
      g d	       y)z7You can limit the number of items returned by find_all.z(<a>1</a><a>2</a><a>3</a><a>4</a><a>5</a>r,      limit)1r   3r   rX   
   )rX   r   rY   45r   Nr   assert_selectsr)   r   s     r   test_find_all_limitz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                     | j                  d      }| j                   |dd      dg       | j                  |j                  d      dg       y )	Nz!<a>1</a><b>2<a id='foo'>3</a></b>r,   r   rV   rX   foor   rY   )r   r^   r   r   s     r   %test_calling_a_tag_is_calling_findallz1TestFindAll.test_calling_a_tag_is_calling_findallj   sG    yy<=DA.6DFFeF,se4r   c                 :   | j                  d      }g }|j                  |       t        j                  d      5 }g |j	                  |      k(  sJ |\  }|j
                  t        k(  sJ t        |j                        }|dk(  sJ 	 d d d        y # 1 sw Y   y xY w)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_recursionz`TestFindAll.test_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursiono   s     yy#w $$D1 	Qw////IW##x///goo&Cabb	 	 	s   ABBc                     | j                  d      }|j                  d      }t        |d      sJ |j                  d      }t        |d      sJ |j                  d      }t        |d      sJ y)z%All find_all calls return a ResultSetrd   r,   sourceTra   r   N)r   r)   hasattrr   r   results      r   test_find_all_resultsetz#TestFindAll.test_find_all_resultset   sl    yy#s#vx(((t$vx(((e,vx(((r   N)
rB   rC   rD   rE   rL   rS   r_   rb   rq   rw   r@   r   r   rG   rG   J   s%    /?DT5
(
)r   rG   c                       e Zd Zd Zy)TestFindAllBasicNamespacesc                     | j                  d      }d|j                  d      j                  k(  sJ d|j                  ddi      j                  k(  sJ y )Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">r[   zmathml:msqrtr,   zsvg:fillredattrs)r   r   r   r2   r   s     r   test_find_by_namespaced_namez7TestFindAllBasicNamespaces.test_find_by_namespaced_name   sR    yyKLdii/66666diiz5&9i:?????r   N)rB   rC   rD   r~   r@   r   r   ry   ry      s    @r   ry   c                   T    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)TestFindAllByNamez&Test ways of finding tags by tag name.Nc                 0    | j                  d      | _        y )Nz<a>First tag.</a>
                                  <b>Second tag.</b>
                                  <c>Third <a>Nested tag.</a> tag.</c>r   treer   s    r   setup_methodzTestFindAllByName.setup_method   s    II J K	r   c                 ^    | j                  | j                  j                  d      ddg       y Nr,   
First tag.Nested tag.r^   r   r)   r   s    r   test_find_all_by_tag_namez+TestFindAllByName.test_find_all_by_tag_name   s&    DII..s3lM5RSr   c                 B   | j                  | j                  j                  dd      dg       | j                  | j                  j                  dd      ddg       | j                  | j                  j                  dt        j                  d            ddg       y )Nr,   r   r   Tr   tagr^   r   r)   rQ   rR   r   s    r   test_find_all_by_name_and_textz0TestFindAllByName.test_find_all_by_name_and_text   s    IIs<8<.	
 	IIs40<2O	
 	IIs2::e+<==)	
r   c                 p    | j                  | j                  j                  j                  d      dg       y )Nr,   r   )r^   r   cr)   r   s    r   !test_find_all_on_non_root_elementz3TestFindAllByName.test_find_all_on_non_root_element   s'    DIIKK005Gr   c                 J    | j                  | j                  d      ddg       y r   )r^   r   r   s    r   %test_calling_element_invokes_find_allz7TestFindAllByName.test_calling_element_invokes_find_all   s    DIIcN\=,IJr   c                 p    | j                  | j                  j                  t        d            ddg       y r   )r^   r   r)   r
   r   s    r   test_find_all_by_tag_strainerz/TestFindAllByName.test_find_all_by_tag_strainer   s.    II|C01L-3P	
r   c                 b    | j                  | j                  j                  ddg      g d       y )Nr,   r   r   zSecond tag.r   r   r   s    r   test_find_all_by_tag_namesz,TestFindAllByName.test_find_all_by_tag_names   s)    IISz*,X	
r   c                 d    | j                  | j                  j                  ddd      g d       y )NT)r,   r   r   r   r   s    r   test_find_all_by_tag_dictz+TestFindAllByName.test_find_all_by_tag_dict   s*    IIT568	
r   c                     | j                  | j                  j                  t        j                  d            g d       y )Nz^[ab]$r   r   r   s    r   test_find_all_by_tag_rez)TestFindAllByName.test_find_all_by_tag_re   s.    IIrzz(348	
r   c                 r    d }| j                  d      }| j                  |j                  |      ddg       y )Nc                 >    | j                   | j                  d      k(  S )Nr    )r2   getr   s    r   id_matches_namezRTestFindAllByName.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.r]   )r   r   r   s      r   'test_find_all_with_tags_matching_methodz9TestFindAllByName.test_find_all_with_tags_matching_method   s<    	- yy 6 7 	DMM/:Z<TUr   c                 J   | j                  d      }|j                  dd      }|j                  dt        j                  d            }|j	                  dddg      \  }}d|j
                  k(  sJ d|j
                  k(  sJ d|j
                  k(  sJ d|j
                  k(  sJ y )NzH<div class='a b'>1</div><div class='a c'>2</div><div class='a d'>3</div>r/   za dza brY   rX   )r   r   rQ   rR   r)   r   )r   r   r1r2r3r4s         r   %test_find_with_multi_valued_attributez7TestFindAllByName.test_find_with_multi_valued_attribute   s    yyV
 YYue$YYubjj01uuen5Bbiibiibiibiir   returnN)rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   r   r   r@   r   r   r   r      sA    0K
T
HK






V
 r   r   c                   l    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zy)TestFindAllByAttributec                 n    | j                  d      }| j                  |j                  d      ddg       y )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.r]   r   r   s     r   test_find_all_by_attribute_namez6TestFindAllByAttribute.test_find_all_by_attribute_name   s9     yy ! "
 	DMMWM5}7UVr   c                 \   dj                  d      }dj                  d      }| j                  |      }|j                  g|j                  |      k(  sJ |j                  g|j                  |j	                  d            k(  sJ |j                  gsJ |j                  |dg             y )Nu   םולשutf8u   <a title="םולש"></a>)titlezsomething else)encoder   r,   r)   decode)r   peacedatar   s       r   %test_find_all_by_utf8_attribute_valuez<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                     | j                  d      }| j                  |j                  d      dg       | j                  |j                  ddi      dg       | j                  |j                  dd	i      d
g       y )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>
                         name1r;   zA tag called 'name1'.r2   r|   zName match.classclass2zClass match.r]   r   s     r   test_find_all_by_attribute_dictz6TestFindAllByAttribute.test_find_all_by_attribute_dict   s}     yy   	DMMwM7:Q9RSDMM0AMB]OTDMM(0CMD~FVWr   c                    | j                  d      }| j                  |j                  dd      dg       | j                  |j                  dd      dg       | j                  |j                  dd	      dg       | j                  |j                  dd      dg       | j                  |j                  d
      ddg       | j                  |j                  dd      dg       | j                  |j                  dd	      dg       y )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,   rX   class_zClass 1.r   rY   zClass 3 and 4.r[   r|   r]   r   s     r   test_find_all_by_classz-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                 |   | j                  d      }|j                  dt        j                  d            }| j	                  |dg       |j                  dt        j                  d            }| j	                  |dg       |j                  dt        j                  d            }| j	                  |dg       y )Nz#<gar class='foo bar'>Found it</gar>garor   Found itr,   zo b)r   r)   rQ   rR   r^   )r   r   fs      r   0test_find_by_class_when_multiple_classes_presentzGTestFindAllByAttribute.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                 (   | j                  d      }| j                  |j                  dt        j                  d            dg       d }| j                  |j                  d|      g        d }| j                  |j                  d|      dg       y )Nz<a class='bar'>Found it</a>r,   bar   c                     t        |       dkD  S NrU   r(   values    r   big_attribute_valueznTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.big_attribute_value3  s    u:>!r   c                     t        |       dk  S r   r   r   s    r   small_attribute_valuezpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.small_attribute_value8  s    u:?"r   r   r^   r)   rQ   rR   )r   r   r   r   s       r   :test_find_all_with_non_dictionary_for_attrs_finds_by_classzQTestFindAllByAttribute.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                 H   | j                  d      }|j                  d      \  }}||gsJ |j                  dd             |gsJ |j                  dd             |g|j                  dd      k(  sJ |g|j                  dd      k(  sJ g |j                  dd      k(  sJ y )Nz*<a class="foo bar"></a><a class="foo"></a>r,   ra   rN   zfoo barr   zbar foor   r)   )r   r   r,   a2s       r   :test_find_all_with_string_for_attrs_finds_multiple_classeszQTestFindAllByAttribute.test_find_all_with_string_for_attrs_finds_multiple_classes=  s    yyEFc"22w1c511ws-DMM#u--s sdmmC	m::::sdmmC3333T]]3	2222r   c                     | j                  d      }t        ddi      }| j                  |j                  |      dg       y )Nzi
                         <a id="first">Match.</a>
                         <a id="second">Non-match.</a>r    r   r|   zMatch.)r   r
   r^   r)   )r   r   strainers      r   'test_find_all_by_attribute_soupstrainerz>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainerI  s@    yy : ;  tWo6DMM(3hZ@r   c                 n    | j                  d      }| j                  |j                  dd       dg       y )N<a id="1">ID present.</a>
                            <a>No ID present.</a>
                            <a id="">ID is empty.</a>r,   r   zNo ID present.r]   r   s     r   $test_find_all_with_missing_attributez;TestFindAllByAttribute.test_find_all_with_missing_attributeQ  s:     yy 9 : 	DMM#$M7:J9KLr   c                 n    | j                  d      }| j                  |j                  d      ddg       y )Nr   Tr   zID present.zID is empty.r]   r   s     r   $test_find_all_with_defined_attributez;TestFindAllByAttribute.test_find_all_with_defined_attributeY  s9     yy 9 : 	DMMTM2]N4STr   c                     | j                  d      }ddg}| j                  |j                  d      |       | j                  |j                  d      |       y )Nz[<a id=1>Unquoted attribute.</a>
                            <a id="1">Quoted attribute.</a>zUnquoted attribute.zQuoted attribute.r   r   rX   r]   )r   r   expecteds      r   $test_find_all_with_numeric_attributez;TestFindAllByAttribute.test_find_all_with_numeric_attributea  sY    yy ? @ *+>?DMMQM/:DMMSM18<r   c                     | j                  d      }| j                  |j                  g d      ddg       | j                  |j                  g       g        y )Nz<a id="1">1</a>
                            <a id="2">2</a>
                            <a id="3">3</a>
                            <a>No ID.</a>)rX   rY   r[   r   rX   rY   r]   r   s     r   (test_find_all_with_list_attribute_valuesz?TestFindAllByAttribute.test_find_all_with_list_attribute_valuesj  sU     yy - . 	DMM_M=SzJ 	DMMRM0"5r   c                     | j                  d      }| j                  |j                  t        j                  d            ddg       y )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_valuezLTestFindAllByAttribute.test_find_all_with_regular_expression_attribute_valuev  sB     yy - . 	DMMRZZ-?M@8YBWXr   c                     | j                  d      }|j                  }|g|j                  dd      k(  sJ g |j                  dd      k(  sJ y )Nz<b>foo</b><b>bar</b><a>foo</a>r,   ra   r   rN   r   r,   r)   r   r   r,   s      r   'test_find_by_name_and_containing_stringz>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                 t    | j                  d      }|j                  d      |j                  dd      k(  sJ y )Nz"<a>foo</a><a><b><c>foo</c></b></a>r,   ra   r   r   r   s     r   =test_find_by_name_and_containing_string_when_string_is_buriedzTTestFindAllByAttribute.test_find_by_name_and_containing_string_when_string_is_buried  s5    yy=>}}S!T]]3u]%EEEEr   c                     | j                  d      }|j                  }|g|j                  dd      k(  sJ g |j                  dd      k(  sJ y )Nz"<b id="1">foo</b><a id="2">foo</a>r&   ra   )r    r   r   rN   r   r   s      r   ,test_find_by_attribute_and_containing_stringzCTestFindAllByAttribute.test_find_by_attribute_and_containing_string  sR    yy=>FFsdmmqm7777T]]a]6666r   N)rB   rC   rD   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   r   r   r   r      s\    WHX$I(-U
3AMU=
6
Y6F7r   r   c                       e Zd ZdZd Zy)
TestSmoothzTest Tag.smooth.c                    | j                  d      }|j                  }|j                  d       |j                  d       |j                  t        d             |j                  t        d             |j                  d       | j	                         }t        ||d      }|j                  d       |j                  d	       |j                  |       d |j                  j                  u sJ d
t        |j                        k(  sJ |j                          dt        |j                        k(  sJ d|j                  d   k(  sJ d|j                  j                  k(  sJ d|j                  d   k(  sJ d|j                  d   k(  sJ y )Nz<div>a</div>r   r   z	Comment 1z	Comment 2dspanrX   r         abcr   12r   r&   )r   r/   rg   r   default_builderr	   r   r   r(   contentssmooth)r   r   r/   builderr   s        r   test_smoothzTestSmooth.test_smooth  sI   yy(hh

3

3

7;'(

7;'(

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

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

C%%%%
 Q''' sxx&&&
 cll1o---cll1o---r   N)rB   rC   rD   rE   r   r@   r   r   r   r     s
    &.r   r   c                       e Zd ZdZd Zy)	TestIndexzTest Tag.indexc                 "   | j                  d      }|j                  }t        |j                        D ]  \  }}||j	                  |      k(  rJ  t        j                  t              5  |j	                  d       d d d        y # 1 sw Y   y xY w)Nah  <div>
                            <a>Identical</a>
                            <b>Not identical</b>
                            <a>Identical</a>

                            <c><d>Identical with child</d></c>
                            <b>Also not identical</b>
                            <c><d>Identical with child</d></c>
                            </div>r   )r   r/   	enumerater   indexpytestraises
ValueError)r   r   r/   ielements        r   
test_indexzTestIndex.test_index  s    yy & ' hh#CLL1 	+JAw		'****	+]]:& 	JJqM	 	 	s   *BBN)rB   rC   rD   rE   r  r@   r   r   r   r     s
    r   r   c                   N    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)TestParentOperationsz;Test navigation and searching through an element's parents.Nc                 f    | j                  d      | _        | j                  j                  | _        y )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   z!TestParentOperations.setup_method  s(    II + ,	 YY[[
r   c                     | j                   j                  d   dk(  sJ | j                   j                  j                  d   dk(  sJ | j                   j                  j                  j                  d   dk(  sJ y )Nr    bottommiddletop)r  parentr   s    r   test_parentz TestParentOperations.test_parent  sk    zz  &(222zz  ''-999zz  ''..t4===r   c                 l    | j                   j                  d   }|j                  | j                   k(  sJ y )Nr   )r   r   r  )r   top_tags     r   %test_parent_of_top_tag_is_soup_objectz:TestParentOperations.test_parent_of_top_tag_is_soup_object  s,    ))$$Q'~~***r   c                 8    d | j                   j                  u sJ y N)r   r  r   s    r   test_soup_object_has_no_parentz3TestParentOperations.test_soup_object_has_no_parent  s    tyy'''''r   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  dd      dg       | j                  j                  d      g k(  sJ y )Nulr  r  r  r  r   r  )assert_selects_idsr  find_parentsr   s    r   test_find_parentsz&TestParentOperations.test_find_parents  sm    JJ##D)+F	
 	

 7 7 7 JXJWzz&&'&2b888r   c                     | j                   j                  dd      d   dk(  sJ | j                   j                  d      J y )Nr  r  r   r    r  )r  find_parentr   s    r   test_find_parentz%TestParentOperations.test_find_parent  sG    zz%%du%5d;uDDDzz%%%1999r   c                 r    | j                   j                  d      }|j                  j                  dk(  sJ y )N
Start herer   r   )r   r   r  r2   r   r"   s     r   test_parent_of_text_elementz0TestParentOperations.test_parent_of_text_element  s.    yy~~\~2{{3&&&r   c                 n    | j                   j                  d      }|j                  d      d   dk(  sJ y )Nr#  r   r  r    r  )r   r   r   r$  s     r   test_text_element_find_parentz2TestParentOperations.test_text_element_find_parent  s4    yy~~\~2%d+x777r   c                     | j                   j                  D cg c]  }|d|j                  v r|d    }}|g dk(  sJ y c c}w )Nr    r  )r  parentsr}   )r   r  r)  s      r   test_parent_generatorz*TestParentOperations.test_parent_generator  sV     **,,
!dfll&: 4L
 

 5555
   Ac                     | j                   j                  D cg c]  }|d|j                  v r|d    }}|g dk(  sJ y c c}w )Nr    )r  r  r  r  )r  self_and_parentsr}   )r   r  resultss      r   test_self_and_parent_generatorz3TestParentOperations.test_self_and_parent_generator  sV     **55
!dfll&: 4L
 

 >>>>
r+  r   )rB   rC   rD   rE   r   r  r  r  r  r!  r%  r'  r*  r/  r@   r   r   r
  r
    s7    E!>
+(9:'86?r   r
  c                       e Zd ZddZy)ProximityTestNc                 0    | j                  d      | _        y )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   zProximityTest.setup_method  s    II P
	r   r   rB   rC   rD   r   r@   r   r   r1  r1    s    
r   r1  c                   J     e Zd Zd	 fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )
TestNextOperationsc                 `    t         t        |           | j                  j                  | _        y r  )superr5  r   r   r   r  r   	__class__s    r   r   zTestNextOperations.setup_method  s      $46YY[[
r   c                     | j                   j                  dk(  sJ | j                   j                  j                  d   dk(  sJ y )NOner    r   )r  next_elementr   s    r   	test_nextzTestNextOperations.test_next   s=    zz&&%///zz&&33D9S@@@r   c                 X    | j                   j                  d      }|j                  J y NThreer   )r   r   r<  )r   lasts     r   test_next_of_last_item_is_nonez1TestNextOperations.test_next_of_last_item_is_none$  s(    yy~~W~-  (((r   c                 4    | j                   j                  J y r  )r   r<  r   s    r   test_next_of_root_is_nonez,TestNextOperations.test_next_of_root_is_none(  s    yy%%---r   c                     | j                  | j                  j                  d      ddg       | j                  j                  d       | j                  | j                  j                  d      dg       y )Nr   Twor@  rU   r   )r^   r  find_all_nextr   s    r   test_find_all_nextz%TestNextOperations.test_find_all_next,  s_    DJJ44S9E7;KL

  A &DJJ444:WIFr   c                     | j                   j                  d      d   dk(  sJ | j                   j                  d      dk(  sJ y )Nr   r    r   r@  r   )r  	find_nextr   s    r   test_find_nextz!TestNextOperations.test_find_next1  sD    zz##C(.#555zz##7#3w>>>r   c                     | j                   j                  d      }|j                  d      j                  dk(  sJ | j	                  |j                  d      ddg       y )Nr;  r   r   rF  r@  )r   r   rJ  r   r^   rG  r$  s     r   test_find_next_for_text_elementz2TestNextOperations.test_find_next_for_text_element5  sS    yy~~U~+~~c"))U222D..s3eW5EFr   c                    | j                   j                  d      }|j                  D cg c]  }| }}|\  }}|d   dk(  sJ |dk(  sJ |j                  D cg c]  }| }}|dd  |k(  sJ |d   |k(  sJ y c c}w c c}w )NrF  r   r    rY   r@  r   r   )r   r   next_elementsself_and_next_elements)r   r  node
successorsr   r   successors2s          r   test_next_generatorsz'TestNextOperations.test_next_generators:  s    		e,',':':;td;
;"X4yC7"""(-(D(DEtEE12*,,,1~&&& < Fs   	A:	A?r   )rB   rC   rD   r   r=  rB  rD  rH  rK  rM  rT  __classcell__r9  s   @r   r5  r5    s.    !A).G
?G

'r   r5  c                   J     e Zd Zd	 fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )
TestPreviousOperationsc                 l    t         t        |           | j                  j	                  d      | _        y r?  )r7  rX  r   r   r   endr8  s    r   r   z#TestPreviousOperations.setup_methodH  s'    $d8:99>>>1r   c                     | j                   j                  d   dk(  sJ | j                   j                  j                  dk(  sJ y )Nr    rY   rF  )rZ  previous_elementr   s    r   test_previousz$TestPreviousOperations.test_previousL  s=    xx((.#555xx((99UBBBr   c                 V    | j                   j                  d      }|j                  J y )Nhtml)r   r   r\  )r   r   s     r   #test_previous_of_first_item_is_nonez:TestPreviousOperations.test_previous_of_first_item_is_noneP  s&    		v&%%---r   c                 4    | j                   j                  J y r  )r   r\  r   s    r   test_previous_of_root_is_nonez4TestPreviousOperations.test_previous_of_root_is_noneT  s    yy))111r   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr   r@  rF  r;  r   r   r;  )r^   rZ  find_all_previousr   s    r   test_find_all_previousz-TestPreviousOperations.test_find_all_previousX  sH     	DHH66s;=TUDHH66!6<ugFr   c                     | j                   j                  d      d   dk(  sJ | j                   j                  d      dk(  sJ y )Nr   r    rY   r;  r   )rZ  find_previousr   s    r   test_find_previousz)TestPreviousOperations.test_find_previous_  sD    xx%%c*40C777xx%%U%3u<<<r   c                     | j                   j                  d      }|j                  d      j                  dk(  sJ | j	                  |j                  d      g d       y )Nr@  r   r   rd  )r   r   rh  r   r^   re  r$  s     r   #test_find_previous_for_text_elementz:TestPreviousOperations.test_find_previous_for_text_elementc  sQ    yy~~W~-!!#&--888D22379PQr   c                     | j                   j                  dd      }| j                  |j                  g d       | j                  |j                  g d       y )Nr   r;  r   )bodytagheadtagr  )rX   rm  rn  r  )r   r   r  previous_elementsself_and_previous_elements)r   r  s     r   test_previous_generatorsz/TestPreviousOperations.test_previous_generatorsh  sF    		s51 7 79XY @ @Bfgr   r   )rB   rC   rD   r   r]  r`  rb  rf  ri  rk  rq  rU  rV  s   @r   rX  rX  G  s/    2C.2G=R
hr   rX  c                       e Zd ZddZy)SiblingTestNc                 ~    d}t        j                  d      j                  d|      }| j                  |      | _        y )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* )rQ   rR   subr   r   )r   markups     r   r   zSiblingTest.setup_methodo  s6     H%))"f5IIf%	r   r   r3  r@   r   r   rs  rs  n  s    &r   rs  c                   J     e Zd Zd	 fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )
TestNextSiblingc                 l    t         t        |           | j                  j	                  d      | _        y )NrX   r   )r7  ry  r   r   r   r  r8  s    r   r   zTestNextSibling.setup_method  s&    ot13YY^^s^+
r   c                 4    | j                   j                  J y r  )r   next_siblingr   s    r   !test_next_sibling_of_root_is_nonez1TestNextSibling.test_next_sibling_of_root_is_none  s    yy%%---r   c                     | j                   j                  d   dk(  sJ | j                   j                  j                  d   dk(  sJ | j                   j                  d   dk(  sJ y )Nr    r   rY   1.1)r  r|  r<  r   s    r   test_next_siblingz!TestNextSibling.test_next_sibling  sa    zz&&t,333zz&&33D9S@@@ zz&&t,555r   c                     | j                   j                  j                  J | j                   j                  d      }|j                  J | j                   j                  d      }|j                  J y )Nr  r   r[   )r   r_  r|  r   )r   nested_span	last_spans      r   test_next_sibling_may_not_existz/TestNextSibling.test_next_sibling_may_not_exist  sh    yy~~**222iinnn.''///IINNcN*	%%---r   c                 J    | j                   j                  d      d   dk(  sJ y )Nr   r    r   )r  r4   r   s    r   test_find_next_siblingz&TestNextSibling.test_find_next_sibling  s$    zz++F3D9S@@@r   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr   r   rY   r[   rY   r   )r  r  rK   r   s    r   test_next_siblingsz"TestNextSibling.test_next_siblings  sE    

 = =f EW

 = = = EuMr   c                     | j                  | j                  j                  g d       | j                  | j                  j                  g d       y )Nr  )rX   r   rY   r[   )r  r  next_siblingsself_and_next_siblingsr   s    r   test_next_siblings_generatorsz-TestNextSibling.test_next_siblings_generators  s7    

 8 8/J

 A ACWXr   c                 P   | j                  d      }|j                  d      }|j                  j                  dk(  sJ |j                  j                  dk(  sJ | j	                  |j                  d      dg       |j                  d      dk(  sJ |j                  d      J y )NFoo<b>bar</b>bazrO   r   r   bazrN   nonesuch)r   r   r|  r2   r^   rK   r4   r   r   r  s      r   "test_next_sibling_for_text_elementz2TestNextSibling.test_next_sibling_for_text_element  s    yy+,			'!!&&#---!!..%777E44S9E7C&&e&4===&&j&9AAAr   r   )rB   rC   rD   r   r}  r  r  r  r  r  r  rU  rV  s   @r   ry  ry    s/    ,.6.AN
YBr   ry  c                   J     e Zd Zd	 fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )
TestPreviousSiblingc                 l    t         t        |           | j                  j	                  d      | _        y )Nr[   r   )r7  r  r   r   r   rZ  r8  s    r   r   z TestPreviousSibling.setup_method  s'    !45799>>S>)r   c                 4    | j                   j                  J y r  )r   previous_siblingr   s    r   %test_previous_sibling_of_root_is_nonez9TestPreviousSibling.test_previous_sibling_of_root_is_none  s    yy))111r   c                     | j                   j                  d   dk(  sJ | j                   j                  j                  d   dk(  sJ | j                   j                  d   dk(  sJ y )Nr    rY   r   z3.1)rZ  r  r\  r   s    r   test_previous_siblingz)TestPreviousSibling.test_previous_sibling  sa    xx((.#555xx((99$?3FFF xx((.%777r   c                     | j                   j                  j                  J | j                   j                  d      }|j                  J | j                   j                  d      }|j                  J y )Nr  r   rX   )r   r_  r  r   )r   r  
first_spans      r   #test_previous_sibling_may_not_existz7TestPreviousSibling.test_previous_sibling_may_not_exist  sh    yy~~..666iinnn.++333YY^^s^+
**222r   c                 J    | j                   j                  d      d   dk(  sJ y )Nr   r    rY   )rZ  r3   r   s    r   test_find_previous_siblingz.TestPreviousSibling.test_find_previous_sibling  s$    xx--f5d;sBBBr   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr   rY   r   rX   rX   r   )r  rZ  rJ   r   s    r   test_previous_siblingsz*TestPreviousSibling.test_previous_siblings  sJ    HH++F3_	
 	 ? ?3 ? G#Or   c                     | j                  | j                  j                  g d       | j                  | j                  j                  g d       y )Nr  )r[   rY   r   rX   )r  rZ  previous_siblingsself_and_previous_siblingsr   s    r   !test_previous_siblings_generatorsz5TestPreviousSibling.test_previous_siblings_generators  s7     : :OL C CEYZr   c                 P   | j                  d      }|j                  d      }|j                  j                  dk(  sJ |j                  j                  dk(  sJ | j	                  |j                  d      dg       |j                  d      dk(  sJ |j                  d      J y )Nr  r  r   r   rO   rN   r  )r   r   r  r2   r^   rJ   r3   r  s      r   &test_previous_sibling_for_text_elementz: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   )rB   rC   rD   r   r  r  r  r  r  r  r  rU  rV  s   @r   r  r    s/    *283CP[Fr   r  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej4                  j7                  dd d g      d        Zej4                  j7                  dd dgd dgf      d         Zd! Zd" Zd# Z d$ Z!d% Z"d& Z#d' Z$d( Z%d) Z&d* Z'd+ Z(d, Z)d- Z*d. Z+d/ Z,d0 Z-d1 Z.d2 Z/d3 Z0d4 Z1d5 Z2d6 Z3d7 Z4ej4                  j7                  d8g d9      d:        Z5d; Z6d< Z7d= Z8d> Z9d? Z:y@)ATestTreeModificationc                 T   | j                  d      }d|j                  d<   |j                         | j                  d      k(  sJ |j                  d= |j                         | j                  d      k(  sJ d|j                  d<   |j                         | j                  d      k(  sJ y )	Nz<a id="1"></a>r&   r    z<a id="2"></a>rd   ra   id2z<a id2="foo"></a>)r   r,   r   document_forr   s     r   test_attribute_modificationz0TestTreeModification.test_attribute_modification  s    yy)*t{{} 1 12B CCCCFF4L{{} 1 1) <<<<u{{} 1 12E FFFFr   c                 J    t        j                  d             }| j                  d|      }t        ||d      }t        ||d      }d|d<   |j                  j                  d|       |j                  j                  d	|       |j                  j                         d
k(  sJ y )Nr_  z<body></body>r   r,   olzhttp://foo.com/hrefr   r   s4   <body><a href="http://foo.com/"></a><ol></ol></body>)r   lookupr   r	   rI   insertr   )r   r   r   r,   r  s        r   test_new_tag_creationz*TestTreeModification.test_new_tag_creation  s    1"))&13yy'y:gs#w%%&			A		BIIFG	
Gr   c                 &   d}| j                  |      }|j                  d      }|j                  }|j                  d      j                  |j                         |j                  |k(  sJ |j                         | j                  d      k(  sJ y )NzT<p id="1">Don't leave me <b>here</b>.</p>
                <p id="2">Don't leave!</p>r   r   zD<p id="1">Don't leave me .</p>
<p id="2">Don't leave!<b>here</b></p>)r   r   r   rg   r  r   r  )r   docr   second_parabolds        r   !test_append_to_contents_moves_tagz6TestTreeModification.test_append_to_contents_moves_tag  s    /yy~ii3i'vv 			S	  ( {{k))){{} 1 1X!
 
 	
 
r   c                    | j                  d      }|j                  d      }|j                  |j                  d            }|j                  dk(  sJ |j                  d|j                  d            \  }|j                  dk(  sJ |j                  d      }|dk(  sJ |j                  dd      }|ddgk(  sJ |j                  d	d
      }|d	d
gk(  sJ |j                  ddg      }|ddgk(  sJ |j                         dk(  sJ y )Nz<html></html>r_  headr   r   r\   rY   r[   67893456789)
r   r   rg   new_tagr2   r  insert_beforeinsert_afterextendget_text)	r   r   r_  r  r   text5text34text67text89s	            r   &test_insertion_returns_inserted_thingsz;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                     d}| j                  |      }|j                  }|j                  |j                        }||k(  sJ y )Nz<a></a><b><c></c></b>)r   r,   replace_withr   r   r"   r   r,   new_as        r   1test_replace_with_returns_thing_that_was_replacedzFTestTreeModification.test_replace_with_returns_thing_that_was_replaced  s;    &yyFFtvv&Ezzr   c                 p    d}| j                  |      }|j                  }|j                         }||k(  sJ y )N<a><b></b><c></c></a>)r   r,   unwrapr  s        r   +test_unwrap_returns_thing_that_was_replacedz@TestTreeModification.test_unwrap_returns_thing_that_was_replaced$  s4    &yyFF
Ezzr   c                    | j                  d      }|j                  }|j                          d |j                  u sJ t	        j
                  t              5  |j                          d d d        t	        j
                  t              5  |j                  |j                         d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY w)Nz<a><b>Foo</b></a><c>Bar</c>)
r   r,   extractr  r  r  r  r  r  r   r   s      r   Itest_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parentz^TestTreeModification.test_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parent+  s    yy67FF			qxx]]:& 	HHJ	]]:& 	#NN466"	# 	#	 		# 	#s   B.	B:.B7:Cc                     d}| j                  |      }|j                  }|j                  j                  |      }||k(  sJ |j                         | j	                  |      k(  sJ y )Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)r   r   r  r   r  )r   r"   r   r   rv   s        r   test_replace_tag_with_itselfz1TestTreeModification.test_replace_tag_with_itself5  s\    >yyFF$$Q'{{{{} 1 1$ 7777r   c                     d}| j                  |      }t        j                  t              5  |j                  j                  |j                         d d d        y # 1 sw Y   y xY wN<a><b></b></a>)r   r  r  r  r   r  r,   r   r"   r   s      r   1test_replace_tag_with_its_parent_raises_exceptionzFTestTreeModification.test_replace_tag_with_its_parent_raises_exception=  sK    yy]]:& 	(FF'	( 	( 	(s   &AA%c                     d}| j                  |      }t        j                  t              5  |j                  j                  d|j                         d d d        y # 1 sw Y   y xY w)Nr  r   )r   r  r  r  r,   r  r  s      r   ,test_insert_tag_into_itself_raises_exceptionzATestTreeModification.test_insert_tag_into_itself_raises_exceptionC  sK    yy]]:& 	%FFMM!TVV$	% 	% 	%s   'AA&c                    | j                  d      }|j                  d|j                  dd      |j                  dd            \  }}d|j                  k(  sJ d|j                  k(  sJ t	        |j
                        \  }}}}d|j                  k(  sJ d|j                  k(  sJ d|j                  k(  sJ d|j                  k(  sJ y )	N-<p>And now, a word:</p><p>And we're back.</p>r   r0   p2r   p3And now, a word:And we're back.)r   r  r  r   listchildren)r   r   r  r  p1p4s         r   test_insert_multiple_elementsz2TestTreeModification.test_insert_multiple_elementsI  s    yyHIQS >SY]@^_Bryy   ryy   dmm,BB!RYY...ryy   ryy    BII---r   c                    | j                  d      }d}| j                  |      }|j                  d|      \  }}d|j                  k(  sJ d|j                  k(  sJ |j                  D ]  }t	        |t
              sJ  t        |j                        \  }}}}d|j                  k(  sJ d|j                  k(  sJ d|j                  k(  sJ d|j                  k(  sJ y)	zInserting one BeautifulSoup object into another actually inserts all
        of its children -- you'll never combine BeautifulSoup objects.
        r  z<p>p2</p><p>p3</p>r   r  r  r  r  N)r   r  r   descendants
isinstancer   r  r  )	r   r   r"   	to_insertr  r  r  r  r  s	            r   1test_insert_beautifulsoup_object_inserts_childrenzFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrenU  s     yyHI#IIdO	Q	*Bryy   ryy   !! 	4A!!]333	4 dmm,BB!RYY...ryy   ryy    BII---r   c                     | j                  d      }|j                  }|j                  dd       |j                  \  }}|j	                  d       |j	                  d       d|j
                  j                  k(  sJ y )Nz<p><a>one</a><b>three</b></p>r   tworu  three)r   r,   r  r   r  r   r   )r   r   r,   leftrights        r   3test_replace_with_maintains_next_element_throughoutzHTestTreeModification.test_replace_with_maintains_next_element_throughoutj  sk    yy89FF	E jje"2 $&&--'''r   c                 :   | j                  d      }|j                  d      j                  d       |j                  d      }|j                  }|j                  |k(  sJ |j
                  |k(  sJ |j                  j                  |k(  sJ |j                  J y )Nz<b>Argh!</b>Argh!r   Hooray!)r   r   r  r   r\  r  r<  )r   r   new_textr   s       r   test_replace_final_nodez,TestTreeModification.test_replace_final_nodex  s    yy(			!..y999I9.FF((A---!###((55AAA$$,,,r   c                    | j                  d      }|j                  j                  dd       |j                         | j	                  d      k(  sJ |j                  d      }|j                  dk(  sJ |j                  j                  |k(  sJ |j                  dk(  sJ |j                  j                  |k(  sJ |j                  J |j                  |j                  k(  sJ y )Nz<a><b>Argh!</b><c></c></a>r   r  z!<a><b>Argh!Hooray!</b><c></c></a>r   r  )r   r   r  r   r  r   r\  r<  r  r|  r   )r   r   r  s      r   test_consecutive_text_nodesz0TestTreeModification.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                     | j                  d      }|j                  j                  dd       |j                  j                  dd       ddg|j                  j                  k(  sJ |j                  j                  d   j                  dk(  sJ y )Nrd   r   rN   ra   )r   r,   r  r   r<  r   s     r   test_insert_stringz'TestTreeModification.test_insert_string  so    yy#aau~000vvq!..%777r   c                     | j                  d      }|j                  j                  d      }|dk(  sJ |j                  j                         dk(  sJ y )Nz<b>1</b>r   z	<b>12</b>)r   r   rg   r   ru   s      r   test_appendz TestTreeModification.test_append  sF    yy$s#}}vv}}+---r   c                    | j                         }| j                  d|      }t        ||d      }|j                  dd       |j                  j                  d|       |j                         | j                  d      k(  sJ |j                  }|j                  |k(  sJ |j                  |k(  sJ |j                  d	      }|j                  |k(  sJ |j                  |k(  sJ |j                  }|j                  |k(  sJ |j                  |k(  sJ |j                  d	      }|j                  |k(  sJ |j                  |k(  sJ |j                  |k(  sJ y )
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  r,   r   r  r   r|  r  r   r<  r\  r   r  )r   r   r   	magic_tagb_tagr   c_tagr  s           r   test_insert_tagz$TestTreeModification.test_insert_tag  sa   &&(yy@'yRgz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                     d}| j                  |      }|j                  j                  d|j                         ||j	                         k(  sJ y )Nz<a>b<c></c>d</a>r   )r   r,   r  r   r   r   r   r   s      r   %test_insert_into_the_current_locationz:TestTreeModification.test_insert_into_the_current_location  s>    !yya t{{}$$$r   c                     d}| j                  |      }|j                  j                  |j                         ||j	                         k(  sJ y r  )r   r,   rg   r   r   r  s      r   *test_append_child_thats_already_at_the_endz?TestTreeModification.test_append_child_thats_already_at_the_end  s<    yydfft{{}$$$r   c                    d}| j                  |      }|j                  |j                  |j                  |j                  |j
                  |j                  g}|j                  j                  |       d|j                         k(  sJ y )Nz1<a><b><c><d><e><f><g></g></f></e></d></c></b></a>z1<a><g></g><f></f><e></e><d></d><c></c><b></b></a>)
r   gr   er   r   r   r,   r  r   r   r   r   elementss       r   #test_extend_with_a_list_of_elementsz8TestTreeModification.test_extend_with_a_list_of_elements  sb    ByyFFDFFDFFDFFDFFDFFChBdkkmSSSr   c                     d}| j                  |      }ddt        d      dg}|j                  j                  |       d|j	                         k(  sJ y )Nrd   r   r   r   r  z<a>bcde</a>)r   r   r,   r  r   r  s       r   "test_extend_with_a_list_of_stringsz7TestTreeModification.test_extend_with_a_list_of_strings  sK    yyoc2C8h---r   get_tagsc                     | S r  r@   r   s    r   r>   zTestTreeModification.<lambda>  s    c r   c                     | j                   S r  )r   r   s    r   r>   zTestTreeModification.<lambda>  s
    s|| r   c                     d}| j                  |      }|j                  dd      }|j                  dd      } ||      }|j                  |       d|j                         k(  sJ d|j                         k(  sJ y )NzS<body><div id="d1"><a>1</a><a>2</a><a>3</a><a>4</a></div><div id="d2"></div></body>r/   d1r   d2z<div id="d1"></div>z3<div id="d2"><a>1</a><a>2</a><a>3</a><a>4</a></div>)r   r   r  r   )r   r  r   r   r  r  tagss          r   &test_extend_with_another_tags_contentsz;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                 .    | j                   j                  S r  )r,   r   r   s    r   r>   zTestTreeModification.<lambda>  s    $&&-- r   z<a></a><b>1</b>c                      y)Nabcder@   r!  s    r   r>   zTestTreeModification.<lambda>  s    r   z<a>1</a><b>abcde</b>c                 p   d}| j                  |      }t        j                  d      5 } ||      }|j                  j	                  |       |j
                  j                         |k(  sJ |\  }|j                  t        k(  sJ t        |j                        }|dk(  sJ 	 d d d        y # 1 sw Y   y xY w)Nz<div><a>1</a><b></b></div>Tre   zIA single non-Tag item was passed into Tag.extend. Use Tag.append instead.)r   rh   ri   r   r  r/   decode_contentsrj   rk   r!   rl   )	r   string_sourcerv   r   r   rn   r   ro   rp   s	            r   )test_extend_with_a_single_non_tag_elementz>TestTreeModification.test_extend_with_a_single_non_tag_element  s     ,yy$$D1 
	Q"4(FFFMM&!88++-777IW##x///goo&C^__
	 
	 
	s   A8B,,B5c                     d}| j                  |      }|j                  j                  d|j                         d|j	                         k(  sJ y )Nz<a><b></b><c></c><d></d></a>r   z<a><d></d><b></b><c></c></a>)r   r,   r  r   r   r  s      r   $test_move_tag_to_beginning_of_parentz9TestTreeModification.test_move_tag_to_beginning_of_parent  s>    -yya ->>>r   c                     | j                  d      }|j                  j                  dd       t        |j                        dk(  sJ y )Nz<br/>r   Contentsz<br>Contents</br>)r   brr  r!   r   s     r   &test_insert_works_on_empty_element_tagz;TestTreeModification.test_insert_works_on_empty_element_tag  s;    
 yy!q*%477|2222r   c                    | j                  d      }|j                  j                  d       |j                  j                  d       |j	                         | j                  d      k(  sJ |j                  j                  |j                         |j	                         | j                  d      k(  sJ |j                  }t        j                  t              5  |j                  |       d d d        |j                          t        j                  t              5  |j                  d       d d d        | j                  d      }|j                  j                  |j                  d             y # 1 sw Y   xY w# 1 sw Y   QxY w)	Nr%   BAZQUUXzQUUX<a>foo</a>BAZ<b>bar</b>QUUX<b>bar</b><a>foo</a>BAZnope<a>r,   )r   r   r  r,   r   r  r  r  r  r  r  r   r   r   s      r   test_insert_beforez'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\\#./	 	
	$ 	$   E3E?3E<?Fc                 v   | j                  d      }|j                  j                  ddd       |j                  j                  ddd       |j	                         | j                  d      k(  sJ |j                  j                  |j                  d       |j	                         | j                  d      k(  sJ y )Nr%   r/   r0  z$QUUX BAZ<a>foo</a>BAZ QUUX<b>bar</b>FOOz'QUUX BAZ<b>bar</b>FOO<a>foo</a>BAZ QUUX)r   r   r  r,   r   r  r   s     r   test_insert_multiple_beforez0TestTreeModification.test_insert_multiple_before$  s    yy/0UC0VS%0{{} 1 12!
 
 	
 
 	TVVU+{{} 1 15!
 
 	
 
r   c                    | j                  d      }|j                  j                  d       |j                  j                  d       |j	                         | j                  d      k(  sJ |j                  j                  |j                         |j	                         | j                  d      k(  sJ |j                  }t        j                  t              5  |j                  |       d d d        |j                          t        j                  t              5  |j                  d       d d d        | j                  d      }|j                  j                  |j                  d             y # 1 sw Y   xY w# 1 sw Y   QxY w)	Nr%   r/  r0  z<a>foo</a>QUUX<b>bar</b>BAZr1  r2  r3  r,   )r   r   r  r,   r   r  r  r  r  r  r  r  r4  s      r   test_insert_afterz&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\\#./	 	
	# 	#r6  c                 v   | j                  d      }|j                  j                  ddd       |j                  j                  ddd       |j	                         | j                  d      k(  sJ |j                  j                  |j                  d       |j	                         | j                  d      k(  sJ y )Nr%   r/  r8  r0  z$<a>foo</a>QUUX BAZ<b>bar</b>BAZ QUUXzFOO z(QUUX BAZ<b>bar</b><a>foo</a>FOO BAZ QUUX)r   r   r  r,   r   r  r   s     r   test_insert_multiple_afterz/TestTreeModification.test_insert_multiple_afterI  s    yy/0E3/FC/{{} 1 12!
 
 	
 
 	DFFF+{{} 1 16!
 
 	
 
r   c                    | j                  d      }|j                  d      }|j                  d      }t        j                  t
              5  |j                  |       d d d        t        j                  t              5  |j                  |       d d d        t        j                  t
              5  |j                  |       d d d        y # 1 sw Y   pxY w# 1 sw Y   IxY w# 1 sw Y   y xY wNru  r,   )r   r  
new_stringr  r  r  r  NotImplementedErrorr   r   r   r   s       r   :test_insert_after_raises_exception_if_after_has_no_meaningzOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningU  s    yy}ll3$]]:& 	%$	%]]./ 	#c"	#]]:& 	"S!	" 	"		% 	%	# 	#	" 	"$   C C3C&CC#&C/c                    | j                  d      }|j                  d      }|j                  d      }t        j                  t
              5  |j                  |       d d d        t        j                  t              5  |j                  |       d d d        t        j                  t
              5  |j                  |       d d d        y # 1 sw Y   pxY w# 1 sw Y   IxY w# 1 sw Y   y xY wr@  )r   r  rA  r  r  r  r  rB  rC  s       r   Ftest_insert_before_raises_notimplementederror_if_before_has_no_meaningz[TestTreeModification.test_insert_before_raises_notimplementederror_if_before_has_no_meaning`  s    yy}ll3$]]:& 	&  %	&]]./ 	$s#	$]]:& 	#c"	# 	#		& 	&	$ 	$	# 	#rE  c                 N   | j                  d      }|j                  d      \  }}|j                  |       |j                         | j	                  d      k(  sJ |j
                  J |j
                  |j                  k(  sJ |j                  dk(  sJ |j                  dk(  sJ y )Nz;<p>There's <b>no</b> business like <b>show</b> business</p>r   z0<p>There's  business like <b>no</b> business</p>noz	 business)	r   r)   r  r   r  r  r0   r<  r|  )r   r   rI  shows       r   test_replace_withz&TestTreeModification.test_replace_withk  s    yyVW==%D"{{} 1 1>!
 
 	
 
 {{"""yyDFF"""$&&&+---r   c                    t        d      }t        j                  t              5  |j	                  d       d d d        | j                  d      j                  }t        j                  t              5  |j                  j	                  |       d d d        t        j                  t              5  |j                  j	                  d|d       d d d        y # 1 sw Y   xY w# 1 sw Y   UxY w# 1 sw Y   y xY w)Nr,   r;   z
won't workr  string1string2)r	   r  r  r  r  r   r,   r   )r   a_tags     r   test_replace_with_errorsz-TestTreeModification.test_replace_with_errorsx  s    ]]:& 	-|,	- 		*+--]]:& 	(GG  '	( ]]:& 	>GG  E9=	> 	>	- 	-
	( 	(	> 	>s#   C4C$1C0C!$C-0C9c                    d}| j                  |      }|j                  d      }d|_        |j                  d      }|j                  d      }d}|j                  j	                  ||||       |j                         dk(  sJ |j                  j                  |k(  sJ |j                  j                  |k(  sJ |j                  j                  |k(  sJ |j                  j                  |k(  sJ y )Nr  r   zText In D Tagr  r   zRandom Textz;<a><b></b><d>Text In D Tag</d><e></e>Random Text<f></f></a>)r   r  r   r   r  r   r   r<  )r   r   r   d_tage_tagf_taga_strings          r   test_replace_with_multiplez/TestTreeModification.test_replace_with_multiple  s    &yyS!&S!S! E5(E:KKMLM	
M vv""e+++||((E111!!((H444!!..%777r   c                     d}| j                  |      }|j                  j                  |j                         d|j	                         k(  sJ y )Nr  z<a><c></c></a>)r   r   r  r   r   r  s      r   test_replace_first_childz-TestTreeModification.test_replace_first_child  >    &yyDFF#4;;=000r   c                     d}| j                  |      }|j                  j                  |j                         d|j	                         k(  sJ y )Nr  r  )r   r   r  r   r   r  s      r   test_replace_last_childz,TestTreeModification.test_replace_last_child  rY  r   c                    | j                  d      }|j                  }|j                  }|j                  |       |j	                         | j                  d      k(  sJ |j                  J |j                  d      j                  J |j                  J |j                  J |j                  J |j                  |j                  k(  sJ |j                  dk(  sJ |j                  j                  |j                  k(  sJ |j                  J |j                  d      }|j                  }|j                  |k(  sJ |j                  |k(  sJ |j                  |k(  sJ |j                  |k(  sJ y )NzQ<a>We<b>reserve<c>the</c><d>right</d></b></a><e>to<f>refuse</f><g>service</g></e>z-<a>We<f>refuse</f></a><e>to<g>service</g></e>r  r   Weto)r   r   r   r  r   r  r  r   r<  r\  r|  r  r,   r  r  )r   r   
remove_tagmove_tagto_textg_tags         r   test_nested_tag_replace_withz1TestTreeModification.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                     | j                  d      }|j                  j                          |j                  J |j                  j                  dk(  sJ y )NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r   emr  r0   r"   r   s     r   test_unwrapz TestTreeModification.test_unwrap  sJ    yy   	wwvv{{????r   c                     | j                  d      }|j                  j                  |j                  d            }|j	                         dk(  sJ |j	                         | j                  d      k(  sJ y )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_wrapzTestTreeModification.test_wrap  sc    yy-.  c!23||~!<<<<{{} 1 12M NNNNr   c                     | j                  d      }|j                  j                  j                  |j                         |j	                         | j                  d      k(  sJ y )Nz<b></b>I wish I was bold.rh  )r   r   r|  ri  r   r  r   s     r   %test_wrap_extracts_tag_from_elsewherez:TestTreeModification.test_wrap_extracts_tag_from_elsewhere  sM    yy45  ({{} 1 12M NNNNr   c                    | j                  d      }|j                  j                  j                  |j                         dt	        |j                  j
                        k(  sJ |j                         | j                  d      k(  sJ y )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|  ri  r(   r   r   r  r   s     r   &test_wrap_puts_new_contents_at_the_endz;TestTreeModification.test_wrap_puts_new_contents_at_the_end  sp    yyFG  (C(((({{} 1 19!
 
 	
 
r   c                    | j                  d      }t        |j                  j                        dk(  sJ |j	                  d      j                         }|j                         dk(  sJ |j                         dk(  sJ t        |j                  j                        dk(  sJ |j                  J |j                  J |j                  j                  J |j	                  d	      }|j	                  d
	      }|j                  |k(  sJ |j                  |k(  sJ |j                  |k(  sJ |j                  |k(  sJ y )NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>rU   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(   rI   r   r   r  r   r  r\  r<  r|  r  )r   r   	extracted	content_1	content_2s        r   test_extractz!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                    | j                  d      }|j                  j                  }|j                  d      }|j                  d      }|j                  j	                  |       |j
                  j	                  |       |j                          |j                          ||j                  j                  k(  sJ ||j
                  j                  k(  sJ y )Nr%   ra   rN   )r   r,   r   rA  rg   r   r  )r   r   foo_1foo_2bar_2s        r   4test_extract_distinguishes_between_identical_stringszITestTreeModification.test_extract_distinguishes_between_identical_strings  s    yy/0&&ee
 	%%%%%%r   c                     | j                  d      }|j                  d      D cg c]  }|j                  j                          c} dt	        |j
                        k(  sJ y c c}w )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{  r  r!   rI   )r   r   r  s      r   "test_extract_multiples_of_same_tagz7TestTreeModification.test_extract_multiples_of_same_tag  sW    yy 
 
 )-h(?@1			@+s499~=== 	As   !A$c                     | j                  d      }|j                  d      j                          d |j                  d      u sJ y )Nz<html>
<body>hi</body>
</html>rI   )r   r   r  r   s     r   Btest_extract_works_when_element_is_surrounded_by_identical_stringszWTestTreeModification.test_extract_works_when_element_is_surrounded_by_identical_strings  s=    yyAB		&!!#tyy((((r   c                 F   | j                  d      }|j                  }|j                  j                          t	        |j                  j
                        dk(  sJ t        |d      sJ |j                  }|j                  d       dt	        |j
                        k(  sJ y)zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>r   r   T)	decomposeN)r   r,   r0   clearr(   r   rt   re  )r   r   r,   re  s       r   
test_clearz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>)rO  r  )r  r  )ro  ru  )r  zF<div><p id="start"><a>Second <em>child</em></a></p><p>child3</p></div>)r)  ru  c                     | j                  d      }t        |j                  |      }|D ]  }|j                           ||j	                         k(  sJ y )NzU<div><em>child1</em><p id='start'><a>Second <em>child</em></a></p><p>child3</p></div>)r   getattrr0   r  r   )r   method_nameexpected_resultr   iteratorr  s         r   test_extract_during_iterationz2TestTreeModification.test_extract_during_iteration0  sS    : yyc
 466;/ 	AIIK	$++-///r   c                 <   | j                  d      }|j                  d      \  }}|j                  }|j                  j                  }||||fD ]  }d|j
                  u rJ  |j                          |||fD ]  }d|j
                  u rJ  d|j
                  u sJ y )Nz;<p><a>String <em>Italicized</em></a></p><p>Another para</p>r0   FT)r   r)   r,   re  r   
decomposedr  )r   r   r  r  r,   r"   r  s          r   test_decomposez#TestTreeModification.test_decomposeU  s    yyVWs#BDDuu||b!T" 	)AALL(((	) 	a 	(A1<<'''	( %%%r   c                     | j                  d      }|j                  }|j                  j                  }d|j                  u sJ |j                          d|j                  u sJ d|j                         k(  sJ y )Nz'<div><p>String 1</p><p>String 2</p></p>FTz!<div><p></p><p>String 2</p></div>)r   r/   r0   r   r  r  r   )r   r   r/   r"   s       r   test_decompose_stringz*TestTreeModification.test_decompose_stringe  si    yyBChhuu||'''t&&&2cjjlBBBr   c                     | j                  d      }d|j                  _        |j                  j                  dgk(  sJ d|j                  _        |j                  j                  dgk(  sJ y)zTag.string = 'string'z<a></a> <b><c></c></b>ra   rN   N)r   r,   r   r   r   r   s     r   test_string_setz$TestTreeModification.test_string_setn  sW    yy12vv5')))vv5')))r   c                     | j                  d      }|j                  j                  |j                  _        |j                  j                         dk(  sJ y )Nz<a><b>foo</b><c>bar</c>s   <a><b>bar</b><c>bar</c></a>)r   r   r   r   r,   r   r   s     r   /test_string_set_does_not_affect_original_stringzDTestTreeModification.test_string_set_does_not_affect_original_stringv  s=    yy23vv}}"@@@@r   c                     | j                  d      }t        d      }||j                  _        t	        |j                  j                  t              sJ y )Nrd   ra   )r   r   r,   r   r  )r   r   cdatas      r   )test_set_string_preserves_class_of_stringz>TestTreeModification.test_set_string_preserves_class_of_string{  s<    yy#e$&&--///r   N);rB   rC   rD   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r
  r  r  r  r  r  markparametrizer  r'  r)  r-  r5  r:  r<  r>  rD  rG  rK  rP  rV  rX  r[  rc  rf  rj  rl  rn  rt  ry  r|  r~  r  r  r  r  r  r  r  r@   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   r  rJ  rG  rh  re  r4   rK   r3   rJ   c                   P    e Zd Zej                  j                  de      d        Zy)TestDeprecatedArgumentsr  c                 &   | j                  d      }t        |j                  |      }t        j                  d      5 } |d       |\  }|j
                  t        k(  sJ t        |j                        }|dk(  sJ 	 d d d        y # 1 sw Y   y xY w)N<a>some</a><b>markup</b>Tre   rw  )r"   zOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.)	r   r  r   rh   ri   rj   rk   r!   rl   r   r  r   methodrn   ro   rp   s          r   test_find_type_method_stringz4TestDeprecatedArguments.test_find_type_method_string  s    yy34-$$D1 	Q!IW##x///goo&Cdee	 	 	s   ?BBN)rB   rC   rD   r  r  r  all_find_type_methodsr  r@   r   r   r  r    s'    [[],AB Cr   r  c                   P    e Zd Zej                  j                  de      d        Zy)TestWarningsr  c                 \   | j                  d      }t        |j                  |      }t        j                  d      5 } |d       |\  }|j
                  t        k(  sJ t        |j                  t              sJ t        |j                        }d|v sJ 	 d d d        y # 1 sw Y   y xY w)Nr  Tre   u)_classzN'_class' is an unusual attribute name and is a common misspelling for 'class_')r   r  r   rh   ri   rj   rk   r  rl   r   r!   r  s          r   test_suspicious_syntax_warningz+TestWarnings.test_suspicious_syntax_warning  s    yy34-$$D1 		Q#IW##x///goo/PQQQgoo&C`		 		 		s   AB""B+N)rB   rC   rD   r  r  r  r  r  r@   r   r   r  r    s'    [[],AB Cr   r  )$rE   r  rQ   rh   bs4r   bs4.builderr   bs4.elementr   r   r   r   r	   
bs4.filterr
   ru  r   r   rG   ry   r   r   r   r   r
  r1  r5  rX  rs  ry  r  r  r  r  r  r@   r   r   <module>r     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   