
    Eg7                        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
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     F/var/www/html/venv/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 )Nz"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   N)__name__
__module____qualname____doc__r   r   r#   r*   r-   r5   r7    r   r   r   r      s.    ,DB
)
,
@@r   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_tagsI   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.*)rF   rE      »TN)r   r)   recompiler   s     r   test_find_all_text_nodesz$TestFindAll.test_find_all_text_nodesO   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   rO   
   )rO   r   rP   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   rM   rO   foor   rP   )r   rU   r   r   s     r   %test_calling_a_tag_is_calling_findallz1TestFindAll.test_calling_a_tag_is_calling_findallf   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_recursionk   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 ResultSetr[   r,   sourceTrX   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)
r8   r9   r:   r;   rC   rJ   rV   rY   rh   rn   r<   r   r   r>   r>   F   s%    /?DT5
(
)r   r>   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">rR   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)r8   r9   r:   ru   r<   r   r   rp   rp      s    @r   rp   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.rU   rz   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rU   rz   r)   rH   rI   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   )rU   rz   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~   )rU   rz   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~   )rU   rz   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.rT   )r   r   rz   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 brP   rO   )r   r   rH   rI   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)r8   r9   r:   r;   r|   r   r   r   r   r   r   r   r   r   r   r<   r   r   rw   rw      sA    0K
T
HK






V
 r   rw   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.rT   r   rz   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>
                         name1r2   zA tag called 'name1'.r2   rs   zName match.classclass2zClass match.rT   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,   rO   class_zClass 1.r   rP   zClass 3 and 4.rR   rs   rT   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)   rH   rI   rU   )r   rz   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 NrL   r(   values    r   big_attribute_valueznTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class.<locals>.big_attribute_value/  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_value4  s    u:?"r   r   rU   r)   rH   rI   )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,   rX   rE   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_classes9  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   rs   zMatch.)r   r
   rU   r)   )r   rz   strainers      r   'test_find_all_by_attribute_soupstrainerz>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainerE  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.rT   r   s     r   $test_find_all_with_missing_attributez;TestFindAllByAttribute.test_find_all_with_missing_attributeM  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.rT   r   s     r   $test_find_all_with_defined_attributez;TestFindAllByAttribute.test_find_all_with_defined_attributeU  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   rO   rT   )r   rz   expecteds      r   $test_find_all_with_numeric_attributez;TestFindAllByAttribute.test_find_all_with_numeric_attribute]  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>)rO   rP   rR   r   rO   rP   rT   r   s     r   (test_find_all_with_list_attribute_valuesz?TestFindAllByAttribute.test_find_all_with_list_attribute_valuesf  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_valuer  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,   rX   r   rE   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,   rX   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&   rX   )r    r   r   rE   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)r8   r9   r:   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spanrO   r         abcr   12r   r&   )r   r/   r^   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)r8   r9   r:   r;   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   rz   r/   ielements        r   
test_indexzTestIndex.test_index  s    yy & ' hh#CLL1 	+JAw		'****	+]]:& 	JJqM	 	 	s   *BBN)r8   r9   r:   r;   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   rz   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   )rz   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)rz   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   )rz   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  )rz   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  parentsrt   )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_parentsrt   )r   r	  resultss      r   test_self_and_parent_generatorz3TestParentOperations.test_self_and_parent_generator  sV     **55
!dfll&: 4L
 

 >>>>
r#  r   )r8   r9   r:   r;   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>ry   r{   s    r   r|   zProximityTest.setup_method  s    II P
	r   r   r8   r9   r:   r|   r<   r   r   r)  r)    s    
r   r)  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  )superr-  r|   rz   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   )rz   r   r4  )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  )rz   r4  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   Twor8  rL   r   )rU   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   r8  r   )r  	find_nextr{   s    r   test_find_nextz!TestNextOperations.test_find_next-  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 )Nr3  r   r   r>  r8  )rz   r   rB  r   rU   r?  r  s     r   test_find_next_for_text_elementz2TestNextOperations.test_find_next_for_text_element1  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 )Nr>  r   r    rP   r8  r   r   )rz   r   next_elementsself_and_next_elements)r   r  node
successorsr   r   successors2s          r   test_next_generatorsz'TestNextOperations.test_next_generators6  s    		e,',':':;td;
;"X4yC7"""(-(D(DEtEE12*,,,1~&&& < Fs   	A:	A?r   )r8   r9   r:   r|   r5  r:  r<  r@  rC  rE  rL  __classcell__r1  s   @r   r-  r-    s.    !A).G
?G

'r   r-  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 r7  )r/  rP  r|   rz   r   endr0  s    r   r|   z#TestPreviousOperations.setup_methodD  s'    $d8:99>>>1r   c                     | j                   j                  d   dk(  sJ | j                   j                  j                  dk(  sJ y )Nr    rP   r>  )rR  previous_elementr{   s    r   test_previousz$TestPreviousOperations.test_previousH  s=    xx((.#555xx((99UBBBr   c                 V    | j                   j                  d      }|j                  J y )Nhtml)rz   r   rT  )r   r   s     r   #test_previous_of_first_item_is_nonez:TestPreviousOperations.test_previous_of_first_item_is_noneL  s&    		v&%%---r   c                 4    | j                   j                  J y r  )rz   rT  r{   s    r   test_previous_of_root_is_nonez4TestPreviousOperations.test_previous_of_root_is_noneP  s    yy))111r   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr   r8  r>  r3  r   r   r3  )rU   rR  find_all_previousr{   s    r   test_find_all_previousz-TestPreviousOperations.test_find_all_previousT  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    rP   r3  r   )rR  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 )Nr8  r   r   r\  )rz   r   r`  r   rU   r]  r  s     r   #test_find_previous_for_text_elementz:TestPreviousOperations.test_find_previous_for_text_element_  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   r3  r   )bodytagheadtagr  )rO   re  rf  r  )rz   r   r  previous_elementsself_and_previous_elements)r   r  s     r   test_previous_generatorsz/TestPreviousOperations.test_previous_generatorsd  sF    		s51 7 79XY @ @Bfgr   r   )r8   r9   r:   r|   rU  rX  rZ  r^  ra  rc  ri  rM  rN  s   @r   rP  rP  C  s/    2C.2G=R
hr   rP  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* )rH   rI   subr   rz   )r   markups     r   r|   zSiblingTest.setup_methodk  s6     H%))"f5IIf%	r   r   r+  r<   r   r   rk  rk  j  s    &r   rk  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 )NrO   r   )r/  rq  r|   rz   r   r  r0  s    r   r|   zTestNextSibling.setup_method  s&    ot13YY^^s^+
r   c                 4    | j                   j                  J y r  )rz   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   rP   1.1)r  rt  r4  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 )Nrw  r   rR   )rz   rW  rt  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   rP   rR   rP   r   )r  r  rB   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  )rO   r   rP   rR   )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>bazrF   r   r   bazrE   nonesuch)r   r   rt  r2   rU   rB   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   )r8   r9   r:   r|   ru  rx  r|  r~  r  r  r  rM  rN  s   @r   rq  rq  ~  s/    ,.6.AN
YBr   rq  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 )NrR   r   )r/  r  r|   rz   r   rR  r0  s    r   r|   z TestPreviousSibling.setup_method  s'    !45799>>S>)r   c                 4    | j                   j                  J y r  )rz   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    rP   r   z3.1)rR  r  rT  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 )Nrw  r   rO   )rz   rW  r  r   )r   rz  
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    rP   )rR  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   rP   r   rO   rO   r   )r  rR  rA   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  )rR   rP   r   rO   )r  rR  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   rF   rE   r  )r   r   r  r2   rU   rA   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   )r8   r9   r:   r|   r  r  r  r  r  r  r  rM  rN  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>r[   rX   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 )NrW  z<body></body>r   r,   olzhttp://foo.com/hrefr   r   s4   <body><a href="http://foo.com/"></a><ol></ol></body>)r   lookupr   r	   r@   insertr   )r   r   r   r,   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   r^   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>rW  headr   r   rS   rP   rR   67893456789)
r   r   r^   new_tagr2   r  insert_beforeinsert_afterextendget_text)	r   r   rW  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   rm   s        r   test_replace_tag_with_itselfz1TestTreeModification.test_replace_tag_with_itself1  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_exception9  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_exception?  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_elementsE  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_childrenQ  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   tworm  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_throughoutf  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   rT  r	  r4  )r   r   new_textr   s       r   test_replace_final_nodez,TestTreeModification.test_replace_final_nodet  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   rT  r4  r  rt  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 )Nr[   r   rE   rX   )r   r,   r  r   r4  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   r^   r   rl   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   rt  r  r   r4  rT  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,   r^   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 )Nr[   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   <lambda>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>Tr\   zIA single non-Tag item was passed into Tag.extend. Use Tag.append instead.)r   r_   r`   r   r  r/   decode_contentsra   rb   r!   rc   )	r   string_sourcerm   r   r   re   r   rf   rg   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(   r)  z$QUUX BAZ<a>foo</a>BAZ QUUX<b>bar</b>FOOz'QUUX BAZ<b>bar</b>FOO<a>foo</a>BAZ QUUX)r   r   r  r,   r   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(  r)  z<a>foo</a>QUUX<b>bar</b>BAZr*  r+  r,  r,   )r   r   r  r,   r   r  r   r   r   r  r  r  r-  s      r   test_insert_afterz&TestTreeModification.test_insert_after-  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                 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(  r1  r)  z$<a>foo</a>QUUX BAZ<b>bar</b>BAZ QUUXzFOO z(QUUX BAZ<b>bar</b><a>foo</a>FOO BAZ QUUX)r   r   r  r,   r   r  r   s     r   test_insert_multiple_afterz/TestTreeModification.test_insert_multiple_afterE  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Nrm  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_meaningQ  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r9  )r   r  r:  r   r   r   r  r;  r<  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"	# 	#		& 	&	$ 	$	# 	#r>  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   r4  rt  )r   r   rB  shows       r   test_replace_withz&TestTreeModification.test_replace_withg  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_errorst  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   r4  )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  rR  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   r4  rT  rt  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.ra  )r   r   rt  rb  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   rt  rb  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>rL   navr   z6<html><body>Some content.  More content.</body></html>z<div id="nav">Nav crap</div>r&   zSome content. r   z More content.)r   r(   r@   r   r   r  r   r	  rT  r4  rt  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%   rX   rE   )r   r,   r   r:  r^   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)   rt  r  r!   r@   )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>r@   )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   rk   r^  )r   r   r,   r^  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>)rG  r|  )r  r|  )rg  rm  )r  zF<div><p id="start"><a>Second <em>child</em></a></p><p>child3</p></div>)r!  rm  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_iteration,  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,   r^  r   
decomposedry  )r   r   r  r  r,   r"   r   s          r   test_decomposez#TestTreeModification.test_decomposeQ  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  ry  r   )r   r   r/   r"   s       r   test_decompose_stringz*TestTreeModification.test_decompose_stringa  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>rX   rE   N)r   r,   r   r   r   r   s     r   test_string_setz$TestTreeModification.test_string_setj  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_stringr  s=    yy23vv}}"@@@@r   c                     | j                  d      }t        d      }||j                  _        t	        |j                  j                  t              sJ y )Nr[   rX   )r   r   r,   r   r  )r   r   cdatas      r   )test_set_string_preserves_class_of_stringz>TestTreeModification.test_set_string_preserves_class_of_stringw  s<    yy#e$&&--///r   N);r8   r9   r:   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&  r.  r3  r5  r7  r=  r@  rD  rI  rO  rQ  rT  r\  r_  rc  re  rg  rm  rr  ru  rw  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  rB  r?  r`  r]  r4   rB   r3   rA   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>Tr\   ro  )r"   zOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.)	r   r~  r   r_   r`   ra   rb   r!   rc   r   r  r   methodre   rf   rg   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)r8   r9   r:   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  Tr\   u)_classzN'_class' is an unusual attribute name and is a common misspelling for 'class_')r   r~  r   r_   r`   ra   rb   r  rc   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)r8   r9   r:   r   r  r  r  r  r<   r   r   r  r    s'    [[],AB Cr   r  )$r;   r   rH   r_   bs4r   bs4.builderr   bs4.elementr   r   r   r   r	   
bs4.filterr
   rm  r   r   r>   rp   rw   r   r   r   r  r)  r-  rP  rk  rq  r  r  r  r  r  r<   r   r   <module>r     s     	   (  $
%@x %@P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   