Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 6]8@sdZddlmZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z mZmZmZmZmZmZmZddlmZmZe jddk Ze jd dk ZGd d d eZGd d d eZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#Gddde#Z$Gddde#Z%Gd d!d!eZ&Gd"d#d#e&Z'Gd$d%d%e&Z(Gd&d'd'eZ)Gd(d)d)eZ*Gd*d+d+eZ+Gd,d-d-eZ,Gd.d/d/eZ-Gd0d1d1eZ.Gd2d3d3eZ/Gd4d5d5eZ0Gd6d7d7eZ1dS)8a8Tests 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_registryHTMLParserTreeBuilder)PY3KCDataComment DeclarationDoctypeNavigableString SoupStrainerTag)SoupTestskipIfZxmlZlxmlc@seZdZddZddZdS)TreeTestcCs|jdd|D|dS)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. cSsg|] }|jqS)string).0tagrr/usr/lib/python3.6/test_tree.py 2sz*TreeTest.assertSelects..N) assertEqual)selftags should_matchrrr assertSelects+szTreeTest.assertSelectscCs|jdd|D|dS)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. cSsg|] }|dqS)idr)rrrrrr;sz-TreeTest.assertSelectsIDs..N)r)rrrrrrassertSelectsIDs4szTreeTest.assertSelectsIDsN)__name__ __module__ __qualname__rrrrrrr)s rc@s8eZdZdZddZddZddZdd Zd d Zd S) TestFindzBasic tests of the find() method. find() just calls find_all() with limit=1, so it's not tested all that thouroughly here. cCs"|jd}|j|jdjddS)Nz 1234b2)souprfindr)rr$rrr test_find_tagEs zTestFind.test_find_tagcCs"|jd}|j|jddddS)Nu

Räksmörgås

u Räksmörgås)r)r$rr%)rr$rrrtest_unicode_text_findIs zTestFind.test_unicode_text_findcCs,|jd}t||jd|jddjdS)Nu&

here it is

z here it isu Räksmörgås)r)r$strrr%text)rr$rrrtest_unicode_attribute_findMs z$TestFind.test_unicode_attribute_findcCs"|jd}|jdt|jdS)z)Test an optimization that finds all tags.zfoobarN)r$rlenfind_all)rr$rrrtest_find_everythingSs zTestFind.test_find_everythingcCs$|jd}|jdt|jddS)z;Test an optimization that finds all tags with a given name.zfoobarbazr+aN)r$rr,r-)rr$rrrtest_find_everything_with_nameXs z'TestFind.test_find_everything_with_nameN) rrr __doc__r&r'r*r.r0rrrrr!>s r!c@s8eZdZdZddZddZddZdd Zd d Zd S) TestFindAllz%Basic tests of the find_all() method.cCs|jd}|j|jdddg|j|jdddg|j|jddgdddg|j|jtjdddddg|j|jdddddgd S) z'You can search the tree for text nodes.uFoobar»bar)r)r)Fooz.*»TN)r$rr-recompile)rr$rrrtest_find_all_text_nodes`s  z$TestFindAll.test_find_all_text_nodescCs|jd}|j|jddddddg|j|jddddg|j|jdd ddddd d g|j|jdd ddddd d gd S)z7You can limit the number of items returned by find_all.z(12345r/)limit1r#3 45rN)r$rr-)rr$rrrtest_find_all_limitps zTestFindAll.test_find_all_limitcCs:|jd}|j|ddddg|j|jdddgdS) Nz!123r/r=)r:r;foo)rr<)r$rr")rr$rrr%test_calling_a_tag_is_calling_findall|s z1TestFindAll.test_calling_a_tag_is_calling_findallcCs.|jd}g}|j||jg|j|dS)Nz)r$appendrr-)rr$lrrrTtest_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursions  z`TestFindAll.test_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursioncCs^|jd}|jd}|jt|d|jd}|jt|d|jdd}|jt|ddS)z%All find_all calls return a ResultSetzr/sourceTrB)r)N)r$r- assertTruehasattr)rr$resultrrrtest_find_all_resultsets    z#TestFindAll.test_find_all_resultsetN) rrr r1r8rArCrFrKrrrrr2]s   r2c@seZdZddZdS)TestFindAllBasicNamespacescCs<|jd}|jd|jdj|jd|jddidjdS)Nz04r?z mathml:msqrtr/zsvg:fillZred)attrs)r$rr%rname)rr$rrrtest_find_by_namespaced_names z7TestFindAllBasicNamespaces.test_find_by_namespaced_nameN)rrr rOrrrrrLsrLcspeZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZZS)TestFindAllByNamez&Test ways of finding tags by tag name.cstt|j|jd|_dS)NzFirst tag. Second tag. Third Nested tag. tag.)superrsetUpr$tree)r) __class__rrrRszTestFindAllByName.setUpcCs|j|jjdddgdS)Nr/z First tag.z Nested tag.)rrSr-)rrrrtest_find_all_by_tag_namesz+TestFindAllByName.test_find_all_by_tag_namecCs\|j|jjddddg|j|jjdddddg|j|jjdtjddddgdS)Nr/z First tag.)r)Tz Nested tag.r)rrSr-r6r7)rrrrtest_find_all_by_name_and_textsz0TestFindAllByName.test_find_all_by_name_and_textcCs|j|jjjddgdS)Nr/z Nested tag.)rrScr-)rrrr!test_find_all_on_non_root_elementsz3TestFindAllByName.test_find_all_on_non_root_elementcCs|j|jdddgdS)Nr/z First tag.z Nested tag.)rrS)rrrr%test_calling_element_invokes_find_allsz7TestFindAllByName.test_calling_element_invokes_find_allcCs |j|jjtdddgdS)Nr/z First tag.z Nested tag.)rrSr-r )rrrrtest_find_all_by_tag_strainersz/TestFindAllByName.test_find_all_by_tag_strainercCs"|j|jjddgdddgdS)Nr/r"z First tag.z Second tag.z Nested tag.)rrSr-)rrrrtest_find_all_by_tag_namessz,TestFindAllByName.test_find_all_by_tag_namescCs$|j|jjddddddgdS)NT)r/r"z First tag.z Second tag.z Nested tag.)rrSr-)rrrrtest_find_all_by_tag_dictsz+TestFindAllByName.test_find_all_by_tag_dictcCs$|j|jjtjddddgdS)Nz^[ab]$z First tag.z Second tag.z Nested tag.)rrSr-r6r7)rrrrtest_find_all_by_tag_resz)TestFindAllByName.test_find_all_by_tag_recCs,dd}|jd}|j|j|ddgdS)NcSs|j|jdkS)Nr)rNget)rrrrid_matches_nameszRTestFindAllByName.test_find_all_with_tags_matching_method..id_matches_namezMatch 1. Does not match. Match 2.zMatch 1.zMatch 2.)r$rr-)rr_rSrrr'test_find_all_with_tags_matching_methods z9TestFindAllByName.test_find_all_with_tags_matching_methodcCsx|jd}|jdd}|jdtjd}|jdddg\}}|jd|j|jd|j|jd|j|jd|jdS)NzH
1
2
3
divza dza br<r;)r$r%r6r7r-rr)rr$Zr1Zr2Zr3Zr4rrr%test_find_with_multi_valued_attributes z7TestFindAllByName.test_find_with_multi_valued_attribute)rrr r1rRrUrVrXrYrZr[r\r]r`rb __classcell__rr)rTrrPs   rPc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!S)"TestFindAllByAttributecCs&|jd}|j|jddddgdS)Nz Matching a. Non-matching Matching b.a. first)rz Matching a.z Matching b.)r$rr-)rrSrrrtest_find_all_by_attribute_namesz6TestFindAllByAttribute.test_find_all_by_attribute_namecCstdjd}djd}|j|}|j|jg|j|d|j|jg|j|jdd|j|jg|j|dgddS)Nuםולשutf8u)titlezsomething else)encoder$rr/r-decode)rZpeacedatar$rrr%test_find_all_by_utf8_attribute_values    zName match. Class match. Non-match. A tag called 'name1'. Zname1)rNzA tag called 'name1'.rN)rMz Name match.classZclass2z Class match.)r$rr-)rrSrrrtest_find_all_by_attribute_dictsz6TestFindAllByAttribute.test_find_all_by_attribute_dictcCs|jd}|j|jddddg|j|jddddg|j|jdd ddg|j|jdddg|j|jdd ddg|j|jdddg|j|jdd dgdS) Nz Class 1. Class 2. Class 1. Class 3 and 4. r/r;)class_zClass 1.rWr<zClass 3 and 4.r?)rM)r$rr-)rrSrrrtest_find_all_by_classsz-TestFindAllByAttribute.test_find_all_by_classcCst|jd}|jdtjdd}|j|dg|jdtjdd}|j|dg|jdtjdd}|j|dgdS)Nz#Found itZgaro)rozFound itr/zo b)r$r-r6r7r)rrSfrrr0test_find_by_class_when_multiple_classes_present-s zGTestFindAllByAttribute.test_find_by_class_when_multiple_classes_presentcCsd|jd}|j|jdtjddgdd}|j|jd|gdd}|j|jd|dgdS) NzFound itr/ZbazFound itcSs t|dkS)Nr9)r,)valuerrrbig_attribute_value@sznTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class..big_attribute_valuecSs t|dkS)Nr9)r,)rtrrrsmall_attribute_valueEszpTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_class..small_attribute_value)r$rr-r6r7)rr$rurvrrr:test_find_all_with_non_dictionary_for_attrs_finds_by_class;s zQTestFindAllByAttribute.test_find_all_with_non_dictionary_for_attrs_finds_by_classcCs|jd}|jd\}}|j||g|jdd|j|g|jdd|j|g|jddd|j|g|jdd|jg|jdddS)Nz*r/rBr3zfoo bar)rozbar foo)r$r-r)rr$r/Za2rrr:test_find_all_with_string_for_attrs_finds_multiple_classesKs zQTestFindAllByAttribute.test_find_all_with_string_for_attrs_finds_multiple_classescCs0|jd}tddid}|j|j|dgdS)Nzi Match. Non-match.rre)rMzMatch.)r$r rr-)rrSstrainerrrr'test_find_all_by_attribute_soupstrainerWsz>TestFindAllByAttribute.test_find_all_by_attribute_soupstrainercCs&|jd}|j|jddddgdS)NzID present. No ID present. ID is empty.r/)rzNo ID present.)r$rr-)rrSrrr$test_find_all_with_missing_attribute_sz;TestFindAllByAttribute.test_find_all_with_missing_attributecCs&|jd}|j|jddddgdS)NzID present. No ID present. ID is empty.T)rz ID present.z ID is empty.)r$rr-)rrSrrr$test_find_all_with_defined_attributegsz;TestFindAllByAttribute.test_find_all_with_defined_attributecCs>|jd}ddg}|j|jdd||j|jdd|dS)Nz[Unquoted attribute. Quoted attribute.zUnquoted attribute.zQuoted attribute.r=)rr;)r$rr-)rrSZexpectedrrr$test_find_all_with_numeric_attributeps z;TestFindAllByAttribute.test_find_all_with_numeric_attributecCs,|jd}|j|jdddgdddgdS)Nz1 2 3 No ID.r;r<r?)r)r$rr-)rrSrrr(test_find_all_with_list_attribute_valuesysz?TestFindAllByAttribute.test_find_all_with_list_attribute_valuescCs,|jd}|j|jtjddddgdS)NzOne a. Two as. Mixed as and bs. One b. No ID.z^a+$)rzOne a.zTwo as.)r$rr-r6r7)rrSrrr5test_find_all_with_regular_expression_attribute_valueszLTestFindAllByAttribute.test_find_all_with_regular_expression_attribute_valuecCsX|jd}|j}|j|g|jddd|jg|jddd|jg|jddddS)Nzfoobarfoor/rB)r)r3)r$r/rr-)rr$r/rrr'test_find_by_name_and_containing_strings  z>TestFindAllByAttribute.test_find_by_name_and_containing_stringcCs*|jd}|j|jd|jddddS)Nz"foofoor/rB)r))r$rr-)rr$rrr=test_find_by_name_and_containing_string_when_string_is_burieds zTTestFindAllByAttribute.test_find_by_name_and_containing_string_when_string_is_buriedcCsB|jd}|j}|j|g|jddd|jg|jddddS)Nz"foofoor+rB)rr)r=r3)r$r/rr-)rr$r/rrr,test_find_by_attribute_and_containing_strings zCTestFindAllByAttribute.test_find_by_attribute_and_containing_stringN)rrr rfrlrnrprsrwrxrzr{r|r}r~rrrrrrrrrds       rdc@seZdZdZddZdS) TestIndexzTest Tag.indexcCsN|jd}|j}x(t|jD]\}}|j||j|qW|jt|jddS)Nah
Identical Not identical Identical Identical with child Also not identical Identical with child
r=)r$ra enumeratecontentsrindex assertRaises ValueError)rrSraielementrrr test_indexs zTestIndex.test_indexN)rrr r1rrrrrrsrcs`eZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ Z S)TestParentOperationsz;Test navigation and searching through an element's parents.cs(tt|j|jd|_|jj|_dS)Na1
          Start here
      )rQrrRr$rSr"start)r)rTrrrRszTestParentOperations.setUpcCsF|j|jjdd|j|jjjdd|j|jjjjdddS)Nrbottommiddletop)rrparent)rrrr test_parentsz TestParentOperations.test_parentcCs |jjd}|j|j|jdS)Nr)rSrrr)rZtop_tagrrr%test_parent_of_top_tag_is_soup_objects z:TestParentOperations.test_parent_of_top_tag_is_soup_objectcCs|jd|jjdS)N)rrSr)rrrrtest_soup_object_has_no_parentsz3TestParentOperations.test_soup_object_has_no_parentcCs8|j|jjddddg|j|jjddddgdS)Nulrrr)r)rrZ find_parents)rrrrtest_find_parentssz&TestParentOperations.test_find_parentscCs8|j|jjddd|j|jjddddddS)Nrrrr)r)rr find_parent)rrrrtest_find_parentsz%TestParentOperations.test_find_parentcCs"|jjdd}|j|jjddS)Nz Start here)r)r")rSr%rrrN)rr)rrrtest_parent_of_text_elementsz0TestParentOperations.test_parent_of_text_elementcCs(|jjdd}|j|jddddS)Nz Start here)r)rrr)rSr%rr)rr)rrrtest_text_element_find_parentsz2TestParentOperations.test_text_element_find_parentcCs(dd|jjD}|j|dddgdS)NcSs&g|]}|dk rd|jkr|dqS)Nr)rM)rrrrrrsz>TestParentOperations.test_parent_generator..rrr)rparentsr)rrrrrtest_parent_generatorsz*TestParentOperations.test_parent_generator)rrr r1rRrrrrrrrrrcrr)rTrrs rcseZdZfddZZS) ProximityTestcstt|j|jd|_dS)NzgOneTwoThree)rQrrRr$rS)r)rTrrrRszProximityTest.setUp)rrr rRrcrr)rTrrsrcsTeZdZfddZddZddZddZd d Zd d Zd dZ ddZ Z S)TestNextOperationscstt|j|jj|_dS)N)rQrrRrSr"r)r)rTrrrRszTestNextOperations.setUpcCs*|j|jjd|j|jjjdddS)NOnerr#)rr next_element)rrrr test_nextszTestNextOperations.test_nextcCs |jjdd}|j|jddS)NThree)r))rSr%rr)rZlastrrrtest_next_of_last_item_is_nonesz1TestNextOperations.test_next_of_last_item_is_nonecCs|j|jjddS)N)rrSr)rrrrtest_next_of_root_is_nonesz,TestNextOperations.test_next_of_root_is_nonecCsB|j|jjdddg|jjdd|j|jjdddgdS)Nr"Tworr9)r)rr find_all_next)rrrrtest_find_all_nextsz%TestNextOperations.test_find_all_nextcCs2|j|jjddd|j|jjddddS)Nr"rr#r)r))rr find_next)rrrrtest_find_next sz!TestNextOperations.test_find_nextcCs<|jjdd}|j|jdjd|j|jdddgdS)Nr)r)r"rr)rSr%rrrrr)rr)rrrtest_find_next_for_text_elementsz2TestNextOperations.test_find_next_for_text_elementcCsF|jjdd}dd|jD}|\}}|j|dd|j|ddS)Nr)r)cSsg|]}|qSrr)rnoderrrrsz:TestNextOperations.test_next_generator..rr<r)rSr%Z next_elementsr)rrZ successorsrrrrrtest_next_generators z&TestNextOperations.test_next_generator) rrr rRrrrrrrrrcrr)rTrrs rcsTeZdZfddZddZddZddZd d Zd d Zd dZ ddZ Z S)TestPreviousOperationscs"tt|j|jjdd|_dS)Nr)r))rQrrRrSr%end)r)rTrrrRszTestPreviousOperations.setUpcCs*|j|jjdd|j|jjjddS)Nrr<r)rrprevious_element)rrrr test_previous!sz$TestPreviousOperations.test_previouscCs|jjd}|j|jddS)Nhtml)rSr%rr)rrerrr#test_previous_of_first_item_is_none%s z:TestPreviousOperations.test_previous_of_first_item_is_nonecCsdS)Nr)rrrrtest_previous_of_root_is_none)sz4TestPreviousOperations.test_previous_of_root_is_nonecCs6|j|jjddddg|j|jjdddgdS)Nr"rrrr=)r)rrfind_all_previous)rrrrtest_find_all_previous/sz-TestPreviousOperations.test_find_all_previouscCs2|j|jjddd|j|jjddddS)Nr"rr<r)r))rr find_previous)rrrrtest_find_previous7sz)TestPreviousOperations.test_find_previouscCs>|jjdd}|j|jdjd|j|jddddgdS)Nr)r)r"rr)rSr%rrrrr)rr)rrr#test_find_previous_for_text_element;sz:TestPreviousOperations.test_find_previous_for_text_elementcCsh|jjdd}dd|jD}|\}}}}|j|dd|j|jd|j|jd|j|jd dS) Nr)r)cSsg|]}|qSrr)rrrrrrCszBTestPreviousOperations.test_previous_generator..rr;bodyheadr)rSr%Zprevious_elementsrrN)rrZ predecessorsr"rrrrrrtest_previous_generatorAs z.TestPreviousOperations.test_previous_generator) rrr rRrrrrrrrrcrr)rTrrs rcseZdZfddZZS) SiblingTestcs4tt|jd}tjdjd|}|j||_dS)Na z\n\s*)rQrrRr6r7subr$rS)rmarkup)rTrrrRPs zSiblingTest.setUp)rrr rRrcrr)rTrrNsrcsLeZdZfddZddZddZddZd d Zd d Zd dZ Z S)TestNextSiblingcs"tt|j|jjdd|_dS)Nr;)r)rQrrRrSr%r)r)rTrrrRfszTestNextSibling.setUpcCs|j|jjddS)N)rrS next_sibling)rrrr!test_next_sibling_of_root_is_nonejsz1TestNextSibling.test_next_sibling_of_root_is_nonecCsB|j|jjdd|j|jjjdd|j|jjdddS)Nrr#r<z1.1)rrrr)rrrrtest_next_siblingmsz!TestNextSibling.test_next_siblingcCsN|j|jjjd|jjdd}|j|jd|jjdd}|j|jddS)Nz1.1)rr?)rrSrrr%)r nested_spanZ last_spanrrrtest_next_sibling_may_not_existts z/TestNextSibling.test_next_sibling_may_not_existcCs|j|jjddddS)Nspanrr#)rrfind_next_sibling)rrrrtest_find_next_sibling}sz&TestNextSibling.test_find_next_siblingcCs6|j|jjddddg|j|jjdddgdS)Nrr#r<r?)r)rrfind_next_siblings)rrrrtest_next_siblingss z"TestNextSibling.test_next_siblingscCsv|jd}|jdd}|j|jjd|j|jjd|j|jddg|j|jddd|j|jddddS)NzFoobarbazr4)r)r"bazr3nonesuch)r$r%rrrNrrr)rr$rrrr"test_next_sibling_for_text_elements  z2TestNextSibling.test_next_sibling_for_text_element) rrr rRrrrrrrrcrr)rTrrds  rcsLeZdZfddZddZddZddZd d Zd d Zd dZ Z S)TestPreviousSiblingcs"tt|j|jjdd|_dS)Nr?)r)rQrrRrSr%r)r)rTrrrRszTestPreviousSibling.setUpcCs|j|jjddS)N)rrSprevious_sibling)rrrr%test_previous_sibling_of_root_is_nonesz9TestPreviousSibling.test_previous_sibling_of_root_is_nonecCsB|j|jjdd|j|jjjdd|j|jjdddS)Nrr<r#z3.1)rrrr)rrrrtest_previous_siblingsz)TestPreviousSibling.test_previous_siblingcCsN|j|jjjd|jjdd}|j|jd|jjdd}|j|jddS)Nz1.1)rr;)rrSrrr%)rrZ first_spanrrr#test_previous_sibling_may_not_exists z7TestPreviousSibling.test_previous_sibling_may_not_existcCs|j|jjddddS)Nrrr<)rrfind_previous_sibling)rrrrtest_find_previous_siblingsz.TestPreviousSibling.test_find_previous_siblingcCs6|j|jjddddg|j|jjdddgdS)Nrr<r#r;)r)rrfind_previous_siblings)rrrrtest_previous_siblingss z*TestPreviousSibling.test_previous_siblingscCsv|jd}|jdd}|j|jjd|j|jjd|j|jddg|j|jddd|j|jddddS)NzFoobarbazr)r)r"r4r3r)r$r%rrrNrrr)rr$rrrr&test_previous_sibling_for_text_elements  z:TestPreviousSibling.test_previous_sibling_for_text_element) rrr rRrrrrrrrcrr)rTrrs  rc@s0eZdZdZddZddZddZdd Zd S) TestTagCreationz$Test the ability to create new tags.cCsd|jd}|jddddid}|jt|t|jd|j|jtddd|j|jd|j dS)NrrBrrNza name)r3rM)r3rN) r$new_tagrH isinstancer rrNdictrMr)rr$rrrr test_new_tags  zTestTagCreation.test_new_tagcCstrBtdd}|jd}|jd}|jd|j|jd|jtdd}|jd}|jd}|jd|j|jd|jdS) Nrzlxml-xmlbrps
      s

      z html.parsers

      )XML_BUILDER_PRESENTrrrri)rZxml_soupZxml_brZxml_pZ html_soupZhtml_brZhtml_prrr1test_tag_inherits_self_closing_rules_from_builders      zATestTagCreation.test_tag_inherits_self_closing_rules_from_buildercCs4|jd}|jd}|jd||jt|tdS)NrrB)r$ new_stringrrHrr )rr$srrr'test_new_string_creates_navigablestrings   z7TestTagCreation.test_new_string_creates_navigablestringcCs6|jd}|jdt}|jd||jt|tdS)NrrB)r$rrrrHr)rr$rrrr3test_new_string_can_create_navigablestring_subclasss   zCTestTagCreation.test_new_string_can_create_navigablestring_subclassN)rrr r1rrrrrrrrrs rc@s<eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMS)NTestTreeModificationcCsl|jd}d|jd<|j|j|jd|jd=|j|j|jdd|jd<|j|j|jddS) Nzr+rzzrBZid2z)r$r/rrj document_for)rr$rrrtest_attribute_modifications   z0TestTreeModification.test_attribute_modificationcCsltjd}|jd|d}t||d}t||d}d|d<|jjd||jjd ||j|jjd dS) Nrz )builderr/olzhttp://foo.com/Zhrefrr=s4
        )rlookupr$r rinsertrri)rrr$r/rrrrtest_new_tag_creations   z*TestTreeModification.test_new_tag_creationcCs\d}|j|}|jdd}|j}|jddj|j|j|j||j|j|jddS)NzT

        Don't leave me here.

        Don't leave!

        r#)rzD

        Don't leave me .

        Don't leave!here

        )r$r%r"rDrrrjr)rdocr$Z second_paraZboldrrr!test_append_to_contents_moves_tags   z6TestTreeModification.test_append_to_contents_moves_tagcCs0d}|j|}|j}|j|j}|j||dS)Nz)r$r/ replace_withrWr)rr)r$r/new_arrr1test_replace_with_returns_thing_that_was_replaceds   zFTestTreeModification.test_replace_with_returns_thing_that_was_replacedcCs,d}|j|}|j}|j}|j||dS)Nz)r$r/unwrapr)rr)r$r/rrrr+test_unwrap_returns_thing_that_was_replaceds  z@TestTreeModification.test_unwrap_returns_thing_that_was_replacedcCsJ|jd}|j}|j|jd|j|jt|j|jt|j|j dS)NzFooBar) r$r/extractrrrrrrrW)rr$r/rrrItest_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parents  z^TestTreeModification.test_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parentcCs:d}|j|}|j}|jj||j|j|j|dS)Nz-Foo)r$rWrrrjr)rr)r$rWrrrtest_replace_tag_with_itself's   z1TestTreeModification.test_replace_tag_with_itselfcCs&d}|j|}|jt|jj|jdS)Nz)r$rrr"rr/)rr)r$rrr1test_replace_tag_with_its_parent_raises_exception.s zFTestTreeModification.test_replace_tag_with_its_parent_raises_exceptioncCs(d}|j|}|jt|jjd|jdS)Nzr)r$rrr/r)rr)r$rrr,test_insert_tag_into_itself_raises_exception3s zATestTreeModification.test_insert_tag_into_itself_raises_exceptionc Cs|jd}d}|j|}|jd|x|jD]}t|t s,tq,Wt|j\}}}}|jd|j |jd|j |jd|j |jd|j dS) zInserting one BeautifulSoup object into another actually inserts all of its children -- you'll never combine BeautifulSoup objects. z-

        And now, a word:

        And we're back.

        z

        p2

        p3

        r=zAnd now, a word:p2p3zAnd we're back.N) r$rZ descendantsrrAssertionErrorlistZchildrenrr) rr$r)Z to_insertrp1rrZp4rrr1test_insert_beautifulsoup_object_inserts_children8s    zFTestTreeModification.test_insert_beautifulsoup_object_inserts_childrencCsX|jd}|j}|jd}|jdd|j\}}|jd|jd|jd|jjdS)Nz

        onethree

        rr=ZtworZthree)r$r/rrZ replaceWithrr"r)rr$r/r"leftrightrrr3test_replace_with_maintains_next_element_throughoutLs      zHTestTreeModification.test_replace_with_maintains_next_element_throughoutcCsl|jd}|jddjd|jdd}|j}|j|j||j|j||j|jj||j|jddS)Nz Argh!zArgh!)r)zHooray!)r$r%rr"rrrr)rr$new_textr"rrrtest_replace_final_node[s  z,TestTreeModification.test_replace_final_nodecCs|jd}|jjdd|j|j|jd|jdd}|j|jd|j|jj||j|j d|j|j j ||j|j d|j|j|j dS)NzArgh!r=zHooray!z!Argh!Hooray!)r)zArgh!) r$r"rrrjrr%rrrrrW)rr$rrrrtest_consecutive_text_nodeses   z0TestTreeModification.test_consecutive_text_nodescCsT|jd}|jjdd|jjdd|jddg|jj|j|jjdjddS)Nzrr3rB)r$r/rrrr)rr$rrrtest_insert_stringzs  z'TestTreeModification.test_insert_stringcCs|j}|jd|d}t||d}|jdd|jjd||j|j|jd|j}|j|j ||j|j ||j dd }|j|j ||j|j ||j}|j|j ||j|j ||j dd }|j|j||j|j ||j|j |dS) Nz%Findlady!)rZmagictagrther=z=Findthelady!ZFind)r))Zdefault_builderr$r rr/rrjrr"rrr%rrrWr)rrr$Z magic_tagZb_tagr%Zc_tagrrrrtest_insert_tags,      z$TestTreeModification.test_insert_tagcCs0d}|j|}|jj|j|j||jdS)Nz)r$r/rDr"rrj)rrkr$rrr*test_append_child_thats_already_at_the_ends z?TestTreeModification.test_append_child_thats_already_at_the_endcCs2d}|j|}|jjd|j|jd|jdS)Nzrz)r$r/rdrrj)rrkr$rrr$test_move_tag_to_beginning_of_parents z9TestTreeModification.test_move_tag_to_beginning_of_parentcCs.|jd}|jjdd|jt|jddS)Nz
        r=ZContentsz
        Contents
        )r$rrrr()rr$rrr&test_insert_works_on_empty_element_tags z;TestTreeModification.test_insert_works_on_empty_element_tagcCs`|jd}|jjd|jjd|j|j|jd|jj|j|j|j|jddS)NzfoobarBAZQUUXzQUUXfooBAZbarzQUUXbarfooBAZ)r$r" insert_beforer/rrjr)rr$rrrtest_insert_befores   z'TestTreeModification.test_insert_beforecCs`|jd}|jjd|jjd|j|j|jd|jj|j|j|j|jddS)Nzfoobarr r zfooQUUXbarBAZzQUUXbarfooBAZ)r$r" insert_afterr/rrjr)rr$rrrtest_insert_afters   z&TestTreeModification.test_insert_aftercCsR|jd}|jd}|jd}|jt|j||jt|j||jt|j|dS)Nrr/)r$rrrrrNotImplementedError)rr$rrrrr:test_insert_after_raises_exception_if_after_has_no_meanings    zOTestTreeModification.test_insert_after_raises_exception_if_after_has_no_meaningcCsR|jd}|jd}|jd}|jt|j||jt|j||jt|j|dS)Nrr/)r$rrrrrr)rr$rrrrrFtest_insert_before_raises_notimplementederror_if_before_has_no_meanings    z[TestTreeModification.test_insert_before_raises_notimplementederror_if_before_has_no_meaningcCsv|jd}|jd\}}|j||j|j|jd|j|jd|j|j|j|j|jd|j|j ddS)Nz;

        There's no business like show business

        r"z0

        There's business like no business

        noz business) r$r-rrrjrrrrr)rr$rZshowrrrtest_replace_withs z&TestTreeModification.test_replace_withcCs0d}|j|}|jj|j|jd|jdS)Nzz)r$r"rrWrrj)rrkr$rrrtest_replace_first_childs z-TestTreeModification.test_replace_first_childcCs0d}|j|}|jj|j|jd|jdS)Nzz)r$rWrr"rrj)rrkr$rrrtest_replace_last_childs z,TestTreeModification.test_replace_last_childcCs|jd}|j}|j}|j||j|j|jd|j|jd|j|jddj d|j|j d|j|j d|j|j d|j|j|j |j|j d|j|j j |j|j|j d|jdd}|j}|j|j ||j|j ||j|j ||j|j |dS)NzQWereservetherighttorefuseservicez-Werefusetoservicer)r)ZWeZto)r$r"rrrrrjrrr%rrrrr/eg)rr$Z remove_tagZmove_tagZto_textZg_tagrrrtest_nested_tag_replace_withs.   z1TestTreeModification.test_nested_tag_replace_withcCs6|jd}|jj|j|jd|j|jjddS)NzI

        Unneeded formatting is unneeded

        zUnneeded formatting is unneeded)r$emrrrr))rrSrrr test_unwraps  z TestTreeModification.test_unwrapcCsF|jd}|jj|jd}|j|jd|j|j|jddS)NzI wish I was bold.r"zI wish I was bold.)r$rwraprrrjr)rr$rtrrr test_wrap"s  zTestTreeModification.test_wrapcCs4|jd}|jjj|j|j|j|jddS)NzI wish I was bold.zI wish I was bold.)r$r"rrrrjr)rr$rrr%test_wrap_extracts_tag_from_elsewhere)s z:TestTreeModification.test_wrap_extracts_tag_from_elsewherecCsH|jd}|jjj|j|jdt|jj|j|j|jddS)Nz+I like being bold.I wish I was bold.r+z+I like being bold.I wish I was bold.) r$r"rrrr,rrjr)rr$rrr&test_wrap_puts_new_contents_at_the_end/s   z;TestTreeModification.test_wrap_puts_new_contents_at_the_endcCs|jd}|jt|jjd|jddj}|j|jd|j|jd|jt|jjd|j|jd|j|j d|j|j j d|jdd }|jd d }|j|j ||j|j ||j|j ||j|j |dS) NzRSome content. More content.r9Znav)rz6Some content. More content.zr+zSome content. )r)z More content.) r$rr,rrr%rrjrrrrr)rr$Z extractedZ content_1Z content_2rrr test_extract7s"   z!TestTreeModification.test_extractcCsz|jd}|jj}|jj}|jd}|jd}|jj||jj||j|j|j||jj|j||jjdS)NzfoobarrBr3)r$r/rr"rrDrr)rr$Zfoo_1Zbar_1Zfoo_2Zbar_2rrr4test_extract_distinguishes_between_identical_stringsPs     zITestTreeModification.test_extract_distinguishes_between_identical_stringscs8|jdfddjdD|jdtjdS)Nzv csg|]}jjqSr)scriptr)rr)r$rrrmszKTestTreeModification.test_extract_multiples_of_same_tag..r$z )r$r-rr(r)rr)r$r"test_extract_multiples_of_same_tagas z7TestTreeModification.test_extract_multiples_of_same_tagcCs.|jd}|jdj|jd|jddS)Nz hi r)r$r%rr)rr$rrrBtest_extract_works_when_element_is_surrounded_by_identical_stringsqszWTestTreeModification.test_extract_works_when_element_is_surrounded_by_identical_stringscCsf|jd}|j}|jj|jt|jjd|jt|d|j }|jdd|jdt|jdS)z Tag.clear()z4

        String Italicized and another

        rrT)Z decomposeN) r$r/rclearrr,rrHrIr)rr$r/rrrr test_clearzs   zTestTreeModification.test_clearcCsB|jd}d|j_|j|jjdgd|j_|j|jjdgdS)zTag.string = 'string'z rBr3N)r$r/rrrr")rr$rrrtest_string_sets  z$TestTreeModification.test_string_setcCs,|jd}|jj|j_|j|jjddS)Nzfoobarsbarbar)r$rWrr"rr/ri)rr$rrr/test_string_set_does_not_affect_original_strings  zDTestTreeModification.test_string_set_does_not_affect_original_stringcCs2|jd}td}||j_|jt|jjtdS)NzrB)r$rr/rrHr)rr$cdatarrr)test_set_string_preserves_class_of_strings z>TestTreeModification.test_set_string_preserves_class_of_stringN))rrr rrrrrrrrrrrrrrrrr r rrrrrrrrrrr r!r"r#r%r&r(r)r*r,rrrrrsL       $ rc@sxeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZdS)TestElementObjectsz)Test various features of element objects.cCsV|jd}|jt|jd|jt|d|jt|jd|jt|jjddS)z3The length of an element is its number of children.z123r=r9N)r$rr,rr)rr$rrrtest_lens  zTestElementObjects.test_lencCsL|jd}|j|j|jd|j|jj|jdjd|j|jddS)z2Accessing a Python member .foo invokes find('foo')zr"rN)r$rr"r%rr/)rr$rrrtest_member_access_invokes_finds z2TestElementObjects.test_member_access_invokes_findc CsP|jd}tjdd }|j}WdQRX|j|j||jdt|djdS)NzT)recordzp.bTag is deprecated, use .find("b") instead. If you really were looking for a tag called bTag, use .find("bTag")r)r$warningscatch_warningsZbTagrr"r(message)rr$wrrrrtest_deprecated_member_accesss z0TestElementObjects.test_deprecated_member_accesscCs2|jd}|j|jjd|j|jjddS)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. zattrZattr2N)r$rHrBhas_attr assertFalse)rr$rrr test_has_attrs z TestElementObjects.test_has_attrcCsd}|j|ddS)Nz%z%)ZassertSoupEquals)rrrrr.test_attributes_come_out_in_alphabetical_orderszATestElementObjects.test_attributes_come_out_in_alphabetical_ordercCs|jd}|j|jjddS)Nz foorB)r$rr"r)rr$rrr test_strings zTestElementObjects.test_stringcCs|jd}|j|jjddS)Nz)r$rr"r)rr$rrrtest_empty_tag_has_no_strings z/TestElementObjects.test_empty_tag_has_no_stringcCs`|jd}|j|jjd|jd}|j|jjd|jd}|jjdd|j|jjddS)Nzfoo
        zfoobarz foor=r3)r$rr"rr/r)rr$rrr-test_tag_with_multiple_children_has_no_strings   z@TestElementObjects.test_tag_with_multiple_children_has_no_stringcCs,|jd}|j|jjd|j|jddS)NzfoorB)r$rr/r)rr$rrr)test_tag_with_recursive_string_has_strings zfeozN)r$r8r"r)rr$rrrtest_lack_of_strings  z&TestElementObjects.test_lack_of_stringcCs`|jd}|j|jjd|j|jjddd|j|jjdd|j|jjddddd S) zBTag.text and Tag.get_text(sep=u"") -> all child text, concatenatedzar t zar t T)stripZart,z a,r, , t za,r,tN)r$rr/r)get_text)rr$rrr test_all_texts  z TestElementObjects.test_all_textcCsJ|jd}|j|jd|j|jttfdd|j|jddddS)NzfoobarZfoobar)typesZ fooIGNOREbar)r$rrBr r)rr$rrrtest_get_text_ignores_commentss  z1TestElementObjects.test_get_text_ignores_commentscCs$|jd}|jddgt|jdS)NzfoobarrBr3)r$rrZstrings)rr$rrr!test_all_strings_ignores_commentss z4TestElementObjects.test_all_strings_ignores_commentsN)rrr r1r.r/r5r9r:r;r<r=r>r?rCrErFrrrrr-s   r-c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)TestCDAtaListAttributesz0Testing cdata-list attributes like 'class'. cCs"|jd}|jdg|jddS)NzrBrm)r$rr/)rr$rrrtest_single_value_becomes_list s z6TestCDAtaListAttributes.test_single_value_becomes_listcCs$|jd}|jddg|jddS)NzrBr3rm)r$rr/)rr$rrr!test_multiple_values_becomes_lists z9TestCDAtaListAttributes.test_multiple_values_becomes_listcCs&|jd}|jdddg|jddS)NzrBr3rrm)r$rr/)rr$rrr2test_multiple_values_separated_by_weird_whitespaces zJTestCDAtaListAttributes.test_multiple_values_separated_by_weird_whitespacecCs |jd}|jd|jjdS)Nzs)r$rr/ri)rr$rrr,test_attributes_joined_into_string_on_outputs zDTestCDAtaListAttributes.test_attributes_joined_into_string_on_outputcCs$|jd}|jdg|jjddS)Nzzabc defr)r$rr/Zget_attribute_list)rr$rrrtest_get_attribute_lists z/TestCDAtaListAttributes.test_get_attribute_listcCs$|jd}|jddg|jddS)Nz(
        z ISO-8859-1zUTF-8zaccept-charset)r$rZform)rr$rrrtest_accept_charset!s z+TestCDAtaListAttributes.test_accept_charsetcCs$d}|j|}|jd|jddS)Nz)zISO-8859-1 UTF-8zaccept-charset)r$rr/)rrkr$rrr-test_cdata_attribute_applying_only_to_one_tag%s zETestCDAtaListAttributes.test_cdata_attribute_applying_only_to_one_tagcs6|jdj|jdjfdd}|jt|dS)Nrcs d_dS)NrB)rNr)rrrt0szJTestCDAtaListAttributes.test_string_has_immutable_name_property..t)r$rrrNrAttributeError)rrOr)rr'test_string_has_immutable_name_property-s  z?TestCDAtaListAttributes.test_string_has_immutable_name_propertyN) rrr r1rHrIrJrKrLrMrNrQrrrrrG srGcs`eZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ Z S)TestPersistencez*Testing features like pickle and deepcopy.cs&tt|jd|_|j|j|_dS)Nay Beautiful Soup: We called him Tortoise because he taught us. foo bar )rQrRrRZpager$rS)r)rTrrrR7szTestPersistence.setUpcCs@tj|jd}tj|}|j|jt|j|j|jjdS)Nr+)pickledumpsrSloadsrrTrrj)rdumpedloadedrrr!test_pickle_and_unpickle_identityKs z1TestPersistence.test_pickle_and_unpickle_identitycCs&tj|j}|j|j|jjdS)N)copydeepcopyrSrrj)rZcopiedrrrtest_deepcopy_identitySs z&TestPersistence.test_deepcopy_identitycCs:tdd}|j}|j}|jdt||j||jdS)Ns

         

        z html.parseru

         

        )rZoriginal_encoding__copy__rr()rr$encodingrYrrrtest_copy_preserves_encodingXs  z,TestPersistence.test_copy_preserves_encodingcCs>d}|j|}tj|tj}tj|}|j|j|jdS)Nu )r$rSrTZHIGHEST_PROTOCOLrUrrj)rrr$rVrWrrrtest_unicode_pickle_s   z#TestPersistence.test_unicode_picklecCszd}|j|}|jdd}tj|}|j|||jd|j|jd|j|jd|j|jd|j|jd|jdS)NzFooBarr4)r) r$r%rYrrrassertNotEqualrr)rrr$s1s2rrr1test_copy_navigablestring_is_not_attached_to_treegs    zATestPersistence.test_copy_navigablestring_is_not_attached_to_treecCs>d}|j|}|j}tj|}|j|||jt|tdS)Nz)r$rrYrrHrr)rrr$rarbrrr0test_copy_navigablestring_subclass_has_same_typess    z@TestPersistence.test_copy_navigablestring_subclass_has_same_typecCs(d}|j|}tj|}|j||dS)Nz)
        FooBar
        end)r$rYr)rrr$Z soup_copyrrrtest_copy_entire_soup{s  z%TestPersistence.test_copy_entire_soupcCsd}|j|}|j}tj|}|jt|t||j|||j||k|jd|j|jd|j|jd|jddj |j d|jddj dS)Nz)
        FooBar
        endZBar)r) r$rarYrr(r8rrr%rr`)rrr$raZdiv_copyrrrtest_copy_tag_copies_contentss   z-TestPersistence.test_copy_tag_copies_contents)rrr r1rRrXr[r^r_rcrdrerfrcrr)rTrrR4s  rRc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!S)"TestSubstitutionscCs0d}|j|}|jdd}|j||jddS)Nu#<<Sacré bleu!>>minimal) formatter)r$rjrr)rrr$decodedrrr!test_default_formatter_is_minimals  z3TestSubstitutions.test_default_formatter_is_minimalcCs0d}|j|}|jdd}|j||jddS)Nu'
        <<Sacré bleu!>>r)riz.
        <<Sacré bleu!>>)r$rjrr)rrr$rjrrrtest_formatter_htmls   z%TestSubstitutions.test_formatter_htmlcCs0d}|j|}|jdd}|j||jddS)Nu'
        <<Sacré bleu!>>Zhtml5)riz-
        <<Sacré bleu!>>)r$rjrr)rrr$rjrrrtest_formatter_html5s   z&TestSubstitutions.test_formatter_html5cCs0d}|j|}|jdd}|j||jddS)Nu#<<Sacré bleu!>>rh)ri)r$rjrr)rrr$rjrrrtest_formatter_minimals  z(TestSubstitutions.test_formatter_minimalcCs0d}|j|}|jdd}|j||jddS)Nu#<<Sacré bleu!>>)riu<>)r$rjrr)rrr$rjrrrtest_formatter_nulls   z%TestSubstitutions.test_formatter_nullcCs4d}|j|}|jddd}|j||jddS)Nz!<foo>bar
        cSs|jS)N)upper)xrrrsz9TestSubstitutions.test_formatter_custom..)rizBAR
        )r$rjrr)rrr$rjrrrtest_formatter_customs  z'TestSubstitutions.test_formatter_customcCsd}|j|}|j}d}|j||j|j||jddd}|j||jdd|j||jddd}|j||jdd ddS) Nu%eu)erh)riz/eru%EcSs|jS)N)rp)rqrrrrrszMTestSubstitutions.test_formatter_is_run_on_attribute_values..)r$r/rrj)rrr$r/Zexpect_minimalZ expect_htmlZ expect_upperrrr)test_formatter_is_run_on_attribute_valuess z;TestSubstitutions.test_formatter_is_run_on_attribute_valuescCs$d}t|dj}|jd|kdS)NzO z html.parsers < < hey > >)rrirH)rrencodedrrr2test_formatter_skips_script_tag_for_html_documentsszDTestSubstitutions.test_formatter_skips_script_tag_for_html_documentscCs$d}t|dj}|jd|kdS)NzF z html.parsers < < hey > >)rrirH)rrrurrr1test_formatter_skips_style_tag_for_html_documentsszCTestSubstitutions.test_formatter_skips_style_tag_for_html_documentscCs |jd}|jd|jjdS)Nz*
        foo
          	bar
          
          
        baz z/
        foo
          	bar
          
          
        baz
        )r$rraprettify)rr$rrr,test_prettify_leaves_preformatted_text_alones z>TestSubstitutions.test_prettify_leaves_preformatted_text_alonecCs,tdd}|jddd}|jd|kdS)Nzfooz html.parsercSs|jS)N)rp)rqrrrrrszLTestSubstitutions.test_prettify_accepts_formatter_function..)riZFOO)rrxrH)rr$Zprettyrrr(test_prettify_accepts_formatter_functions z:TestSubstitutions.test_prettify_accepts_formatter_functioncCs"|jd}|jtt|jdS)Nz)r$rr(typerx)rr$rrr(test_prettify_outputs_unicode_by_defaults z:TestSubstitutions.test_prettify_outputs_unicode_by_defaultcCs$|jd}|jtt|jddS)Nzzutf-8)r$rbytesr{rx)rr$rrrtest_prettify_can_encode_datas z/TestSubstitutions.test_prettify_can_encode_datacCs0d}|j|}|jjd}|j||jddS)NuSacré bleu!zutf-8)r$r"rir)rrr$rurrr,test_html_entity_substitution_off_by_defaults  z>TestSubstitutions.test_html_entity_substitution_off_by_defaultcCsd}|j|}|j|jdd|jd}|jd|k|jd}|jd|k|jd}|jd |k|jd jd }|jd |kdS) NzEZcontentztext/html; charset=x-sjiszutf-8s charset=utf-8euc_jpscharset=euc_jpz shift-jisscharset=shift-jiszutf-16zcharset=utf-16)r$rmetarirHrj)rZmeta_tagr$utf_8r shift_jisZutf_16_urrrtest_encoding_substitution s    z,TestSubstitutions.test_encoding_substitutioncCs2d}td}|j||d}|j|jdjddS)Nz`
        foo
        Zpre)Z parse_onlyr)r r$rrrN)rrryr$rrr;test_encoding_substitution_doesnt_happen_if_tag_is_strained$szMTestSubstitutions.test_encoding_substitution_doesnt_happen_if_tag_is_strainedN)rrr rkrlrmrnrorsrtrvrwryrzr|r~rrrrrrrrgs       rgc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS) TestEncodingz0Test the ability to encode objects into strings.cCs.d}|j|}|j|jjjddjddS)Nu zutf-8u☃)r$rr"rri)rrr$rrr"test_unicode_string_can_be_encoded2s z/TestEncoding.test_unicode_string_can_be_encodedcCs,d}|j|}|j|jjd|jddS)Nu zutf-8)r$rr"ri)rrr$rrr1test_tag_containing_unicode_string_can_be_encoded8s z>TestEncoding.test_tag_containing_unicode_string_can_be_encodedcCs&d}|j|}|j|jjdddS)Nu asciis)r$rr"ri)rrr$rrrs zITestEncoding.test_encoding_substitutes_unrecognized_characters_by_defaultcCs&d}|j|}|jt|jddddS)Nu rstrict)errors)r$rUnicodeEncodeErrorri)rrr$rrr test_encoding_can_be_made_strictCs z-TestEncoding.test_encoding_can_be_made_strictcCs$d}|j|}|jd|jjdS)Nu u☃)r$rr"Zdecode_contents)rrr$rrrtest_decode_contentsIs z!TestEncoding.test_decode_contentscCs.d}|j|}|jdjd|jjdddS)Nu u☃rg)r])r$rrir"Zencode_contents)rrr$rrrtest_encode_contentsNs  z!TestEncoding.test_encode_contentscCs*d}|j|}|jdjd|jjdS)Nu u☃rg)r$rrir"ZrenderContents)rrr$rrrtest_deprecated_renderContentsUs z+TestEncoding.test_deprecated_renderContentscCs8d}|j|}tr$|j|t|n|jdt|dS)Nu s \u2603)r$rrrepr)rrr$rrr test_repr[s  zTestEncoding.test_reprN) rrr r1rrrrrrrrrrrrr/src@s,eZdZddZddZddZddZd S) TestNavigableStringSubclassescCsX|jd}td}|jd||jt|d|j|jddd|j|jdddS)NrrBr=z)r)r)r$rrrr(r%r)rr$r+rrr test_cdataes   z(TestNavigableStringSubclasses.test_cdatacsVd_fdd}jd}td}|jd|jd|j|djdjd S) zkText inside a CData object is passed into the formatter. But the return value is ignored. rcsjd7_dS)Nr=zBITTER FAILURE)count)args)rrr incrementvszNTestNavigableStringSubclasses.test_cdata_is_never_formatted..incrementrz<><><>r=s<><>]]>)riN)rr$rrrri)rrr$r+r)rrtest_cdata_is_never_formattedos   z;TestNavigableStringSubclasses.test_cdata_is_never_formattedcCs2td}|jd}|jd||j|jddS)NrBrr=s )r r$rrri)rZdoctyper$rrrtest_doctype_ends_in_newlines  z:TestNavigableStringSubclasses.test_doctype_ends_in_newlinecCstd}|jd|jdS)NrBz)r rZ output_ready)rr rrrtest_declarationsz.TestNavigableStringSubclasses.test_declarationN)rrr rrrrrrrrrcs rc@seZdZdZddZddZeZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Z d:d;Z!dd?Z#d@dAZ$dBdCZ%dDdEZ&dFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+dPdQZ,dRdSZ-dTdUZ.dVdWZ/dXdYZ0dZd[Z1d\d]Z2d^d_Z3d`daZ4dbdcZ5dddeZ6dfdgZ7dhdiZ8djdkZ9dldmZ:dndoZ;dpdqZ The title Hello there.

        An H1

        Some text

        Some more text

        An H2

        Another

        Bob

        Another H2

        me span1a1 span1a2 test span2a1

        English

        English UK

        English US

        French

        cCst|jd|_dS)Nz html.parser)rHTMLr$)rrrrrRszTestSoupSelector.setUpcKsRdd|jj|f|D}|j|j|j||d|dj|dj|fdS)NcSsg|] }|dqS)rr)relrrrrsz2TestSoupSelector.assertSelects..z$Selector %s, expected [%s], got [%s]z, )r$selectsortrjoin)rselector expected_idskwargsZel_idsrrrrs zTestSoupSelector.assertSelectscGs"x|D]\}}|j||qWdS)N) assertSelect)rZtestsrrrrrassertSelectMultiplesz%TestSoupSelector.assertSelectMultiplecCsF|jjd}|jt|d|j|djd|j|djdgdS)Nrhr=rz The title)r$rrr,rNr)relsrrrtest_one_tag_ones z!TestSoupSelector.test_one_tag_onecCsX|jjd}|jt|dx|D]}|j|jdq"W|jjd}|jd|ddS)Nramainr)r$rrr,rN select_one)rrrarrrrtest_one_tag_manys    z"TestSoupSelector.test_one_tag_manycCs|jjd}|jd|dS)NZnonexistenttag)r$rr)rmatchrrr(test_select_one_returns_none_if_no_matchs z9TestSoupSelector.test_select_one_returns_none_if_no_matchcCs |jjd}|jdddgdS)Nzdiv divinnerdata1)r$rr)rrrrrtest_tag_in_tag_ones z$TestSoupSelector.test_tag_in_tag_onecCs&x dD]}|j|ddddgqWdS) Nhtml div html body divbody divrrrfooter)rrr)r)rrrrrtest_tag_in_tag_manys z%TestSoupSelector.test_tag_in_tag_manycCsB|jddgdd|jdddgdd|jdd ddd gd ddS) Nzhtml divrr=)r:z html body divrr+zbody divrrr>)r)rrrr test_limitszTestSoupSelector.test_limitcCs|jt|jjdddS)Ndelr)rr,r$r)rrrrtest_tag_no_matchsz"TestSoupSelector.test_tag_no_matchcCs|jt|jjddS)Nztag%t)rrr$r)rrrrtest_invalid_tagsz!TestSoupSelector.test_invalid_tagcCs|jdddgdS)Nzcustom-dashed-tagdash1dash2)r)rrrrtest_select_dashed_tag_idssz+TestSoupSelector.test_select_dashed_tag_idscCs6|jjd}|j|djd|j|ddddS)Nzcustom-dashed-tag[id="dash2"]rzcustom-dashed-tagrr)r$rrrN)rZdashedrrrtest_select_dashed_by_ids z)TestSoupSelector.test_select_dashed_by_idcCs|j|jjddjddS)Nzbody > custom-dashed-tagrz Hello there.)rr$rr))rrrrtest_dashed_tag_textsz%TestSoupSelector.test_dashed_tag_textcCs |j|jjd|jjddS)Nzcustom-dashed-tag)rr$rr-)rrrr#test_select_dashed_matches_find_allsz4TestSoupSelector.test_select_dashed_matches_find_allcCs|jddgfdddgfdS)NZh1header1Zh2header2header3)r)rrrrtest_header_tags sz!TestSoupSelector.test_header_tagscCsVxPd D]H}|jj|}|jt|d|j|djd|j|dddgqWdS) N.onepp.onep html p.onepr=rrrmonep)rrr)r$rrr,rN)rrrrrrtest_class_ones   zTestSoupSelector.test_class_onecCs |jjd}|jt|ddS)Nzdiv.onepr)r$rrr,)rrrrrtest_class_mismatched_tags z*TestSoupSelector.test_class_mismatched_tagcCs xdD]}|j|dgqWdS)N div#inner#inner div div#innerr)rrr)r)rrrrr test_one_ids zTestSoupSelector.test_one_idcCs |jjd}|jt|ddS)Nz #doesnotexistr)r$rrr,)rrrrr test_bad_ids zTestSoupSelector.test_bad_idcCsf|jjd}|jt|dx|D]}|j|jdq"W|j|dddg|j|djddS)Nz div#inner pr9rr=rmrr)r$rrr,rNr8r7)rrrrrrtest_items_in_id#s   z!TestSoupSelector.test_items_in_idcCs*x$dD]}|jt|jj|dqWdS)N div#main deldiv#main div.oops div div#mainr)rrr)rr,r$r)rrrrrtest_a_bunch_of_emptys+s z'TestSoupSelector.test_a_bunch_of_emptyscCs xd D]}|j|d gqWdS) N.class1p.class1.class2p.class2.class3p.class3 html p.class2div#inner .class2pmulti)rrrrrrrr)r)rrrrrtest_multi_class_support/sz)TestSoupSelector.test_multi_class_supportcCs xdD]}|j|dgqWdS)N.class1.class3.class3.class2.class1.class2.class3r)rrr)r)rrrrrtest_multi_class_selection4sz+TestSoupSelector.test_multi_class_selectioncCs"|jdddg|jddgdS)Nz.s1 > as1a1s1a2z .s1 > a spans1a2s1)r)rrrrtest_child_selector9sz$TestSoupSelector.test_child_selectorcCs|jddgdS)Nz.s1 > a#s1a2 spanr)r)rrrrtest_child_selector_id=sz'TestSoupSelector.test_child_selector_idcCst|jddgfddgfddgfddgfddgfddgfd dgfd gfd dgfd dgfd dgfdgfdgfdgfdS)Nzp[class="onep"]rz p[id="p1"]z[class="onep"]z [id="p1"]zlink[rel="stylesheet"]l1zlink[type="text/css"]zlink[href="blah.css"]zlink[href="no-blah.css"]z[rel="stylesheet"]z[type="text/css"]z[href="blah.css"]z[href="no-blah.css"]zp[href="no-blah.css"])r)rrrrtest_attribute_equals@sz&TestSoupSelector.test_attribute_equalsc Cs\|jddgfddgfddgfddgfddgfddgfdd gfd d gfd d gfd d gf dS) Nzp[class~="class1"]rzp[class~="class2"]zp[class~="class3"]z[class~="class1"]z[class~="class2"]z[class~="class3"]za[rel~="friend"]bobz a[rel~="met"]z[rel~="friend"]z [rel~="met"])r)rrrrtest_attribute_tildeRsz%TestSoupSelector.test_attribute_tildecCsv|jddgfddgfdgfdgfdgfddgfdd d gfd d d gfd d dgfdd dgfddgfdd gfddgf dS)Nz[rel^="style"]rzlink[rel^="style"]znotlink[rel^="notstyle"]z[rel^="notstyle"]zlink[rel^="notstyle"]zlink[href^="bla"]za[href^="http://"]rmez[href^="http://"]z [id^="p"]rrz [id^="m"]rz div[id^="m"]z a[id^="m"]zdiv[data-tag^="dashed"]r)r)rrrrtest_attribute_startswith`s    z*TestSoupSelector.test_attribute_startswithc CsH|jddgfddgfddgfdddddd d d d gfd dgfdgfdS)Nz[href$=".css"]rzlink[href$=".css"]z link[id$="1"]z [id$="1"]rrrrs2a1rrz div[id$="1"]z[id$="noending"])r)rrrrtest_attribute_endswithqsz(TestSoupSelector.test_attribute_endswithcCs|jddgfddgfdgfdgfdgfddgfdd d gfd d d gfddgfdd gfddgfddgfddgfdddd ddddddg fddgfdgfdd d dgfdd d gfd dgfd!dd"gfd#d"gfd$dgfdS)%Nz[rel*="style"]rzlink[rel*="style"]znotlink[rel*="notstyle"]z[rel*="notstyle"]zlink[rel*="notstyle"]zlink[href*="bla"]z[href*="http://"]rrz [id*="p"]rrz div[id*="m"]rz a[id*="m"]z[href*=".css"]zlink[href*=".css"]z link[id*="1"]z [id*="1"]rrrrrrrz div[id*="1"]z[id*="noending"]z [href*="."]z a[href*="."]zlink[href*="."]z div[id*="n"]rz div[id*="nn"]zdiv[data-tag*="edval"])r)rrrrtest_attribute_contains{s.     z(TestSoupSelector.test_attribute_containscCs2|jddddgfddddgfddgfdgfdS) Nz p[lang|="en"]zlang-enz lang-en-gbz lang-en-usz [lang|="en"]z p[lang|="fr"]zlang-frz p[lang|="gb"])r)rrrrtest_attribute_exact_or_hypens   z.TestSoupSelector.test_attribute_exact_or_hypenc CsV|jddddgfddgfdddgfddd d d gfd d dgfdgfdgfddgfdS)Nz[rel]rrrz link[rel]za[rel]z[lang]zlang-enz lang-en-gbz lang-en-uszlang-frzp[class]rrz[blah]zp[blah]z div[data-tag]r)r)rrrrtest_attribute_existss   z&TestSoupSelector.test_attribute_existscCs,d}t|d}|jd\}|jd|jdS)Nz]
        nope
        yes
        z html.parserzdiv[style="display: right"]yes)rrrr)rrr$Zchosenrrr"test_quoted_space_in_selector_names  z3TestSoupSelector.test_quoted_space_in_selector_namecCs(|jt|jjd|jt|jjddS)Nza:no-such-pseudoclassza:nth-of-type(a))rrr$r)rrrrtest_unsupported_pseudoclasssz-TestSoupSelector.test_unsupported_pseudoclasscCs|jjd}|jt|d|j|djd|jjd}|jt|d|j|djd|jjd}|jt|d|jt|jjddS) Nzdiv#inner p:nth-of-type(1)r=rz Some textzdiv#inner p:nth-of-type(3)ZAnotherzdiv#inner p:nth-of-type(4)zdiv p:nth-of-type(0))r$rrr,rrr)rrrrrtest_nth_of_types   z!TestSoupSelector.test_nth_of_typecCs2|jjd}|jt|d|j|djddS)Nzdiv#inner > p:nth-of-type(1)r=rz Some text)r$rrr,r)rrrrr"test_nth_of_type_direct_descendants z3TestSoupSelector.test_nth_of_type_direct_descendantcCs|jddgdS)Nz#inner > p:nth-of-type(2)r)r)rrrr"test_id_child_selector_nth_of_typesz3TestSoupSelector.test_id_child_selector_nth_of_typecCs.|jjddd}|jd}|j|ddgdS)Nrar)rrr)r$r%rr)rrselectedrrrtest_select_on_elements z'TestSoupSelector.test_select_on_elementcCs|jddg|jdgdS)Nz .fancy #innerrz.normal #inner)r)rrrrtest_overspecified_child_idsz,TestSoupSelector.test_overspecified_child_idcCsB|jddg|jddg|jddg|jg|jjddS)Nz#p1 + h2rz #p1 + h2 + prz#p1 + #header2 + .class1z#p1 + p)rrr$r)rrrrtest_adjacent_sibling_selectorsz/TestSoupSelector.test_adjacent_sibling_selectorcCsR|jdddg|jddg|jddg|jddg|jg|jjddS) Nz#p1 ~ h2rrz#p1 ~ #header2z #p1 ~ h2 + arz#p1 ~ h2 + [rel="me"]z #inner ~ h2)rrr$r)rrrrtest_general_sibling_selectors z.TestSoupSelector.test_general_sibling_selectorcCs|jt|jjddS)Nzh1 >)rrr$r)rrrrtest_dangling_combinatorsz)TestSoupSelector.test_dangling_combinatorcCs|jddddgdS)Nz p[lang] ~ pz lang-en-gbz lang-en-uszlang-fr)r)rrrr2test_sibling_combinator_wont_select_same_tag_twiceszCTestSoupSelector.test_sibling_combinator_wont_select_same_tag_twicecCs|jdddgdS)Nzx, yxidyid)r)rrrrtest_multiple_selectsz%TestSoupSelector.test_multiple_selectcCs|jdddgdS)Nzx,yrr)r)rrrr"test_multiple_select_with_no_spacesz3TestSoupSelector.test_multiple_select_with_no_spacecCs|jdddgdS)Nzx, yrr)r)rrrr$test_multiple_select_with_more_spacesz5TestSoupSelector.test_multiple_select_with_more_spacecCs|jddgdS)Nzx, xr)r)rrrrtest_multiple_select_duplicatedsz0TestSoupSelector.test_multiple_select_duplicatedcCs|jdddgdS)Nzx, y ~ p[lang=fr]rzlang-fr)r)rrrrtest_multiple_select_siblingsz-TestSoupSelector.test_multiple_select_siblingcCs|jdddgdS)Nzx, y > zrzidb)r)rrrr.test_multiple_select_tag_and_direct_descendantsz?TestSoupSelector.test_multiple_select_tag_and_direct_descendantcCs|jdddddddgdS)Nz div > x, y, zrrzidarzidabzidac)r)rrrr/test_multiple_select_direct_descendant_and_tags sz@TestSoupSelector.test_multiple_select_direct_descendant_and_tagscCs|jdddddddgdS)Nz div x,y, zrrr rr r )r)rrrr(test_multiple_select_indirect_descendant sz9TestSoupSelector.test_multiple_select_indirect_descendantcCs(|jt|jjd|jt|jjddS)Nz,x, yzx,,y)rrr$r)rrrrtest_invalid_multiple_selectsz-TestSoupSelector.test_invalid_multiple_selectcCs|jdddgdS)Nzp[lang=en], p[lang=en-gb]zlang-enz lang-en-gb)r)rrrrtest_multiple_select_attrssz+TestSoupSelector.test_multiple_select_attrscCs|jddddgdS)Nz*x, y > z[id=zida], z[id=zidab], z[id=zidb]rrr )r)rrrrtest_multiple_select_idssz)TestSoupSelector.test_multiple_select_idscCs|jdddgdS)Nzbody > div > x, y > zrr)r)rrrrtest_multiple_select_nestedsz,TestSoupSelector.test_multiple_select_nestedcCsRd}t|d}|jd}|jdt|x$|jddgdD]}||ks:tq:WdS)Nz3
        z html.parserz.c1, .c2r9Zc1Zc2)ro)rrrr,r-r)rrr$rrrrrtest_select_duplicate_elementss   z/TestSoupSelector.test_select_duplicate_elementsN)>rrr rrRrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrrrrsv1     r)2r1ZpdbrrYrSr6r1Zbs4rZ bs4.builderrrZ bs4.elementrrrr r r r r Z bs4.testingrrrrZ LXML_PRESENTrr!r2rLrPrdrrrrrrrrrrr-rGrRrgrrrrrrr sN  ( ;O83(3--*6n+a4*