
    ,hP                       d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
mZ ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ  e
j2                  d      duZ e
j2                  d	      du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( d)e      Z+ G d* d+e      Z, G d, d-e      Z- G d. d/e      Z. G d0 d1e      Z/ G d2 d3e      Z0 G d4 d5e      Z1 G d6 d7e      Z2 G d8 d9e      Z3 G d: d;e      Z4 G d< d=e      Z5y)>a8  Tests for Beautiful Soup's tree traversal methods.

The tree traversal methods are the main advantage of using Beautiful
Soup over just using a parser.

Different parsers will build different Beautiful Soup trees given the
same markup, but all Beautiful Soup trees can be traversed with the
methods tested here.
    )	set_traceN)BeautifulSoup)builder_registryHTMLParserTreeBuilder)	PY3KCDataCommentDeclarationDoctype	FormatterNavigableStringSoupStrainerTag)SoupTestskipIfxmllxmlc                       e Zd Zd Zd Zy)TreeTestc                 b    | j                  |D cg c]  }|j                   c}|       yc c}w )zMake sure that the given tags have the correct text.

        This is used in tests that define a bunch of tags, each
        containing a single string, and then select certain strings by
        some mechanism.
        N)assertEqualstringselftagsshould_matchtags       U/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/bs4/tests/test_tree.pyassertSelectszTreeTest.assertSelects+   s&     	5#**5|D5s   ,c                 T    | j                  |D cg c]  }|d   	 c}|       yc c}w )zMake sure that the given tags have the correct IDs.

        This is used in tests that define a bunch of tags, each
        containing a single string, and then select certain strings by
        some mechanism.
        idN)r   r   s       r   assertSelectsIDszTreeTest.assertSelectsIDs4   s&     	t4#d)4lC4s   %N)__name__
__module____qualname__r   r"        r   r   r   )   s    EDr'   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)TestFindzBasic tests of the find() method.

    find() just calls find_all() with limit=1, so it's not tested all
    that thouroughly here.
    c                 |    | j                  d      }| j                  |j                  d      j                  d       y )Nz <a>1</a><b>2</b><a>3</a><b>4</b>b2)soupr   findr   r   r-   s     r   test_find_tagzTestFind.test_find_tagE   s/    yy;<3..4r'   c                 j    | j                  d      }| j                  |j                  d      d       y )Nu   <h1>Räksmörgås</h1>   Räksmörgåsr   )r-   r   r.   r/   s     r   test_unicode_text_findzTestFind.test_unicode_text_findI   s,    yy12/:OLr'   c                     | j                  d      }t        |       | j                  d|j                  d      j                         y )Nu&   <h1 id="Räksmörgås">here it is</h1>z
here it isr2   r!   )r-   strr   r.   textr/   s     r   test_unicode_attribute_findz$TestFind.test_unicode_attribute_findM   s9    yyABD	tyyOy'D'I'IJr'   c                 x    | j                  d      }| j                  dt        |j                                      y)z)Test an optimization that finds all tags.<a>foo</a><b>bar</b>   Nr-   r   lenfind_allr/   s     r   test_find_everythingzTestFind.test_find_everythingS   s,    yy/0C01r'   c                 z    | j                  d      }| j                  dt        |j                  d                   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_nameX   s/    yy9:Cc 234r'   N)	r#   r$   r%   __doc__r0   r4   r9   r@   rC   r&   r'   r   r)   r)   >   s"    5MK2
5r'   r)   c                   .    e 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      }| j                  |j                  d      dg       | j                  |j                  d      dg       | j                  |j                  ddg      ddg       | j                  |j                  t        j                  d            g d       | j                  |j                  d      g d       y	)
z'You can search the tree for text nodes.u   <html>Foo<b>bar</b>»</html>barr3   r8   Fooz.*)rJ   rH      »TN)r-   r   r?   recompiler/   s     r   test_find_all_text_nodesz$TestFindAll.test_find_all_text_nodes`   s    yy9:e4ug>E2UG<MMu~M.	@ 	BJJt,<=/	1 	D1/	1r'   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>rB      limit)1r,   3   rS   
   )rS   r,   rT   45r   Nr-   r   r?   r/   s     r   test_find_all_limitzTestFindAll.test_find_all_limitp   s    yyCD4==A=6H4==A=6>MM#RM(*C	E 	MM#QM')B	Dr'   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>rB   rU   rQ   rS   foor6   rT   )r-   r   r+   r/   s     r   %test_calling_a_tag_is_calling_findallz1TestFindAll.test_calling_a_tag_is_calling_findall|   sG    yy<=41-u5466U6+cU3r'   c                     | j                  d      }g }|j                  |       | j                  g |j                  |             y N<a></a>)r-   appendr   r?   )r   r-   ls      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_recursion   s;    yy#	 	T]]1-.r'   c                 0   | j                  d      }|j                  d      }| j                  t        |d             |j                  d      }| j                  t        |d             |j                  d      }| j                  t        |d             y)z%All find_all calls return a ResultSetr`   rB   sourceTr\   rI   N)r-   r?   
assertTruehasattr)r   r-   results      r   test_find_all_resultsetz#TestFindAll.test_find_all_resultset   su    yy#s#12t$12E*12r'   N)	r#   r$   r%   rD   rN   rZ   r]   rc   ri   r&   r'   r   rF   rF   ]   s    /1 
D4
/
3r'   rF   c                       e Zd Zd Zy)TestFindAllBasicNamespacesc                     | j                  d      }| j                  d|j                  d      j                         | j                  d|j                  ddi      j                         y )Nz0<mathml:msqrt>4</mathml:msqrt><a svg:fill="red">rW   zmathml:msqrtrB   zsvg:fillredattrs)r-   r   r.   r   namer/   s     r   test_find_by_namespaced_namez7TestFindAllBasicNamespaces.test_find_by_namespaced_name   sV    yyKLdii7>>?diie/EiFKKLr'   N)r#   r$   r%   rq   r&   r'   r   rk   rk      s    Mr'   rk   c                   ^     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z xZS )TestFindAllByNamez&Test ways of finding tags by tag name.c                 V    t         t        |           | j                  d      | _        y )Nz<a>First tag.</a>
                                  <b>Second tag.</b>
                                  <c>Third <a>Nested tag.</a> tag.</c>superr   setUpr-   treer   	__class__s    r   rw   zTestFindAllByName.setUp   s'    h#%YY  J K	r'   c                 ^    | j                  | j                  j                  d      ddg       y NrB   
First tag.Nested tag.r   rx   r?   r   s    r   test_find_all_by_tag_namez+TestFindAllByName.test_find_all_by_tag_name   s*    IIs#lM%B	Dr'   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 )NrB   r}   rI   Tr~   r   r   rx   r?   rL   rM   r   s    r   test_find_all_by_name_and_textz0TestFindAllByName.test_find_all_by_name_and_text   s    IIs6	H 	IIs.}0M	O 	IIsE):;=)	+r'   c                 p    | j                  | j                  j                  j                  d      dg       y )NrB   r~   )r   rx   cr?   r   s    r   !test_find_all_on_non_root_elementz3TestFindAllByName.test_find_all_on_non_root_element   s'    499;;//4}oFr'   c                 J    | j                  | j                  d      ddg       y r|   )r   rx   r   s    r   %test_calling_element_invokes_find_allz7TestFindAllByName.test_calling_element_invokes_find_all   s    499S>L-+HIr'   c                 p    | j                  | j                  j                  t        d            ddg       y r|   )r   rx   r?   r   r   s    r   test_find_all_by_tag_strainerz/TestFindAllByName.test_find_all_by_tag_strainer   s/    II|C01=)	+r'   c                 b    | j                  | j                  j                  ddg      g d       y )NrB   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*8	:r'   c                 d    | j                  | j                  j                  ddd      g d       y )NT)rB   r+   r   r   r   s    r   test_find_all_by_tag_dictz+TestFindAllByName.test_find_all_by_tag_dict   s*    IId$78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!   )rp   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.rY   )r   r   rx   s      r   'test_find_all_with_tags_matching_methodz9TestFindAllByName.test_find_all_with_tags_matching_method   s@    	- yy 6 7 	MM/*Z,D	Fr'   c                    | j                  d      }|j                  dd      }|j                  dt        j                  d            }|j	                  dddg      \  }}| j                  d|j                         | j                  d|j                         | j                  d|j                         | j                  d|j                         y )NzH<div class='a b'>1</div><div class='a c'>2</div><div class='a d'>3</div>divza dza brT   rS   )r-   r.   rL   rM   r?   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'   )r#   r$   r%   rD   rw   r   r   r   r   r   r   r   r   r   r   __classcell__rz   s   @r   rs   rs      sB    0KD
	+GJ+
:
:
:
F
)r'   rs   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>firstr6   zMatching a.zMatching b.rY   r   rx   s     r   test_find_all_by_attribute_namez6TestFindAllByAttribute.test_find_all_by_attribute_name   s<     yy ! "
 	4==G=4)=9	;r'   c                    dj                  d      }dj                  d      }| j                  |      }| j                  |j                  g|j	                  |             | j                  |j                  g|j	                  |j                  d                   | j                  |j                  g|j	                  |dg             y )Nu   םולשutf8u   <a title="םולש"></a>)titlezsomething else)encoder-   r   rB   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$&&4==u=#=>$&&4==u||F7K=#LM$&&4==?O7P=#QRr'   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rp   zA tag called 'name1'.rp   rn   zName match.classclass2zClass match.rY   r   s     r   test_find_all_by_attribute_dictz6TestFindAllByAttribute.test_find_all_by_attribute_dict  s     yy   	4==g=634	6 	4==/A=B)?	, 	4==(/C=D*+	-r'   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>
                         rB   rS   class_zClass 1.r   rT   zClass 3 and 4.rW   rn   rY   r   s     r   test_find_all_by_classz-TestFindAllByAttribute.test_find_all_by_class  s    yy   	4==S=9J<H4==S=9<L;MN4==S=9<L;MN 	4==c2ZLA4==s=3j*5MN4==c25E4FG4==c25E4FGr'   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 itrB   zo b)r-   r?   rL   rM   r   )r   rx   fs      r   0test_find_by_class_when_multiple_classes_presentzGTestFindAllByAttribute.test_find_by_class_when_multiple_classes_present-  s    yy>?MM%

3M81zl+MM%

3M81zl+ MM%

5(9M:1zl+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>rB   bar   c                     t        |       dkD  S NrP   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_valueE  s    u:?"r'   r-   r   r?   rL   rM   )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4==bjj.>?*N	" 	4==.ABBG	# 	MM#45
|	Er'   c                    | j                  d      }|j                  d      \  }}| j                  ||g|j                  dd             | j                  |g|j                  dd             | j                  |g|j                  dd             | j                  |g|j                  dd             | j                  g |j                  dd             y )Nz*<a class="foo bar"></a><a class="foo"></a>rB   r\   rH   zfoo barr   zbar foo)r-   r?   r   )r   r-   rB   a2s       r   :test_find_all_with_string_for_attrs_finds_multiple_classeszQTestFindAllByAttribute.test_find_all_with_string_for_attrs_finds_multiple_classesK  s    yyEFc"2!R$--U";<!dmmC78 	!dmmC	mBC!dmmC;<T]]3	:;r'   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   rn   zMatch.)r-   r   r   r?   )r   rx   strainers      r   'test_find_all_by_attribute_soupstrainerz>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainerW  sA    yy : ;  tg&674==2XJ?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>rB   r6   zNo ID present.rY   r   s     r   $test_find_all_with_missing_attributez;TestFindAllByAttribute.test_find_all_with_missing_attribute_  s:     yy 9 : 	4===69I8JKr'   c                 n    | j                  d      }| j                  |j                  d      ddg       y )Nr   Tr6   zID present.zID is empty.rY   r   s     r   $test_find_all_with_defined_attributez;TestFindAllByAttribute.test_find_all_with_defined_attributeg  s=     yy 9 : 	MMTM"]N$C	Er'   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.rU   r6   rS   rY   )r   rx   expecteds      r   $test_find_all_with_numeric_attributez;TestFindAllByAttribute.test_find_all_with_numeric_attributep  sY    yy ? @ *+>?4==A=.94==C=0(;r'   c                 r    | j                  d      }| j                  |j                  g d      ddg       y )Nz<a id="1">1</a>
                            <a id="2">2</a>
                            <a id="3">3</a>
                            <a>No ID.</a>)rS   rT   rW   r6   rS   rT   rY   r   s     r   (test_find_all_with_list_attribute_valuesz?TestFindAllByAttribute.test_find_all_with_list_attribute_valuesy  s;     yy - . 	4==O=<:	'r'   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+$r6   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_value  sE     yy - . 	4==BJJv,>=?$i0	2r'   c                    | j                  d      }|j                  }| j                  |g|j                  dd             | j                  g |j                  dd             | j                  g |j                  dd             y )Nz<b>foo</b><b>bar</b><a>foo</a>rB   r\   rI   rH   r-   rB   r   r?   r   r-   rB   s      r   'test_find_by_name_and_containing_stringz>TestFindAllByAttribute.test_find_by_name_and_containing_string  ss    yy9:FF!dmmCem<=T]]3U];<T]]3U];<r'   c                     | j                  d      }| j                  |j                  d      |j                  dd             y )Nz"<a>foo</a><a><b><c>foo</c></b></a>rB   r\   rI   )r-   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  s7    yy=>s+T]]3U]-KLr'   c                     | j                  d      }|j                  }| j                  |g|j                  dd             | j                  g |j                  dd             y )Nz"<b id="1">foo</b><a id="2">foo</a>r<   r\   )r!   r8   rU   rH   r   r   s      r   ,test_find_by_attribute_and_containing_stringzCTestFindAllByAttribute.test_find_by_attribute_and_containing_string  sV    yy=>FF!dmmqum=>T]]ae]<=r'   N)r#   r$   r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r'   r   r   r      sY    	;S-*H(,E 
<@LE<'2=M>r'   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                  |       | j                  d |j                  j                         | j                  d
t        |j                               |j                          | j                  dt        |j                               | j                  d|j                  d          | j                  d|j                  j                         | j                  d|j                  d          | j                  d|j                  d          y )Nz<div>a</div>r+   r   z	Comment 1z	Comment 2dspanrS   r,         abcr   12rU   r<   )r-   r   ra   r	   default_builderr   r   r   r   r>   contentssmooth)r   r-   r   builderr   s        r   test_smoothzTestSmooth.test_smooth  sW   yy(hh

3

3

7;'(

7;'(

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

4 	sxx/C-.

C-.
 	Q0 	sxx/
 	cll1o6cll1o6r'   N)r#   r$   r%   rD   r   r&   r'   r   r   r     s
    &7r'   r   c                       e Zd ZdZd Zy)	TestIndexzTest Tag.indexc                     | j                  d      }|j                  }t        |j                        D ]&  \  }}| j	                  ||j                  |             ( | j                  t        |j
                  d       y )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>rU   )r-   r   	enumerater   r   indexassertRaises
ValueError)r   rx   r   ielements        r   
test_indexzTestIndex.test_index  sk    yy & ' hh#CLL1 	4JAwQ		' 23	4*djj!4r'   N)r#   r$   r%   rD   r   r&   r'   r   r   r     s
    5r'   r   c                   R     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Z xZS )TestParentOperationsz;Test navigation and searching through an element's parents.c                     t         t        |           | j                  d      | _        | j                  j
                  | _        y )Na1  <ul id="empty"></ul>
                                 <ul id="top">
                                  <ul id="middle">
                                   <ul id="bottom">
                                    <b>Start here</b>
                                   </ul>
                                  </ul>)rv   r   rw   r-   rx   r+   startry   s    r   rw   zTestParentOperations.setUp  s7    "D/1II + ,	 YY[[
r'   c                 6   | j                  | j                  j                  d   d       | j                  | j                  j                  j                  d   d       | j                  | j                  j                  j                  j                  d   d       y )Nr!   bottommiddletop)r   r   parentr   s    r   test_parentz TestParentOperations.test_parent  sq    **40(;**11$7B**1188>Fr'   c                     | j                   j                  d   }| j                  |j                  | j                          y )Nr   )rx   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'3r'   c                 P    | j                  d | j                  j                         y N)r   rx   r  r   s    r   test_soup_object_has_no_parentz3TestParentOperations.test_soup_object_has_no_parent  s    tyy//0r'   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  dd      dg       y )Nulr  r  r  r  r6   )r"   r   find_parentsr   s    r   test_find_parentsz&TestParentOperations.test_find_parents  sP    JJ##D)+F	HJJ##DX#6
	Dr'   c                     | j                  | j                  j                  d      d   d       | j                  | j                  j                  dd      d   d       y )Nr  r!   r  r  r6   )r   r   find_parentr   s    r   test_find_parentz%TestParentOperations.test_find_parent  sO    //5d;XF///?EuMr'   c                     | j                   j                  d      }| j                  |j                  j                  d       y )N
Start hererI   r+   )rx   r.   r   r  rp   r   r8   s     r   test_parent_of_text_elementz0TestParentOperations.test_parent_of_text_element  s0    yy~~<~0))3/r'   c                     | j                   j                  d      }| j                  |j                  d      d   d       y )Nr  rI   r  r!   r  )rx   r.   r   r  r  s     r   test_text_element_find_parentz2TestParentOperations.test_text_element_find_parent  s6    yy~~<~0))$/5x@r'   c                     | j                   j                  D cg c]  }|d|j                  v r|d    }}| j                  |g d       y c c}w )Nr!   r  )r   parentsro   r   )r   r  r  s      r   test_parent_generatorz*TestParentOperations.test_parent_generator  sW    .2jj.@.@ CF(TV\\-A $< C C"=>Cs   A)r#   r$   r%   rD   rw   r  r	  r  r  r  r  r  r  r   r   s   @r   r   r     s7    E	!G
41DN0A?r'   r   c                        e Zd Z fdZ xZS )ProximityTestc                 V    t         t        |           | j                  d      | _        y )Nzg<html id="start"><head></head><body><b id="1">One</b><b id="2">Two</b><b id="3">Three</b></body></html>ru   ry   s    r   rw   zProximityTest.setUp  s$    h#%IIuw	r'   r#   r$   r%   rw   r   r   s   @r   r  r    s    w wr'   r  c                   H     e Zd Z 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  )rv   r#  rw   rx   r+   r   ry   s    r   rw   zTestNextOperations.setUp  s      $-/YY[[
r'   c                     | j                  | j                  j                  d       | j                  | j                  j                  j                  d   d       y )NOner!   r,   )r   r   next_elementr   s    r   	test_nextzTestNextOperations.test_next#  sA    00%800==dCSIr'   c                 t    | j                   j                  d      }| j                  |j                  d        y NThreerI   )rx   r.   r   r'  )r   lasts     r   test_next_of_last_item_is_nonez1TestNextOperations.test_next_of_last_item_is_none'  s,    yy~~7~+**D1r'   c                 P    | j                  | j                  j                  d        y r  )r   rx   r'  r   s    r   test_next_of_root_is_nonez,TestNextOperations.test_next_of_root_is_none+  s    //6r'   c                     | j                  | j                  j                  d      ddg       | j                  j                  d       | j                  | j                  j                  d      dg       y )Nr+   Twor+  rP   r6   )r   r   find_all_nextr   s    r   test_find_all_nextz%TestNextOperations.test_find_all_next/  s_    4::33C85':JK

  A &4::33q39G9Er'   c                     | j                  | j                  j                  d      d   d       | j                  | j                  j                  d      d       y )Nr+   r!   r,   r+  rI   )r   r   	find_nextr   s    r   test_find_nextz!TestNextOperations.test_find_next4  sH    --c248#>--7-;WEr'   c                     | j                   j                  d      }| j                  |j                  d      j                  d       | j                  |j                  d      ddg       y )Nr&  rI   r+   r1  r+  )rx   r.   r   r5  r   r   r2  r  s     r   test_find_next_for_text_elementz2TestNextOperations.test_find_next_for_text_element8  sU    yy~~5~),33U;4--c2UG4DEr'   c                     | j                   j                  d      }|j                  D cg c]  }| }}|\  }}| j                  |d   d       | j                  |d       y c c}w )Nr1  rI   r!   rT   r+  )rx   r.   next_elementsr   )r   r   node
successorsr   r   s         r   test_next_generatorz&TestNextOperations.test_next_generator=  sa    		E*',':':;td;
;"XTC(7+	 <s   	A#)r#   r$   r%   rw   r(  r-  r/  r3  r6  r8  r=  r   r   s   @r   r#  r#    s/    !J27F
FF
,r'   r#  c                   H     e Zd Z 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*  )rv   r?  rw   rx   r.   endry   s    r   rw   zTestPreviousOperations.setUpG  s'    $d1399>>w>/r'   c                     | j                  | j                  j                  d   d       | j                  | j                  j                  j                  d       y )Nr!   rT   r1  )r   rA  previous_elementr   s    r   test_previousz$TestPreviousOperations.test_previousK  sA    2248#>22CCUKr'   c                 r    | j                   j                  d      }| j                  |j                  d        y )Nhtml)rx   r.   r   rC  )r   r   s     r   #test_previous_of_first_item_is_nonez:TestPreviousOperations.test_previous_of_first_item_is_noneO  s*    		v&//6r'   c                      y r  r&   r   s    r   test_previous_of_root_is_nonez4TestPreviousOperations.test_previous_of_root_is_noneS  s     	r'   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr+   r+  r1  r&  rU   r6   r&  )r   rA  find_all_previousr   s    r   test_find_all_previousz-TestPreviousOperations.test_find_all_previousY  sL     	HH&&s+-D	F488555;eWEr'   c                     | j                  | j                  j                  d      d   d       | j                  | j                  j                  d      d       y )Nr+   r!   rT   r&  rI   )r   rA  find_previousr   s    r   test_find_previousz)TestPreviousOperations.test_find_previousa  sH    //4T:C@//U/;UCr'   c                     | j                   j                  d      }| j                  |j                  d      j                  d       | j                  |j                  d      g d       y )Nr+  rI   r+   rK  )rx   r.   r   rO  r   r   rL  r  s     r   #test_find_previous_for_text_elementz:TestPreviousOperations.test_find_previous_for_text_elemente  sW    yy~~7~+++C077A""3')@	Br'   c                 X   | j                   j                  d      }|j                  D cg c]  }| }}|\  }}}}| j                  |d   d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       y c c}w )Nr&  rI   r!   rS   bodyheadrF  )rx   r.   previous_elementsr   rp   )r   r   r;  predecessorsr+   rT  rU  rF  s           r   test_previous_generatorz.TestPreviousOperations.test_previous_generatork  s    		E*).)@)@AAA +4t4#&F+F+F+ Bs   	B')r#   r$   r%   rw   rD  rG  rI  rM  rP  rR  rX  r   r   s   @r   r?  r?  E  s/    0L7FDB
,r'   r?  c                        e Zd Z fdZ xZS )SiblingTestc                     t         t        |           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* )rv   rZ  rw   rL   rM   subr-   rx   )r   markuprz   s     r   rw   zSiblingTest.setUpz  sD    k4&( H%))"f5IIf%	r'   r!  r   s   @r   rZ  rZ  x  s    & &r'   rZ  c                   B     e Zd Z f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 )NrS   r6   )rv   r`  rw   rx   r.   r   ry   s    r   rw   zTestNextSibling.setUp  s&    ot*,YY^^s^+
r'   c                 P    | j                  | j                  j                  d        y r  )r   rx   next_siblingr   s    r   !test_next_sibling_of_root_is_nonez1TestNextSibling.test_next_sibling_of_root_is_none  s    //6r'   c                    | j                  | j                  j                  d   d       | j                  | j                  j                  j                  d   d       | j                  | j                  j                  d   d       y )Nr!   r,   rT   1.1)r   r   rc  r'  r   s    r   test_next_siblingz!TestNextSibling.test_next_sibling  sg    006<00==dCSI 	006>r'   c                 D   | j                  | j                  j                  j                  d        | j                  j	                  d      }| j                  |j                  d        | j                  j	                  d      }| j                  |j                  d        y )Nrf  r6   rW   )r   rx   rF  rc  r.   )r   nested_span	last_spans      r   test_next_sibling_may_not_existz/TestNextSibling.test_next_sibling_may_not_exist  st    44d;iinnn.1148IINNcN*	//6r'   c                 `    | j                  | j                  j                  d      d   d       y )Nr   r!   r,   )r   r   find_next_siblingr   s    r   test_find_next_siblingz&TestNextSibling.test_find_next_sibling  s&    55f=dCSIr'   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr   )r,   rT   rW   rT   r6   )r"   r   find_next_siblingsr   s    r   test_next_siblingsz"TestNextSibling.test_next_siblings  sJ    djj;;FC-	/ 	djj;;s;CcUKr'   c                    | j                  d      }|j                  d      }| j                  |j                  j                  d       | j                  |j                  j                  d       | j                  |j                  d      dg       | j                  |j                  d      d       | j                  |j                  d      d        y )NFoo<b>bar</b>bazrJ   rI   r+   bazrH   nonesuch)r-   r.   r   rc  rp   r   rp  rm  r   r-   r   s      r   "test_next_sibling_for_text_elementz2TestNextSibling.test_next_sibling_for_text_element  s    yy+,		u	%++00#6++88%@533C85'B00e0<eD00j0A4Hr'   )r#   r$   r%   rw   rd  rg  rk  rn  rq  rw  r   r   s   @r   r`  r`    s)    ,7?7JLIr'   r`  c                   B     e Zd Z f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 )NrW   r6   )rv   ry  rw   rx   r.   rA  ry   s    r   rw   zTestPreviousSibling.setUp  s'    !4.099>>S>)r'   c                 P    | j                  | j                  j                  d        y r  )r   rx   previous_siblingr   s    r   %test_previous_sibling_of_root_is_nonez9TestPreviousSibling.test_previous_sibling_of_root_is_none  s    33T:r'   c                    | j                  | j                  j                  d   d       | j                  | j                  j                  j                  d   d       | j                  | j                  j                  d   d       y )Nr!   rT   r,   z3.1)r   rA  r|  rC  r   s    r   test_previous_siblingz)TestPreviousSibling.test_previous_sibling  sg    2248#>22CCDI3O 	2248%@r'   c                 D   | j                  | j                  j                  j                  d        | j                  j	                  d      }| j                  |j                  d        | j                  j	                  d      }| j                  |j                  d        y )Nrf  r6   rS   )r   rx   rF  r|  r.   )r   ri  
first_spans      r   #test_previous_sibling_may_not_existz7TestPreviousSibling.test_previous_sibling_may_not_exist  st    88$?iinnn.55t<YY^^s^+
44d;r'   c                 `    | j                  | j                  j                  d      d   d       y )Nr   r!   rT   )r   rA  find_previous_siblingr   s    r   test_find_previous_siblingz.TestPreviousSibling.test_find_previous_sibling  s&    77?EsKr'   c                     | j                  | j                  j                  d      g d       | j                  | j                  j                  d      dg       y )Nr   )rT   r,   rS   rS   r6   )r"   rA  find_previous_siblingsr   s    r   test_previous_siblingsz*TestPreviousSibling.test_previous_siblings  sJ    dhh==fE-	/ 	dhh===EuMr'   c                    | j                  d      }|j                  d      }| j                  |j                  j                  d       | j                  |j                  j                  d       | j                  |j                  d      dg       | j                  |j                  d      d       | j                  |j                  d      d        y )Nrs  rt  rI   r+   rJ   rH   ru  )r-   r.   r   r|  rp   r   r  r  rv  s      r   &test_previous_sibling_for_text_elementz:TestPreviousSibling.test_previous_sibling_for_text_element  s    yy+,		u	%//44c://@@%H577<ugF44%4@%H44*4EtLr'   )r#   r$   r%   rw   r}  r  r  r  r  r  r   r   s   @r   ry  ry    s*    *;A<LNMr'   ry  c                       e Zd Zd Zy)TestTagc                 |   | j                  d      j                  d      }d |_        | j                  d|j	                  d             dg|_        | j                  d|j	                  d             | j                  d|j	                  d              ddg|_        | j                  d|j	                  d             y )Nr\  a_tagTr   some_other_tagrU   F)r-   new_tag_preserve_whitespace_tagsr   _should_pretty_printpreserve_whitespace_tags)r   r   s     r   test__should_pretty_printz!TestTag.test__should_pretty_print  s    iim##G, )-%s77:; )9'9$s77:; 	 8 8 >? )9''B$ 8 8 ;<r'   N)r#   r$   r%   r  r&   r'   r   r  r    s    =r'   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)TestTagCreationz$Test the ability to create new tags.c                 N   | j                  d      }|j                  ddddi      }| j                  t        |t                     | j                  d|j                         | j                  t        dd      |j                         | j                  d |j                         y )Nr\  r\   rt  rp   za name)rH   ro   )rH   rp   )
r-   r  rf   
isinstancer   r   rp   dictro   r  )r   r-   r  s      r   test_new_tagzTestTagCreation.test_new_tag  s~    yy},,u%7I,J
7C01-%h7Gw~~.r'   c                    t         rnt        dd      }|j                  d      }|j                  d      }| j                  d|j	                                | j                  d|j	                                t        dd      }|j                  d      }|j                  d      }| j                  d|j	                                | j                  d|j	                                y )	Nr\  zlxml-xmlbrps   <br/>s   <p/>html.parsers   <p></p>)XML_BUILDER_PRESENTr   r  r   r   )r   xml_soupxml_brxml_p	html_souphtml_brhtml_ps          r   1test_tag_inherits_self_closing_rules_from_builderzATestTagCreation.test_tag_inherits_self_closing_rules_from_builder
  s    $R4H%%d+F$$S)E Xv}}7Welln5!"m4	##D)""3' 	7>>#34V]]_5r'   c                     | j                  d      }|j                  d      }| j                  d|       | j                  t	        |t
                     y Nr\  r\   )r-   
new_stringr   rf   r  r   r   r-   ss      r   'test_new_string_creates_navigablestringz7TestTagCreation.test_new_string_creates_navigablestring  s@    yy}OOE""
1o67r'   c                     | j                  d      }|j                  dt              }| j                  d|       | j	                  t        |t                     y r  )r-   r  r	   r   rf   r  r  s      r   3test_new_string_can_create_navigablestring_subclasszCTestTagCreation.test_new_string_can_create_navigablestring_subclass$  sB    yy}OOE7+"
1g./r'   N)r#   r$   r%   rD   r  r  r  r  r&   r'   r   r  r     s    ./6(80r'   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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+y*)+TestTreeModificationc                    | j                  d      }d|j                  d<   | j                  |j                         | j	                  d             |j                  d= | j                  |j                         | j	                  d             d|j                  d<   | j                  |j                         | j	                  d             y )	Nz<a id="1"></a>r<   r!   z<a id="2"></a>r`   r\   id2z<a id2="foo"></a>)r-   rB   r   r   document_forr/   s     r   test_attribute_modificationz0TestTreeModification.test_attribute_modification,  s    yy)*t(9(9:J(KLFF4L(9(9)(DEu(9(9:M(NOr'   c                 `    t        j                  d             }| j                  d|      }t        ||d      }t        ||d      }d|d<   |j                  j                  d|       |j                  j                  d	|       | j                  |j                  j                         d
       y )NrF  z<body></body>r   rB   olzhttp://foo.com/hrefr   rU   s4   <body><a href="http://foo.com/"></a><ol></ol></body>)r   lookupr-   r   rT  insertr   r   )r   r   r-   rB   r  s        r   test_new_tag_creationz*TestTreeModification.test_new_tag_creation5  s    1"))&13yy'y:gs#w%%&			A		BIIC	Er'   c                 R   d}| j                  |      }|j                  d      }|j                  }|j                  d      j                  |j                         | j	                  |j
                  |       | j	                  |j                         | j                  d             y )NzT<p id="1">Don't leave me <b>here</b>.</p>
                <p id="2">Don't leave!</p>r,   r6   zD<p id="1">Don't leave me .</p>
<p id="2">Don't leave!<b>here</b></p>)r-   r.   r+   ra   r   r  r   r  )r   docr-   second_parabolds        r   !test_append_to_contents_moves_tagz6TestTreeModification.test_append_to_contents_moves_tagA  s    /yy~ii3i'vv 			S	  ( 	k2KKM4,,9:	;r'   c                     d}| j                  |      }|j                  }|j                  |j                        }| j	                  ||       y )Nz<a></a><b><c></c></b>)r-   rB   replace_withr   r   r   r8   r-   rB   new_as        r   1test_replace_with_returns_thing_that_was_replacedzFTestTreeModification.test_replace_with_returns_thing_that_was_replacedS  s?    &yyFFtvv&E"r'   c                     d}| j                  |      }|j                  }|j                         }| j                  ||       y )N<a><b></b><c></c></a>)r-   rB   unwrapr   r  s        r   +test_unwrap_returns_thing_that_was_replacedz@TestTreeModification.test_unwrap_returns_thing_that_was_replacedZ  s8    &yyFF
E"r'   c                 ,   | j                  d      }|j                  }|j                          | j                  d |j                         | j                  t        |j                         | j                  t        |j                  |j                         y )Nz<a><b>Foo</b></a><c>Bar</c>)
r-   rB   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_parenta  se    yy67FF			qxx(*ahh/*anndff=r'   c                     d}| j                  |      }|j                  }|j                  j                  |       | j                  |j	                         | j                  |             y )Nz-<a><b></b><c>Foo<d></d></c></a><a><e></e></a>)r-   r   r  r   r   r  )r   r8   r-   r   s       r   test_replace_tag_with_itselfz1TestTreeModification.test_replace_tag_with_itselfi  sP    >yyFFA(9(9$(?@r'   c                     d}| j                  |      }| j                  t        |j                  j                  |j
                         y N<a><b></b></a>)r-   r   r   r+   r  rB   r   r8   r-   s      r   1test_replace_tag_with_its_parent_raises_exceptionzFTestTreeModification.test_replace_tag_with_its_parent_raises_exceptionp  s4    yy*dff&9&9466Br'   c                     d}| j                  |      }| j                  t        |j                  j                  d|j                         y )Nr  r   )r-   r   r   rB   r  r  s      r   ,test_insert_tag_into_itself_raises_exceptionzATestTreeModification.test_insert_tag_into_itself_raises_exceptionu  s4    yy*dffmmQ?r'   c                    | j                  d      }d}| j                  |      }|j                  d|       |j                  D ]  }t        |t              sJ  t        |j                        \  }}}}| j                  d|j                         | j                  d|j                         | j                  d|j                         | j                  d|j                         y)	zInserting one BeautifulSoup object into another actually inserts all
        of its children -- you'll never combine BeautifulSoup objects.
        z-<p>And now, a word:</p><p>And we're back.</p>z<p>p2</p><p>p3</p>rU   zAnd now, a word:p2p3zAnd we're back.N)	r-   r  descendantsr  r   listchildrenr   r   )	r   r-   r8   	to_insertr   p1r  r  p4s	            r   1test_insert_beautifulsoup_object_inserts_childrenzFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrenz  s     yyHI#IIdO	Ay!!! 	4A!!]33	4 dmm,BB+RYY7ryy)ryy)*BII6r'   c                 .   | j                  d      }|j                  }|j                  d   }|j                  dd       |j                  \  }}|j	                  d       |j	                  d       | j                  d|j                  j                         y )Nz<p><a>one</a><b>three</b></p>r   rU   twor\  three)r-   rB   r   r  replaceWithr   r+   r   )r   r-   rB   r+   leftrights         r   3test_replace_with_maintains_next_element_throughoutzHTestTreeModification.test_replace_with_maintains_next_element_throughout  sz    yy89FFJJqM	E jje" 	$&&--0r'   c                    | j                  d      }|j                  d      j                  d       |j                  d      }|j                  }| j	                  |j
                  |       | j	                  |j                  |       | j	                  |j
                  j                  |       | j	                  |j                  d        y )Nz<b>Argh!</b>Argh!rI   Hooray!)r-   r.   r  r+   r   rC  r  r'  )r   r-   new_textr+   s       r   test_replace_final_nodez,TestTreeModification.test_replace_final_node  s    yy(		w	,,Y799)9,FF22A6!,22??J..5r'   c                 l   | j                  d      }|j                  j                  dd       | j                  |j	                         | j                  d             |j                  d      }| j                  |j                  d       | j                  |j                  j                  |       | j                  |j                  d       | j                  |j                  j                  |       | j                  |j                  d        | j                  |j                  |j                         y )Nz<a><b>Argh!</b><c></c></a>rU   r  z!<a><b>Argh!Hooray!</b><c></c></a>rI   r  )r-   r+   r  r   r   r  r.   rC  r'  r|  rc  r   )r   r-   r  s      r   test_consecutive_text_nodesz0TestTreeModification.test_consecutive_text_nodes  s     yy56a#KKM4,,35	6 99)9,22G<22??J22G<22??J..5..7r'   c                 L   | j                  d      }|j                  j                  dd       |j                  j                  dd       | j                  ddg|j                  j                         | j                  |j                  j                  d   j
                  d       y )Nr`   r   rH   r\   )r-   rB   r  r   r   r'  r/   s     r   test_insert_stringz'TestTreeModification.test_insert_string  ss    yy#aa%9+88%@r'   c                    | j                         }| j                  d|      }t        ||d      }|j                  dd       |j                  j                  d|       | j                  |j                         | j                  d             |j                  }| j                  |j                  |       | j                  |j                  |       |j                  d	      }| j                  |j                  |       | j                  |j                  |       |j                  }| j                  |j                  |       | j                  |j                  |       |j                  d	      }| j                  |j                  |       | j                  |j                  |       | j                  |j                  |       y )
Nz%<a><b>Find</b><c>lady!</c><d></d></a>r  magictagr   therU   z=<a><b>Find</b><magictag>the</magictag><c>lady!</c><d></d></a>FindrI   )r   r-   r   r  rB   r   r   r  r+   rc  r|  r.   r'  rC  r   r  )r   r   r-   	magic_tagb_tagr.   c_tagr  s           r   test_insert_tagz$TestTreeModification.test_insert_tag  sz   &&(yy3W  Fgz2	E"a#KKM4,,OQ	R
 ++Y733U;zzvz&**I633T://7//;nn%n(Y/))51//5r'   c                     d}| j                  |      }|j                  j                  |j                         | j	                  ||j                                y r  )r-   rB   ra   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                  |       | j                  d|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+   rB   extendr   r   )r   r   r-   rb   s       r   test_extendz TestTreeModification.test_extend  se    ByyVVTVVTVVTVVTVVTVV<aLdkkm\r'   c                     d}| j                  |      }|j                  j                  d|j                         | j	                  d|j                                y )Nz<a><b></b><c></c><d></d></a>r   z<a><d></d><b></b><c></c></a>)r-   rB   r  r   r   r   r  s      r   $test_move_tag_to_beginning_of_parentz9TestTreeModification.test_move_tag_to_beginning_of_parent  sA    -yya 7Gr'   c                     | j                  d      }|j                  j                  dd       | j                  t	        |j                        d       y )Nz<br/>rU   Contentsz<br>Contents</br>)r-   r  r  r   r7   r/   s     r   &test_insert_works_on_empty_element_tagz;TestTreeModification.test_insert_works_on_empty_element_tag  s=    
 yy!q*%TWW':;r'   c                    | j                  d      }|j                  j                  d       |j                  j                  d       | j	                  |j                         | j                  d             |j                  j                  |j                         | j	                  |j                         | j                  d             |j                  }| j                  t        |j                  |       |j                          | j                  t        |j                  d       | j                  d      }|j                  j                  |j                  d             y )	Nr;   BAZQUUXzQUUX<a>foo</a>BAZ<b>bar</b>QUUX<b>bar</b><a>foo</a>BAZnope<a>rB   )r-   r+   insert_beforerB   r   r   r  r   r   r  r  r   r-   r+   s      r   test_insert_beforez'TestTreeModification.test_insert_before  s   yy/0U#V$KKM4,,-JK	M 	TVV$KKM4,,-JK	M FF*aooq9 	
		*aoov> yyT\\#./r'   c                    | j                  d      }|j                  j                  ddd       |j                  j                  ddd       | j	                  |j                         | j                  d             |j                  j                  |j                  d       | j	                  |j                         | j                  d             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  rB   r   r   r  r/   s     r   test_insert_multiple_beforez0TestTreeModification.test_insert_multiple_before  s    yy/0UC0VS%0KKM4,,-ST	V 	TVVU+KKM4,,-VW	Yr'   c                    | j                  d      }|j                  j                  d       |j                  j                  d       | j	                  |j                         | j                  d             |j                  j                  |j                         | j	                  |j                         | j                  d             |j                  }| j                  t        |j                  |       |j                          | j                  t        |j                  d       | j                  d      }|j                  j                  |j                  d             y )	Nr;   r  r  z<a>foo</a>QUUX<b>bar</b>BAZr  r	  r
  rB   )r-   r+   insert_afterrB   r   r   r  r   r   r  r  r  r  s      r   test_insert_afterz&TestTreeModification.test_insert_after!  s   yy/0E"F#KKM4,,-JK	MDFF#KKM4,,-JK	M FF*anna8 	
		*annf= yyT\\#./r'   c                    | j                  d      }|j                  j                  ddd       |j                  j                  ddd       | j	                  |j                         | j                  d             |j                  j                  |j                  d       | j	                  |j                         | j                  d             y )Nr;   r  r  r  z$<a>foo</a>QUUX BAZ<b>bar</b>BAZ QUUXzFOO z(QUUX BAZ<b>bar</b><a>foo</a>FOO BAZ QUUX)r-   r+   r  rB   r   r   r  r/   s     r   test_insert_multiple_afterz/TestTreeModification.test_insert_multiple_after7  s    yy/0E3/FC/KKM4,,-ST	VDFFF+KKM4,,-WX	Zr'   c                 0   | j                  d      }|j                  d      }|j                  d      }| j                  t        |j
                  |       | j                  t        |j
                  |       | j                  t        |j
                  |       y Nr\  rB   )r-   r  r  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_meaningA  st    yy}ll3$*f&9&93?-t/@/@#F*c&6&6<r'   c                 0   | j                  d      }|j                  d      }|j                  d      }| j                  t        |j
                  |       | j                  t        |j
                  |       | j                  t        |j
                  |       y 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_meaningI  st    yy}ll3$*f&:&:C@-t/A/A3G*c&7&7=r'   c                    | j                  d      }|j                  d      \  }}|j                  |       | j                  |j	                         | j                  d             | j                  |j                  d        | j                  |j                  |j                         | j                  |j                  d       | j                  |j                  d       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  r  r  r'  rc  )r   r-   r  shows       r   test_replace_withz&TestTreeModification.test_replace_withQ  s    yyMO==%D"KKMBD	E
 	d+DFF+$/+6r'   c                     d}| j                  |      }|j                  j                  |j                         | j	                  d|j                                y )Nr  z<a><c></c></a>)r-   r+   r  r   r   r   r  s      r   test_replace_first_childz-TestTreeModification.test_replace_first_child`  A    &yyDFF#)4;;=9r'   c                     d}| j                  |      }|j                  j                  |j                         | j	                  d|j                                y )Nr  r  )r-   r   r  r+   r   r   r  s      r   test_replace_last_childz,TestTreeModification.test_replace_last_childf  r$  r'   c                 F   | j                  d      }|j                  }|j                  }|j                  |       | j	                  |j                         | j                  d             | j	                  |j                  d        | j	                  |j                  d      j                  d        | j	                  |j                  d        | j	                  |j                  d        | j	                  |j                  d        | j	                  |j                  |j                         | j	                  |j                  d       | j	                  |j                  j                  |j                         | j	                  |j                  d        |j                  d      }|j                  }| j	                  |j                  |       | j	                  |j                  |       | j	                  |j                  |       | j	                  |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  rI   Weto)r-   r+   r   r  r   r   r  r  r.   r'  rC  rc  r|  rB   r  r  )r   r-   
remove_tagmove_tagto_textg_tags         r   test_nested_tag_replace_withz1TestTreeModification.test_nested_tag_replace_withl  s   yyce
 VV
66)KKM4,,?A	B
 	**D1g6CCTJ44d;00$744d; 	$&&122D9..;;TVVD..5 )))&--u5--u5//9//9r'   c                     | j                  d      }|j                  j                          | j                  |j                  d        | j                  |j                  j
                  d       y )NzI
            <p>Unneeded <em>formatting</em> is unneeded</p>
            zUnneeded formatting is unneeded)r-   emr  r   r  r8   r   s     r   test_unwrapz TestTreeModification.test_unwrap  sR    yy   	$'&GHr'   c                    | j                  d      }|j                  j                  |j                  d            }| j	                  |j                         d       | j	                  |j                         | j                  d             y )NzI wish I was bold.r+   <b>I wish I was bold.</b>)r-   r   wrapr  r   r   r  )r   r-   r   s      r   	test_wrapzTestTreeModification.test_wrap  sk    yy-.  c!23)DEKKM4,,-HI	Kr'   c                     | j                  d      }|j                  j                  j                  |j                         | j	                  |j                         | j                  d             y )Nz<b></b>I wish I was bold.r3  )r-   r+   rc  r4  r   r   r  r/   s     r   %test_wrap_extracts_tag_from_elsewherez:TestTreeModification.test_wrap_extracts_tag_from_elsewhere  sS    yy45  (KKM4,,-HI	Kr'   c                 @   | j                  d      }|j                  j                  j                  |j                         | j	                  dt        |j                  j                               | j	                  |j                         | j                  d             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+   rc  r4  r   r>   r   r   r  r/   s     r   &test_wrap_puts_new_contents_at_the_endz;TestTreeModification.test_wrap_puts_new_contents_at_the_end  sr    yyFG  (C01KKM4,,=?	@r'   c                    | j                  d      }| j                  t        |j                  j                        d       |j                  d      j                         }| j                  |j                         d       | j                  |j                         d       | j                  t        |j                  j                        d       | j                  |j                  d        | j                  |j                  d        | j                  |j                  j                  d        |j                  d	      }|j                  d
	      }| j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       y )NzR<html><body>Some content. <div id="nav">Nav crap</div> More content.</body></html>rP   navr6   z6<html><body>Some content.  More content.</body></html>z<div id="nav">Nav crap</div>r<   zSome content. rI   z More content.)r-   r   r>   rT  r   r.   r  r   r  rC  r'  rc  r|  )r   r-   	extracted	content_1	content_2s        r   test_extractz!TestTreeModification.test_extract  sh   yy`b 	TYY//0!4III'//1	KKMS	U))+-KL 	TYY//0!4))4033T://<<dC II#3I4	II#3I4	//;//;33Y?33Y?r'   c                    | j                  d      }|j                  j                  }|j                  j                  }|j	                  d      }|j	                  d      }|j                  j                  |       |j                  j                  |       |j                          |j                          | j                  ||j                  j                         | j                  ||j                  j                         y )Nr;   r\   rH   )r-   rB   r   r+   r  ra   r  r   )r   r-   foo_1bar_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} | j	                  dt        |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?   rG  r  r   r7   rT  )r   r-   r   s      r   "test_extract_multiples_of_same_tagz7TestTreeModification.test_extract_multiples_of_same_tag  sZ    yy 
 
 )-h(?@1			@5s499~F 	As   !A/c                     | j                  d      }|j                  d      j                          | j                  d |j                  d             y )Nz<html>
<body>hi</body>
</html>rT  )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  sE    yy 			&!!#tyy01r'   c                    | j                  d      }|j                  }|j                  j                          | j	                  t        |j                  j                        d       | j                  t        |d             |j                  }|j                  d       | j	                  dt        |j                               y)zTag.clear()z4<p><a>String <em>Italicized</em></a> and another</p>r   r   T)	decomposeN)
r-   rB   r  clearr   r>   r   rf   rg   r0  )r   r-   rB   r0  s       r   
test_clearzTestTreeModification.test_clear  s    yyOPFFTVV__-q1:./ TT	$C,-r'   c                    | j                  d      }d|j                  _        | j                  |j                  j                  dg       d|j
                  _        | j                  |j
                  j                  dg       y)zTag.string = 'string'z<a></a> <b><c></c></b>r\   rH   N)r-   rB   r   r   r   r+   r/   s     r   test_string_setz$TestTreeModification.test_string_set  s[    yy125'25'2r'   c                     | j                  d      }|j                  j                  |j                  _        | j	                  |j
                  j                         d       y )Nz<a><b>foo</b><c>bar</c>s   <a><b>bar</b><c>bar</c></a>)r-   r   r   r+   r   rB   r   r/   s     r   /test_string_set_does_not_affect_original_stringzDTestTreeModification.test_string_set_does_not_affect_original_string  s?    yy23*HIr'   c                     | j                  d      }t        d      }||j                  _        | j	                  t        |j                  j                  t                     y )Nr`   r\   )r-   r   rB   r   rf   r  r   r-   cdatas      r   )test_set_string_preserves_class_of_stringz>TestTreeModification.test_set_string_preserves_class_of_string  s?    yy#e
466==%89r'   N),r#   r$   r%   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r&  r.  r1  r5  r7  r9  r?  rE  rH  rJ  rN  rP  rR  rV  r&   r'   r   r  r  *  s    P
E;$##>AC
@
7(168*A6<.]H<0.	Y0,Z=>7::":HIKK@@2/"G 2.3J
: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y)TestElementObjectsz)Test various features of element objects.c                 N   | j                  d      }| j                  t        |j                        d       | j                  t        |      d       | j                  t        |j                        d       | j                  t        |j                  j                        d       y)z3The length of an element is its number of children.z<top>1<b>2</b>3</top>rU   rP   N)r-   r   r>   r   r  r/   s     r   test_lenzTestElementObjects.test_len  sy    yy01 	T]]+Q/TA& 	TXX*TXX../3r'   c                 <   | j                  d      }| j                  |j                  |j                  d             | j                  |j                  j                  |j                  d      j                  d             | j                  |j
                  d       y)z2Accessing a Python member .foo invokes find('foo')<b><i></i></b>r+   r   N)r-   r   r+   r.   r   rB   r/   s     r   test_member_access_invokes_findz2TestElementObjects.test_member_access_invokes_find"  sl    yy)*30499S>#6#6s#;<&r'   c                    | j                  d      }t        j                  d      5 }|j                  }d d d        | j	                  |j
                         | j	                  dt        d   j                               y # 1 sw Y   NxY w)Nr\  T)recordzp.bTag is deprecated, use .find("b") instead. If you really were looking for a tag called bTag, use .find("bTag")r   )r-   warningscatch_warningsbTagr   r+   r7   message)r   r-   wr   s       r   test_deprecated_member_accessz0TestElementObjects.test_deprecated_member_access)  st    yy)*$$D1 	Q))C	%~!		 	s   BBc                     | j                  d      }| j                  |j                  j                  d             | j	                  |j                  j                  d             y)zhas_attr() checks for the presence of an attribute.

        Please note note: has_attr() is different from
        __in__. has_attr() checks the tag's attributes and __in__
        checks the tag's chidlren.
        z<foo attr='bar'>attrattr2N)r-   rf   r\   has_attrassertFalser/   s     r   test_has_attrz TestElementObjects.test_has_attr2  sK     yy+,))&12**734r'   c                 ,    d}| j                  |d       y )Nz%<b a="1" z="5" m="3" f="2" y="4"></b>z%<b a="1" f="2" m="3" y="4" z="5"></b>)assertSoupEquals)r   r^  s     r   .test_attributes_come_out_in_alphabetical_orderzATestElementObjects.test_attributes_come_out_in_alphabetical_order>  s    8f&MNr'   c                 r    | j                  d      }| j                  |j                  j                  d       y )Nz
<b>foo</b>r\   r-   r   r+   r   r/   s     r   test_stringzTestElementObjects.test_stringB  s*     yy&.r'   c                 r    | j                  d      }| j                  |j                  j                  d        y )N<b></b>rp  r/   s     r   test_empty_tag_has_no_stringz/TestElementObjects.test_empty_tag_has_no_stringH  s(    yy#-r'   c                    | j                  d      }| j                  |j                  j                  d        | j                  d      }| j                  |j                  j                  d        | j                  d      }|j                  j                  dd       | j                  |j                  j                  d        y )Nz<a>foo<b></b><b></b></b>z<a>foo<b></b>bar</b>z
<a>foo</b>rU   rH   )r-   r   r+   r   rB   r  r/   s     r   -test_tag_with_multiple_children_has_no_stringz@TestElementObjects.test_tag_with_multiple_children_has_no_stringM  s    yy34-yy/0- yy&a-r'   c                     | j                  d      }| j                  |j                  j                  d       | j                  |j                  d       y )Nz<a><b>foo</b></a>r\   )r-   r   rB   r   r/   s     r   )test_tag_with_recursive_string_has_stringz<TestElementObjects.test_tag_with_recursive_string_has_string[  s?     yy,-.e,r'   c                     | j                  d      }| j                  |j                  j                         | j                  d      }| j                  |j                  j                         y)z7Only a tag containing a single text node has a .string.z<b>f<i>e</i>o</b>rs  N)r-   rj  r+   r   r/   s     r   test_lack_of_stringz&TestElementObjects.test_lack_of_stringb  sK    yy,-'yy#'r'   c                 z   | j                  d      }| j                  |j                  j                  d       | j                  |j                  j	                  d      d       | j                  |j                  j	                  d      d       | j                  |j                  j	                  dd      d       y	)
zBTag.text and Tag.get_text(sep=u"") -> all child text, concatenatedz<a>a<b>r</b>   <r> t </r></a>zar  t T)stripart,z	a,r, , t za,r,tN)r-   r   rB   r8   get_textr/   s     r   test_all_textz TestElementObjects.test_all_textj  s    yy89h/t4e<-{;D97Cr'   c                    | j                  d      }| j                  |j                         d       | j                  |j                  t        t        f      d       | j                  |j                  d       d       y )Nfoo<!--IGNORE-->barfoobar)typesfooIGNOREbar)r-   r   r  r   r	   r/   s     r   test_get_text_ignores_commentsz1TestElementObjects.test_get_text_ignores_commentsr  si    yy./(3MM' :M;^	MMMM%~	7r'   c                 t    | j                  d      }| j                  ddgt        |j                               y )Nr  r\   rH   )r-   r   r  stringsr/   s     r   !test_all_strings_ignores_commentsz4TestElementObjects.test_all_strings_ignores_comments{  s.    yy./%dll);<r'   N)r#   r$   r%   rD   rZ  r]  re  rk  rn  rq  rt  rv  rx  rz  r  r  r  r&   r'   r   rX  rX    sH    34'	5O/.
.-(D7=r'   rX  c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestCDAtaListAttributesz0Testing cdata-list attributes like 'class'.
    c                 f    | j                  d      }| j                  dg|j                  d          y )Nz<a class='foo'>r\   r   r-   r   rB   r/   s     r   test_single_value_becomes_listz6TestCDAtaListAttributes.test_single_value_becomes_list  s+    yy*+%1r'   c                 h    | j                  d      }| j                  ddg|j                  d          y )Nz<a class='foo bar'>r\   rH   r   r  r/   s     r   !test_multiple_values_becomes_listz9TestCDAtaListAttributes.test_multiple_values_becomes_list  s-    yy./%9r'   c                 h    | j                  d      }| j                  g d|j                  d          y )Nz<a class='foo	bar
baz'>)r\   rH   rt  r   r  r/   s     r   2test_multiple_values_separated_by_weird_whitespacezJTestCDAtaListAttributes.test_multiple_values_separated_by_weird_whitespace  s*    yy45.tvvg?r'   c                 z    | j                  d      }| j                  d|j                  j                                y )Nz<a class='foo	bar'>s   <a class="foo bar"></a>)r-   r   rB   r   r/   s     r   ,test_attributes_joined_into_string_on_outputzDTestCDAtaListAttributes.test_attributes_joined_into_string_on_output  s,    yy/03TVV]]_Er'   c                 ~    | j                  d      }| j                  dg|j                  j                  d             y )Nz<a id='abc def'>zabc defr!   )r-   r   rB   get_attribute_listr/   s     r   test_get_attribute_listz/TestCDAtaListAttributes.test_get_attribute_list  s2    yy+,)dff&?&?&EFr'   c                 h    | j                  d      }| j                  ddg|j                  d          y )Nz(<form accept-charset="ISO-8859-1 UTF-8">z
ISO-8859-1zUTF-8accept-charset)r-   r   formr/   s     r   test_accept_charsetz+TestCDAtaListAttributes.test_accept_charset  s0    yyCD,0$))<L2MNr'   c                 h    d}| j                  |      }| j                  d|j                  d          y )Nz)<a accept-charset="ISO-8859-1 UTF-8"></a>zISO-8859-1 UTF-8r  r  r  s      r   -test_cdata_attribute_applying_only_to_one_tagzETestCDAtaListAttributes.test_cdata_attribute_applying_only_to_one_tag  s1    :yy 	+TVV4D-EFr'   c                     | j                  d      j                  | j                  d j                         fd}| j	                  t
        |       y )Nr  c                      d _         y )Nr\   r   r3   s   r   tzJTestCDAtaListAttributes.test_string_has_immutable_name_property.<locals>.t  s
    FKr'   )r-   r   r   rp   r   AttributeError)r   r  r   s     @r   'test_string_has_immutable_name_propertyz?TestCDAtaListAttributes.test_string_has_immutable_name_property  s?    3&&v{{+	 .!,r'   N)r#   r$   r%   rD   r  r  r  r  r  r  r  r  r&   r'   r   r  r    s4    2:@FGOG-r'   r  c                   X     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )TestPersistencez*Testing features like pickle and deepcopy.c                 x    t         t        |           d| _        | j	                  | j                        | _        y )Nay  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Beautiful Soup: We called him Tortoise because he taught us.</title>
<link rev="made" href="mailto:leonardr@segfault.org">
<meta name="Description" content="Beautiful Soup: an HTML parser optimized for screen-scraping.">
<meta name="generator" content="Markov Approximation 1.4 (module: leonardr)">
<meta name="author" content="Leonard Richardson">
</head>
<body>
<a href="foo">foo</a>
<a href="foo"><b>bar</b></a>
</body>
</html>)rv   r  rw   pager-   rx   ry   s    r   rw   zTestPersistence.setUp  s/    ot*,	  IIdii(	r'   c                    t        j                  | j                  d      }t        j                  |      }| j	                  |j
                  t               | j	                  |j                         | j                  j                                y )Nr<   )pickledumpsrx   loadsr   rz   r   r   )r   dumpedloadeds      r   !test_pickle_and_unpickle_identityz1TestPersistence.test_pickle_and_unpickle_identity  s_     dii+f%))=9$))*:*:*<=r'   c                     t        j                  | j                        }| j                  |j	                         | j                  j	                                y r  )copydeepcopyrx   r   r   )r   copieds     r   test_deepcopy_identityz&TestPersistence.test_deepcopy_identity  s7    tyy)$))*:*:*<=r'   c                     t        dd      }|j                  }|j                         }| j                  dt	        |             | j                  ||j                         y )Ns   <p>&nbsp;</p>r  u	   <p> </p>)r   original_encoding__copy__r   r7   )r   r-   encodingr  s       r   test_copy_preserves_encodingz,TestPersistence.test_copy_preserves_encoding  sO    -}=))}}c$i04#9#9:r'   c                    | j                  d      j                  }d|_        d|_        |j	                         }| j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         y )Nz<p></p>rV   !   )	r-   r  
sourceline	sourceposr  r   can_be_empty_elementcdata_list_attributesr  )r   r   r  s      r   'test_copy_preserves_builder_informationz7TestPersistence.test_copy_preserves_builder_information  s    ii	"$$  	):):;(8(89$$f&A&A	
 	%%v'C'C	
 	((&*I*I	
r'   c                     d}| j                  |      }t        j                  |t        j                        }t        j                  |      }| j                  |j                         |j                                y )N
   <b>☃</b>)r-   r  r  HIGHEST_PROTOCOLr  r   r   )r   rF  r-   r  r  s        r   test_unicode_picklez#TestPersistence.test_unicode_pickle  sT    #yydF$;$;<f%$++-8r'   c                    d}| j                  |      }|j                  d      }t        j                  |      }| j                  ||       | j                  d |j                         | j                  d |j
                         | j                  d |j                         | j                  d |j                         | j                  d |j                         y )Nz<b>Foo<a></a></b><b>Bar</b>rJ   r3   )	r-   r.   r  r   r  r'  assertNotEqualrc  rC  r   rF  r-   s1s2s        r   1test_copy_navigablestring_is_not_attached_to_treezATestPersistence.test_copy_navigablestring_is_not_attached_to_tree  s    ,yyYYeY$YYr]R ryy)r/D"//2r/r223r'   c                     d}| j                  |      }|j                  }t        j                  |      }| j                  ||       | j	                  t        |t                     y )Nz<b><!--Foo--></b>)r-   r   r  r   rf   r  r	   r  s        r   0test_copy_navigablestring_subclass_has_same_typez@TestPersistence.test_copy_navigablestring_subclass_has_same_type  sM    "yy[[YYr]R 
2w/0r'   c                 x    d}| j                  |      }t        j                  |      }| j                  ||       y )N)<div><b>Foo<a></a></b><b>Bar</b></div>end)r-   r  r   )r   rF  r-   	soup_copys       r   test_copy_entire_soupz%TestPersistence.test_copy_entire_soup
  s1    :yyIIdO	y)r'   c                    d}| j                  |      }|j                  }t        j                  |      }| j                  t	        |      t	        |             | j                  ||       | j                  ||u        | j                  d |j                         | j                  d |j                         | j                  d |j                  d      j                         | j                  d |j                  d      j                         y )Nr  Barr3   )r-   r   r  r   r7   rj  r  rC  r.   r'  r  )r   rF  r-   r   div_copys        r   test_copy_tag_copies_contentsz-TestPersistence.test_copy_tag_copies_contents  s    :yyhh99S> 	S3x=1h' 	) 	x/x889x}}E}:GGHD#((%("8"E"EFr'   )r#   r$   r%   rD   rw   r  r  r  r  r  r  r  r  r  r   r   s   @r   r  r    s9    0)(>>
;
29
41*G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)TestSubstitutionsc                     d}| j                  |      }|j                  d      }| j                  || j                  d             y N#   <b>&lt;&lt;Sacré bleu!&gt;&gt;</b>minimal	formatterr-   r   r   r  r   r^  r-   decodeds       r   !test_default_formatter_is_minimalz3TestSubstitutions.test_default_formatter_is_minimal&  I    Wyy ++	+2VX	Yr'   c                     d}| j                  |      }|j                  d      }| j                  || j                  d             y )N'   <br><b>&lt;&lt;Sacré bleu!&gt;&gt;</b>rF  r  z.<br/><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>r  r  s       r   test_formatter_htmlz%TestSubstitutions.test_formatter_html0  sF    [yy +++/NO	Qr'   c                     d}| j                  |      }|j                  d      }| j                  || j                  d             y )Nr  html5r  z-<br><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>r  r  s       r   test_formatter_html5z&TestSubstitutions.test_formatter_html58  sF    [yy +++0MN	Pr'   c                     d}| j                  |      }|j                  d      }| j                  || j                  d             y r  r  r  s       r   test_formatter_minimalz(TestSubstitutions.test_formatter_minimal@  r  r'   c                     d}| j                  |      }|j                  d       }| j                  || j                  d             y )Nr  r  u   <b><<Sacré bleu!>></b>r  r  s       r   test_formatter_nullz%TestSubstitutions.test_formatter_nullJ  sG    Wyy +++- 	++,fg	ir'   c                     d}| j                  |      }|j                  d       }| j                  || j                  d             y )Nz!<b>&lt;foo&gt;</b><b>bar</b><br/>c                 "    | j                         S r  upperxs    r   <lambda>z9TestSubstitutions.test_formatter_custom.<locals>.<lambda>V  s    AGGI r'   r  z<b><FOO></b><b>BAR</b><br/>r  r  s       r   test_formatter_customz'TestSubstitutions.test_formatter_customS  sH    4yy ++*=+> 	;<	>r'   c                    d}| j                  |      }|j                  }d}| j                  ||j                                | j                  ||j                  d             d}| j                  ||j                  d             | j                  ||j                  d              d}| j                  ||j                  d              y )	Nu%   <a href="http://a.com?a=b&c=é">e</a>u)   <a href="http://a.com?a=b&amp;c=é">e</a>r  r  z/<a href="http://a.com?a=b&amp;c=&eacute;">e</a>rF  u%   <a href="HTTP://A.COM?A=B&C=É">E</a>c                 "    | j                         S r  r  r  s    r   r  zMTestSubstitutions.test_formatter_is_run_on_attribute_values.<locals>.<lambda>l  s    AGGI r'   )r-   rB   r   r   )r   r^  r-   rB   expect_minimalexpect_htmlexpect_uppers          r   )test_formatter_is_run_on_attribute_valuesz;TestSubstitutions.test_formatter_is_run_on_attribute_values]  s    8yy FFD4I)FGGahhh&@AD!9:>qxx:Mx'NOr'   c                 b    d}t        |d      j                         }| j                  d|v        y )NzO
  <script type="text/javascript">
   console.log("< < hey > > ");
  </script>
r     < < hey > >r   r   rf   r   r  encodeds      r   2test_formatter_skips_script_tag_for_html_documentszDTestSubstitutions.test_formatter_skips_script_tag_for_html_documentsn  1    
  ]3::<'12r'   c                 b    d}t        |d      j                         }| j                  d|v        y )NzF
  <style type="text/css">
   console.log("< < hey > > ");
  </style>
r  r  r  r  s      r   1test_formatter_skips_style_tag_for_html_documentszCTestSubstitutions.test_formatter_skips_style_tag_for_html_documentsw  r  r'   c                 z    | j                  d      }| j                  d|j                  j                                y )NzN<div>  foo  <pre>  	bar
  
  </pre>  baz  <textarea> eee
fff	</textarea></div>zO<div>
 foo
 <pre>  	bar
  
  </pre>
 baz
 <textarea> eee
fff	</textarea>
</div>)r-   r   r   prettifyr/   s     r   ,test_prettify_leaves_preformatted_text_alonez>TestSubstitutions.test_prettify_leaves_preformatted_text_alone  s4    yyno 	gHH	!r'   c                 h    t        dd      }|j                  d       }| j                  d|v        y )Nz<html><body>foo</body></html>r  c                 "    | j                         S r  r  r  s    r   r  zLTestSubstitutions.test_prettify_accepts_formatter_function.<locals>.<lambda>  s    QWWY r'   r  r  )r   r  rf   )r   r-   prettys      r   (test_prettify_accepts_formatter_functionz:TestSubstitutions.test_prettify_accepts_formatter_function  s0    <mL+>?(r'   c                     | j                  d      }| j                  t        t        |j	                                      y r_   )r-   r   r7   typer  r/   s     r   (test_prettify_outputs_unicode_by_defaultz:TestSubstitutions.test_prettify_outputs_unicode_by_default  s+    yy#d4==?34r'   c                     | j                  d      }| j                  t        t        |j	                  d                   y )Nr`   utf-8)r-   r   bytesr	  r  r/   s     r   test_prettify_can_encode_dataz/TestSubstitutions.test_prettify_can_encode_data  s.    yy#T]]7%; <=r'   c                     d}| j                  |      }|j                  j                  d      }| j                  ||j                  d             y )Nu   <b>Sacré bleu!</b>r  )r-   r+   r   r   )r   r^  r-   r  s       r   ,test_html_entity_substitution_off_by_defaultz>TestSubstitutions.test_html_entity_substitution_off_by_default  s@    Gyy &&--(&--"89r'   c                    d}| j                  |      }| j                  |j                  d   d       |j                  d      }| j	                  d|v        |j                  d      }| j	                  d|v        |j                  d      }| j	                  d	|v        |j                  d
      j                  d
      }| j	                  d|v        y )NzE<meta content="text/html; charset=x-sjis" http-equiv="Content-type"/>contentztext/html; charset=x-sjisr  s   charset=utf-8euc_jps   charset=euc_jpz	shift-jiss   charset=shift-jiszutf-16zcharset=utf-16)r-   r   metar   rf   r   )r   meta_tagr-   utf_8r  	shift_jisutf_16_us          r   test_encoding_substitutionz,TestSubstitutions.test_encoding_substitution  s    2yy" 	9-/JK G$(E12X&)V34KK,	,	9:;;x(//9(H45r'   c                     d}t        d      }| j                  ||      }| j                  |j                  d   j                  d       y )Nz`<head><meta content="text/html; charset=x-sjis" http-equiv="Content-type"/></head><pre>foo</pre>pre)
parse_onlyr   )r   r-   r   r   rp   )r   r^  r   r-   s       r   ;test_encoding_substitution_doesnt_happen_if_tag_is_strainedzMTestSubstitutions.test_encoding_substitution_doesnt_happen_if_tag_is_strained  sG    G  &yyHy5q)..6r'   N)r#   r$   r%   r  r  r  r  r  r  r  r  r   r  r  r
  r  r  r  r  r&   r'   r   r  r  $  sX    YQPYi>P"33!)
5>:60	7r'   r  c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestEncodingz0Test the ability to encode objects into strings.c                     d}| j                  |      }| j                  |j                  j                  j	                  d      dj	                  d             y )Nr  r     ☃)r-   r   r+   r   r   r   rF  r-   s      r   "test_unicode_string_can_be_encodedz/TestEncoding.test_unicode_string_can_be_encoded  sE    #yy--g6'..w7	9r'   c                     d}| j                  |      }| j                  |j                  j                  d      |j                  d             y )Nr  r  r-   r   r+   r   r"  s      r   1test_tag_containing_unicode_string_can_be_encodedz>TestEncoding.test_tag_containing_unicode_string_can_be_encoded  s=    #yyFFMM'"DKK$8	:r'   c                     d}| j                  |      }| j                  |j                  j                  d      d       y )Nr  asciis   <b>&#9731;</b>r%  r"  s      r   <test_encoding_substitutes_unrecognized_characters_by_defaultzITestEncoding.test_encoding_substitutes_unrecognized_characters_by_default  s2    #yyw/1BCr'   c                 p    d}| j                  |      }| j                  t        |j                  dd       y )Nr  r(  strict)errors)r-   r   UnicodeEncodeErrorr   r"  s      r    test_encoding_can_be_made_strictz-TestEncoding.test_encoding_can_be_made_strict  s5    #yyWX 	 	Gr'   c                 ~    d}| j                  |      }| j                  d|j                  j                                y )Nr  r!  )r-   r   r+   decode_contentsr"  s      r   test_decode_contentsz!TestEncoding.test_decode_contents  s1    #yy(>(>(@Ar'   c                     d}| j                  |      }| j                  dj                  d      |j                  j	                  d             y )Nr  r!  r   )r  )r-   r   r   r+   encode_contentsr"  s      r   test_encode_contentsz!TestEncoding.test_encode_contents  sJ    #yy  ($&&*@*@ +A +!	"r'   c                     d}| j                  |      }| j                  dj                  d      |j                  j	                                y )Nr  r!  r   )r-   r   r   r+   renderContentsr"  s      r   test_deprecated_renderContentsz+TestEncoding.test_deprecated_renderContents  s@    #yy  ($&&*?*?*A	Cr'   c                     d}| j                  |      }t        r| j                  |t        |             y | j                  dt        |             y )Nr  s   <b>\u2603</b>)r-   r   r   reprr"  s      r   	test_reprzTestEncoding.test_repr  s@    #yyT4:..T
;r'   N)r#   r$   r%   rD   r#  r&  r)  r.  r1  r4  r7  r:  r&   r'   r   r  r    s1    :9:D
GB
"C<r'   r  c                       e Zd Zd Zy)TestFormatterc                      G d dt               }| j                  d      } |       }|j                  |      }| j                  |j                  |j
                         | j                  d|       y )Nc                       e Zd Zd Zy)=TestFormatter.test_sort_attributes.<locals>.UnsortedFormatterc              3      K   || _         t        |j                  j                               D ]  \  }}|dk(  r||f  y w)Nignore)called_withsortedro   items)r   r   kvs       r   
attributeszHTestFormatter.test_sort_attributes.<locals>.UnsortedFormatter.attributes  sD     #& "399??#45 DAqH} A#Is   A AN)r#   r$   r%   rG  r&   r'   r   UnsortedFormatterr?    s    r'   rH  z*<p cval="1" aval="2" ignore="ignored"></p>r  z<p aval="2" cval="1"></p>)r   r-   r   r   rB  r  )r   rH  r-   r  r  s        r   test_sort_attributesz"TestFormatter.test_sort_attributes  sd    		 	 yyEF%'	++	+2 	..74g>r'   N)r#   r$   r%   rI  r&   r'   r   r<  r<    s    ?r'   r<  c                   $    e Zd Zd Zd Zd Zd Zy)TestNavigableStringSubclassesc                    | j                  d      }t        d      }|j                  d|       | j                  t	        |      d       | j                  |j                  d      d       | j                  |j                  d   d       y )Nr\  r\   rU   z<![CDATA[foo]]>rI   r   )r-   r   r  r   r7   r.   r   rT  s      r   
test_cdataz(TestNavigableStringSubclasses.test_cdata  sq     yy}eAuT$56.6q)51r'   c                      d _          fd} j                  d      }t        d      }|j                  d|        j	                  d|j                  |              j	                  d j                          y)	zkText inside a CData object is passed into the formatter.

        But the return value is ignored.
        r   c                  0    xj                   dz  c_         y)NrU   zBITTER FAILURE)count)argsr   s    r   	incrementzNTestNavigableStringSubclasses.test_cdata_is_never_formatted.<locals>.increment  s    JJ!OJ#r'   r\  z<><><>rU   s   <![CDATA[<><><>]]>r  N)rP  r-   r   r  r   r   )r   rR  r-   rU  s   `   r   test_cdata_is_never_formattedz;TestNavigableStringSubclasses.test_cdata_is_never_formatted  sj     
	$ yy}hAu!4;;;#C	EDJJ'r'   c                     t        d      }| j                  d      }|j                  d|       | j                  |j	                         d       y )Nr\   r\  rU   s   <!DOCTYPE foo>
)r   r-   r  r   r   )r   doctyper-   s      r   test_doctype_ends_in_newlinez:TestNavigableStringSubclasses.test_doctype_ends_in_newline'  s?     %.yy}Aw(;<r'   c                 Z    t        d      }| j                  d|j                                y )Nr\   z<?foo?>)r
   r   output_ready)r   r   s     r   test_declarationz.TestNavigableStringSubclasses.test_declaration/  s#    ANN$45r'   N)r#   r$   r%   rM  rS  rV  rY  r&   r'   r   rK  rK  	  s    2($=6r'   rK  c                   j   e Zd ZdZd Zd Z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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- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=y;)<TestSoupSelectora  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>The title</title>
<link rel="stylesheet" href="blah.css" type="text/css" id="l1">
</head>
<body>
<custom-dashed-tag class="dashed" id="dash1">Hello there.</custom-dashed-tag>
<div id="main" class="fancy">
<div id="inner">
<h1 id="header1">An H1</h1>
<p>Some text</p>
<p class="onep" id="p1">Some more text</p>
<h2 id="header2">An H2</h2>
<p class="class1 class2 class3" id="pmulti">Another</p>
<a href="http://bob.example.org/" rel="friend met" id="bob">Bob</a>
<h2 id="header3">Another H2</h2>
<a id="me" href="http://simonwillison.net/" rel="me">me</a>
<span class="s1">
<a href="#" id="s1a1">span1a1</a>
<a href="#" id="s1a2">span1a2 <span id="s1a2s1">test</span></a>
<span class="span2">
<a href="#" id="s2a1">span2a1</a>
</span>
<span class="span3"></span>
<custom-dashed-tag class="dashed" id="dash2"/>
<div data-tag="dashedvalue" id="data1"/>
</span>
</div>
<x id="xid">
<z id="zida"/>
<z id="zidab"/>
<z id="zidac"/>
</x>
<y id="yid">
<z id="zidb"/>
</y>
<p lang="en" id="lang-en">English</p>
<p lang="en-gb" id="lang-en-gb">English UK</p>
<p lang="en-us" id="lang-en-us">English US</p>
<p lang="fr" id="lang-fr">French</p>
</div>

<div id="footer">
</div>
c                 :    t        | j                  d      | _        y )Nr  )r   HTMLr-   r   s    r   rw   zTestSoupSelector.setUpf  s    !$))];	r'   c                     | j                   j                  |fi |D cg c]  }|d   	 }}|j                          |j                          | j                  ||d|ddj	                  |      ddj	                  |      d       y c c}w )Nr!   z	Selector z, expected [z, z], got [])r-   selectsortr   join)r   selectorexpected_idskwargselel_idss         r   r   zTestSoupSelector.assertSelectsi  sz    %5TYY%5%5h%I&%IJr"T(JJv$))L1499V3D	
 Ks   B
c                 <    |D ]  \  }}| j                  ||        y r  )assertSelect)r   testsrc  rd  s       r   assertSelectMultiplez%TestSoupSelector.assertSelectMultipleu  s&    &+ 	6"Hlh5	6r'   c                     | j                   j                  d      }| j                  t        |      d       | j                  |d   j                  d       | j                  |d   j
                  dg       y )Nr   rU   r   z	The title)r-   r`  r   r>   rp   r   r   elss     r   test_one_tag_onez!TestSoupSelector.test_one_tag_oney  s\    iiw'S1%Qg.Q;-8r'   c                    | j                   j                  d      }| j                  t        |      d       |D ]  }| j                  |j                  d         | j                   j                  d      }| j                  d|d          y )Nr      mainr!   )r-   r`  r   r>   rp   
select_one)r   rn  r   rf  s       r   test_one_tag_manyz"TestSoupSelector.test_one_tag_many  sw    iiu%S1% 	.CSXXu-	. YY!!%(D*r'   c                 ^    | j                   j                  d      }| j                  d |       y )Nnonexistenttag)r-   rs  r   )r   matchs     r   (test_select_one_returns_none_if_no_matchz9TestSoupSelector.test_select_one_returns_none_if_no_match  s'    		$$%56u%r'   c                 b    | j                   j                  d      }| j                  dddg       y )Nzdiv divinnerdata1)r-   r`  r   rm  s     r   test_tag_in_tag_onez$TestSoupSelector.test_tag_in_tag_one  s+    iiy)9w&89r'   c                 :    dD ]  }| j                  |g d        y )N)html divhtml body divbody divr{  rr  rz  footerr   r   rc  s     r   test_tag_in_tag_manyz%TestSoupSelector.test_tag_in_tag_many  s$    A 	OHx)MN	Or'   c                     | j                  ddgd       | j                  dddgd       | j                  dg d	d
       y )Nr~  rr  rU   rQ   r  rz  r<   r  r  rV   r  r   s    r   
test_limitzTestSoupSelector.test_limit  sN    :xq9?Wf,=QG:'K!# 	 	%r'   c                 l    | j                  t        | j                  j                  d            d       y )Ndelr   r   r>   r-   r`  r   s    r   test_tag_no_matchz"TestSoupSelector.test_tag_no_match  s&    TYY--e45q9r'   c                 Z    | j                  t        | j                  j                  d       y )Nztag%tr   SyntaxErrorr-   r`  r   s    r   test_invalid_tagz!TestSoupSelector.test_invalid_tag  s    +tyy'7'7Ar'   c                 ,    | j                  dddg       y )Ncustom-dashed-tagdash1dash2r  r   s    r   test_select_dashed_tag_idsz+TestSoupSelector.test_select_dashed_tag_ids  s    .'0BCr'   c                     | j                   j                  d      }| j                  |d   j                  d       | j                  |d   d   d       y )Nzcustom-dashed-tag[id="dash2"]r   r  r!   r  )r-   r`  r   rp   )r   dasheds     r   test_select_dashed_by_idz)TestSoupSelector.test_select_dashed_by_id  sH    !!"CD)<=4'2r'   c                 t    | j                  | j                  j                  d      d   j                  d       y )Nzbody > custom-dashed-tagr   zHello there.)r   r-   r`  r8   r   s    r   test_dashed_tag_textz%TestSoupSelector.test_dashed_tag_text  s-    ))*DEaHMM~^r'   c                     | j                  | j                  j                  d      | j                  j                  d             y )Nr  )r   r-   r`  r?   r   s    r   #test_select_dashed_matches_find_allz4TestSoupSelector.test_select_dashed_matches_find_all  s2    ))*=>		@R@RSf@ghr'   c                 6    | j                  ddgfdddgf       y )Nh1header1h2header2header3rk  r   s    r   test_header_tagsz!TestSoupSelector.test_header_tags  s'    !!I;Iy)*	
r'   c                     dD ]p  }| j                   j                  |      }| j                  t        |      d       | j                  |d   j                  d       | j                  |d   d   dg       r y )N)z.onepzp.onepzhtml p.oneprU   r   r  r   onep)r-   r`  r   r>   rp   )r   rc  rn  s      r   test_class_onezTestSoupSelector.test_class_one  sk    : 	8H))""8,CSXq)SV[[#.SVG_vh7		8r'   c                 p    | j                   j                  d      }| j                  t        |      d       y )Nzdiv.onepr   r-   r`  r   r>   rm  s     r   test_class_mismatched_tagz*TestSoupSelector.test_class_mismatched_tag  s*    iiz*S1%r'   c                 8    dD ]  }| j                  |dg        y )N)z	div#innerz#innerzdiv div#innerrz  r  r  s     r   test_one_idzTestSoupSelector.test_one_id  s#    @ 	4Hx'3	4r'   c                 p    | j                   j                  d      }| j                  t        |      d       y )Nz#doesnotexistr   r  rm  s     r   test_bad_idzTestSoupSelector.test_bad_id  s*    ii/S1%r'   c                 .   | j                   j                  d      }| j                  t        |      d       |D ]  }| j                  |j                  d         | j                  |d   d   dg       | j                  |d   j                  d             y )Nzdiv#inner prP   r  rU   r   r  r   )r-   r`  r   r>   rp   rj  ri  )r   rn  rf  s      r   test_items_in_idz!TestSoupSelector.test_items_in_id  s    ii}-S1% 	+BRWWc*	+Q6(3Q12r'   c                 z    dD ]6  }| j                  t        | j                  j                  |            d       8 y )N)zdiv#main delzdiv#main div.oopszdiv div#mainr   r  r  s     r   test_a_bunch_of_emptysz'TestSoupSelector.test_a_bunch_of_emptys  s7    M 	AHS!1!1(!;<a@	Ar'   c                 8    dD ]  }| j                  |dg        y )N)z.class1zp.class1z.class2zp.class2z.class3zp.class3zhtml p.class2zdiv#inner .class2pmultir  r  s     r   test_multi_class_supportz)TestSoupSelector.test_multi_class_support  s&    I 	5Hx(4	5r'   c                 8    dD ]  }| j                  |dg        y )N)z.class1.class3z.class3.class2z.class1.class2.class3r  r  r  s     r   test_multi_class_selectionz+TestSoupSelector.test_multi_class_selection  s%    2 	5Hx(4	5r'   c                 R    | j                  dddg       | j                  ddg       y )Nz.s1 > as1a1s1a2z.s1 > a spans1a2s1r  r   s    r   test_child_selectorz$TestSoupSelector.test_child_selector  s)    9vv&67>H:6r'   c                 *    | j                  ddg       y )Nz.s1 > a#s1a2 spanr  r  r   s    r   test_child_selector_idz'TestSoupSelector.test_child_selector_id  s    .
;r'   c                     | j                  ddgfddgfddgfddgfddgfddgfd	dgfd
g fddgfddgfddgfdg fdg fdg f       y )Nzp[class="onep"]r  z
p[id="p1"]z[class="onep"]z	[id="p1"]zlink[rel="stylesheet"]l1zlink[type="text/css"]zlink[href="blah.css"]zlink[href="no-blah.css"]z[rel="stylesheet"]z[type="text/css"]z[href="blah.css"]z[href="no-blah.css"]zp[href="no-blah.css"]r  r   s    r   test_attribute_equalsz&TestSoupSelector.test_attribute_equals  s    !!'D6"v&4&!%v.$tf-$tf-',!D6* 4&) 4&)#R($b)#R(	
r'   c                 t    | j                  ddgfddgfddgfddgfddgfddgfdd	gfd
d	gfdd	gfdd	gf
       y )Nzp[class~="class1"]r  zp[class~="class2"]zp[class~="class3"]z[class~="class1"]z[class~="class2"]z[class~="class3"]za[rel~="friend"]bobza[rel~="met"]z[rel~="friend"]z[rel~="met"]r  r   s    r   test_attribute_tildez%TestSoupSelector.test_attribute_tilde  st    !!!H:.!H:.!H:. 8*- 8*- 8*-%)ug&(eW%	
r'   c                     | j                  ddgfddgfdg fdg fdg fddgfdd	d
gfdd	d
gfdddgfdd
dgfddgfdd
gfddgf       y )Nz[rel^="style"]r  zlink[rel^="style"]znotlink[rel^="notstyle"]z[rel^="notstyle"]zlink[rel^="notstyle"]zlink[href^="bla"]za[href^="http://"]r  mez[href^="http://"]z	[id^="p"]r  r  z	[id^="m"]rr  zdiv[id^="m"]z
a[id^="m"]zdiv[data-tag^="dashed"]r{  r  r   s    r   test_attribute_startswithz*TestSoupSelector.test_attribute_startswith  s    !!v&!D6*', "%$b) 4&)!E4=1 5$-08T*+4.)fX&D6"&	2	
r'   c           	      T    | j                  ddgfddgfddgfdg dfddgfd	g f       y )
Nz[href$=".css"]r  zlink[href$=".css"]zlink[id$="1"]z	[id$="1"])r{  r  r  r  r  s2a1r  r  zdiv[id$="1"]r{  z[id$="noending"]r  r   s    r   test_attribute_endswithz(TestSoupSelector.test_attribute_endswith  sI    !!v&!D6*tf%]^gY'$	
r'   c                     | j                  ddgfddgfdg fdg fdg fddgfdd	d
gfdddgfddgfdd
gfddgfddgfddgfdg dfddgfdg fdg dfdd	d
gfddgfdddgfddgfd dgf       y )!Nz[rel*="style"]r  zlink[rel*="style"]znotlink[rel*="notstyle"]z[rel*="notstyle"]zlink[rel*="notstyle"]zlink[href*="bla"]z[href*="http://"]r  r  z	[id*="p"]r  r  zdiv[id*="m"]rr  z
a[id*="m"]z[href*=".css"]zlink[href*=".css"]zlink[id*="1"]z	[id*="1"])	r{  r  r  r  r  r  r  r  r  zdiv[id*="1"]r{  z[id*="noending"]z[href*="."])r  r  r  za[href*="."]zlink[href*="."]zdiv[id*="n"]rz  zdiv[id*="nn"]zdiv[data-tag*="edval"]r  r   s    r   test_attribute_containsz(TestSoupSelector.test_attribute_contains!  s    !!v&!D6*', "%$b) 4&) 5$-08T*+fX&D6"v&!D6*tf%efgY'$/0eT]+'fg./wi(%y13	
r'   c                 F    | j                  dg dfdg dfddgfdg f       y )Nzp[lang|="en"])lang-en
lang-en-gb
lang-en-usz[lang|="en"]zp[lang|="fr"]lang-frzp[lang|="gb"]r  r   s    r   test_attribute_exact_or_hypenz.TestSoupSelector.test_attribute_exact_or_hypen>  s4    !!EFDEyk*b!		
r'   c                 h    | j                  dg dfddgfdddgfdg d	fd
ddgfdg fdg fddgf       y )Nz[rel])r  r  r  z	link[rel]r  za[rel]r  r  z[lang])r  r  r  r  zp[class]r  r  z[blah]zp[blah]zdiv[data-tag]r{  r  r   s    r   test_attribute_existsz&TestSoupSelector.test_attribute_existsF  s]    !!)*4&!t}%IJ$)*rNOwi(		
r'   c                 ~    d}t        |d      }|j                  d      \  }| j                  d|j                         y )Nz]<div style="display: wrong">nope</div>
        <div style="display: right">yes</div>
        r  zdiv[style="display: right"]yes)r   r`  r   r   )r   rF  r-   chosens       r   "test_quoted_space_in_selector_namez3TestSoupSelector.test_quoted_space_in_selector_nameR  s<     T=1;;<=.r'   c                     | j                  t        | j                  j                  d       | j                  t        | j                  j                  d       y )Nza:no-such-pseudoclassza:nth-of-type(a))r   r  r-   r`  r  r   s    r   test_unsupported_pseudoclassz-TestSoupSelector.test_unsupported_pseudoclassZ  sE    !1!13J	L 	))+=	?r'   c                 0   | j                   j                  d      }| j                  t        |      d       | j                  |d   j                  d       | j                   j                  d      }| j                  t        |      d       | j                  |d   j                  d       | j                   j                  d      }| j                  t        |      d       | j                   j                  d      }| j                  t        |      d       y )	Nzdiv#inner p:nth-of-type(1)rU   r   	Some textzdiv#inner p:nth-of-type(3)Anotherzdiv#inner p:nth-of-type(4)zdiv p:nth-of-type(0)r-   r`  r   r>   r   rm  s     r   test_nth_of_typez!TestSoupSelector.test_nth_of_typea  s    ii;<S1%Q4 ii;<S1%Q	2 ii;<S1% ii56S1%r'   c                     | j                   j                  d      }| j                  t        |      d       | j                  |d   j                  d       y )Nzdiv#inner > p:nth-of-type(1)rU   r   r  r  rm  s     r   "test_nth_of_type_direct_descendantz3TestSoupSelector.test_nth_of_type_direct_descendantt  sC    ii=>S1%Q4r'   c                 *    | j                  ddg       y )Nz#inner > p:nth-of-type(2)r  r  r   s    r   "test_id_child_selector_nth_of_typez3TestSoupSelector.test_id_child_selector_nth_of_typey  s    6?r'   c                     | j                   j                  dd      }|j                  d      }| j                  |ddg       y )Nr   rr  r6   rz  r{  )r-   r.   r`  r"   )r   rz  selecteds      r   test_select_on_elementz'TestSoupSelector.test_select_on_element|  s?     		u0<<& 	h'(:;r'   c                 N    | j                  ddg       | j                  dg        y )Nz.fancy #innerrz  z.normal #innerr  r   s    r   test_overspecified_child_idz,TestSoupSelector.test_overspecified_child_id  s%    ?WI6+R0r'   c                     | j                  ddg       | j                  ddg       | j                  ddg       | j                  g | j                  j                  d             y )Nz#p1 + h2r  z#p1 + h2 + pr  z#p1 + #header2 + .class1z#p1 + pr   r   r-   r`  r   s    r   test_adjacent_sibling_selectorz/TestSoupSelector.test_adjacent_sibling_selector  sX    :	{3>H:65zBTYY--i89r'   c                     | j                  dddg       | j                  ddg       | j                  ddg       | j                  ddg       | j                  g | j                  j                  d             y )	Nz#p1 ~ h2r  r  z#p1 ~ #header2z#p1 ~ h2 + ar  z#p1 ~ h2 + [rel="me"]z#inner ~ h2r  r   s    r   test_general_sibling_selectorz.TestSoupSelector.test_general_sibling_selector  sn    :	9'=>+i[9>D622TF;TYY--m<=r'   c                 Z    | j                  t        | j                  j                  d       y )Nzh1 >r  r   s    r   test_dangling_combinatorz)TestSoupSelector.test_dangling_combinator  s    +tyy'7'7@r'   c                 ,    | j                  dg d       y )Nzp[lang] ~ p)r  r  r  r  r   s    r   2test_sibling_combinator_wont_select_same_tag_twicezCTestSoupSelector.test_sibling_combinator_wont_select_same_tag_twice  s    =*QRr'   c                 ,    | j                  dddg       y )Nzx, yxidyidr  r   s    r   test_multiple_selectz%TestSoupSelector.test_multiple_select  s    6E5>2r'   c                 ,    | j                  dddg       y )Nzx,yr  r  r  r   s    r   "test_multiple_select_with_no_spacez3TestSoupSelector.test_multiple_select_with_no_space  s    55%.1r'   c                 ,    | j                  dddg       y )Nzx,    yr  r  r  r   s    r   $test_multiple_select_with_more_spacez5TestSoupSelector.test_multiple_select_with_more_space  s    9uen5r'   c                 *    | j                  ddg       y )Nzx, xr  r  r   s    r   test_multiple_select_duplicatedz0TestSoupSelector.test_multiple_select_duplicated  s    6E7+r'   c                 ,    | j                  dddg       y )Nzx, y ~ p[lang=fr]r  r  r  r   s    r   test_multiple_select_siblingz-TestSoupSelector.test_multiple_select_sibling  s    .	0BCr'   c                 ,    | j                  dddg       y )Nzx, y > zr  zidbr  r   s    r   .test_multiple_select_tag_and_direct_descendantz?TestSoupSelector.test_multiple_select_tag_and_direct_descendant  s    :v7r'   c                 ,    | j                  dg d       y )Nzdiv > x, y, zr  r  zidar  zidabzidacr  r   s    r   /test_multiple_select_direct_descendant_and_tagsz@TestSoupSelector.test_multiple_select_direct_descendant_and_tags  s    ?,\]r'   c                 ,    | j                  dg d       y )Nzdiv x,y,  zr  r  r   s    r   (test_multiple_select_indirect_descendantz9TestSoupSelector.test_multiple_select_indirect_descendant  s    =*Z[r'   c                     | j                  t        | j                  j                  d       | j                  t        | j                  j                  d       y )Nz,x, yzx,,yr  r   s    r   test_invalid_multiple_selectz-TestSoupSelector.test_invalid_multiple_select  s:    +tyy'7'7A+tyy'7'7@r'   c                 ,    | j                  dddg       y )Nzp[lang=en], p[lang=en-gb]r  r  r  r   s    r   test_multiple_select_attrsz+TestSoupSelector.test_multiple_select_attrs  s    6L8QRr'   c                 ,    | j                  dg d       y )Nz*x, y > z[id=zida], z[id=zidab], z[id=zidb])r  r  r  r  r   s    r   test_multiple_select_idsz)TestSoupSelector.test_multiple_select_ids  s    GIabr'   c                 ,    | j                  dddg       y )Nzbody > div > x, y > zr  r  r  r   s    r   test_multiple_select_nestedz,TestSoupSelector.test_multiple_select_nested  s    2UFODr'   c                     d}t        |d      }|j                  d      }| j                  dt        |             |j	                  ddg      D ]  }||v rJ  y )Nz3<div class="c1"/><div class="c2"/><div class="c1"/>r  z.c1, .c2rP   c1c2r   )r   r`  r   r>   r?   )r   r^  r-   r  r   s        r   test_select_duplicate_elementsz/TestSoupSelector.test_select_duplicate_elements  sc     GV]3;;z*CM*
 }}T4L}9 	'Gh&&	'r'   N)>r#   r$   r%   r]  rw   r   ri  rk  ro  rt  rx  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r&   r'   r   r[  r[  3  s>   /Db<
 !L69+&
:O
%:BD3
_i
8&4&3A5
5
7<
$

"

:


/?&&5
@<1:>AS326,D8^\AScE'r'   r[  )6rD   pdbr   r  r  rL   r`  bs4r   bs4.builderr   r   bs4.elementr   r   r	   r
   r   r   r   r   r   bs4.testingr   r   r  r  LXML_PRESENTr   r)   rF   rk   rs   r   r   r   r   r  r#  r?  rZ  r`  ry  r  r  r  rX  r  r  r  r  r<  rK  r[  r&   r'   r   <module>r     s      	  
 
 

 /'..u5TA ' ''/t;Dx D*5x 5>83( 83vM ML) L)^r>X r>j)7 )7X5 5$0?8 0?fwH w&, &,P0,] 0,f&( &,*Ik *IZ*M+ *MZ=h =0(0h (0Te:8 e:Nl= l=\)-h )-VxGh xGtX7 X7t2<8 2<h?H ?.(6H (6T['x ['r'   