Ϫf,dZddlmZddlmZmZddlmZddlm Z ddl m Z m Z GddZ Gd d e e ZGd d e e Zy )zH Specific tests for (some of) the methods in L{twisted.web.domhelpers}. )reload)AnyOptional)minidom)TestCase) domhelpersmicrodomcteZdZUdZdZeeed<dZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZy)DOMHelpersTestsMixinz A mixin for L{TestCase} subclasses which defines test methods for domhelpers functionality based on a DOM creation function provided by a subclass. Ndomc|jjd}tj|ddj}d}|j |||j }tj|ddj}|j ||d}|jj|}tj|d}dj|Dcgc]}|jdc}}d}|j |||j } tj| d}dj|Dcgc]}|jdc}}|j ||d} |jj| } tj| d}dj|Dcgc]}|jdc}}d }|j ||| j } tj| d}dj|Dcgc]}|jdc}}|j ||d } |jj| }tj|d}|j }||jd jdg}|j ||tj|d}|j ||ycc}wcc}wcc}wcc}w) NzfoorzinabcdefghaH abdgheicfjz') r parseStringrgetElementsByTagNamenodeName assertEqualdocumentElementjoin getAttribute childNodes)selfdoc1actualexpectedel1doc2_xmldoc2tag_listnodeel2doc3_xmldoc3el3doc4_xmldoc4roots B/usr/lib/python3/dist-packages/twisted/web/test/test_domhelpers.pytest_getElementsByTagNamez.DOMHelpersTestsMixin.test_getElementsByTagNamesxx##H-00u=a@II *""00ehGd$++D1GH *"xx##H-224?hGd$++D1GH *""223>hGd$++D1GH *<xx##H-00u=##$//"-88;< *00u= *UH H,H HsK:K-K$K)c|jjd}tj|}d}|j ||tj|j }|j ||d}|jj|}tj|}d}|j ||tj|j }|j ||d}|jj|}tj|}d}|j ||tj|j }|j ||y)Nz foorz+abcdefghrzPabdgheicfjrr rrgatherTextNodesrr)rrrrr!r"r&r's r,test_gatherTextNodesz)DOMHelpersTestsMixin.test_gatherTextNodesQs0xx##L1++D1 *++D,@,@A *@xx##H-++D1 *++D,@,@A * - xx##H-++D1 *++D,@,@A *c|jjd}|j}tj||j |j |jjdj |jjd}|jjd}tj||jj }|jjd}|j|jjd|j ||j y)Nzarb) r rrr clearNodertoxmlElementr appendChild)rra_noder"b_noderrs r,test_clearNodez#DOMHelpersTestsMixin.test_clearNodelsxx##$?@%%V$ )9)9#)>)D)D)FGxx##$?@%%003V$%%++-88##C(TXX--c23 !12r2cr|jjd}|jj}tj|d}|j }|j d}|jdd|j||j tj|d}|j }|j d}|jdd|j||j |jtjtj|dy) N$rcclassbarr5idpzork) r rDocumentrgetr7 createElement setAttributer assertRaisesNodeLookupErrorrrdocr$rrs r,test_getzDOMHelpersTestsMixin.test_getzsxx##$JKhh!~~dE*$$S)gu- !12~~dE*$$S)dE* !12 *44jnndGTr2c|jjd}|jj}tj|d}|j }|j d}|jdd|j||j tj|d}|j|dy)Nr>rr?r@rC) r rrDr getIfExistsr7rFrGrassertIdenticalrJs r,test_getIfExistsz%DOMHelpersTestsMixin.test_getIfExistssxx##$JKhh!%%dE2$$S)gu- !12%%dG4 T4(r2c@|jjd}|jj}tj|d}|j }|j d}|jdd|j||j y)Nzrr5rB) r rrDr getAndClearr7rFrGrrJs r,test_getAndClearz%DOMHelpersTestsMixin.test_getAndClears}xx##$DEhh!%%dE2$$S)dE* !12r2c|jjd}|jj}tj|j ddd}dj |Dcgc]}|jc}}|jd}|jdd|jd}|jdd|j||j||jtj|j ddd }dj |Dcgc]}|jc}}|j||j|jzycc}wcc}w) Nz:rolive) noNestingrr5r?r) r rrDr locateNodesrrr7rFrGr9r)rrrK node_listr$rrr?s r,test_locateNodesz%DOMHelpersTestsMixin.test_locateNodess0xx## H hh!**4??E7VWX 9=4$**,=>$$S)eW-   c " ug&Q !12**4??E7VWX 9=4$**,=> !1AGGI!=>>>s (E?/Fc L|jjd}tj|jdjdjd}dj |Dcgc]}t |ds|jc}}|j|dycc}w)Nz!rrtagNamecba) r rr getParentsrrhasattrr\rrrrYr$rs r,test_getParentsz$DOMHelpersTestsMixin.test_getParentssxx##$GH)) OOA  ) )! , 7 7 : &/ Ld743KT\\ L  ' Ms 'B!9B!c|jjd}tj|d}dj |Dcgc]}|j c}}|j |dtj|dd}dj |Dcgc]}|j c}}|j |dycc}wcc}w)Nz+rrabc1ac)r rrfindElementsWithAttributerr\rr`s r,test_findElementsWithAttributez3DOMHelpersTestsMixin.test_findElementsWithAttributesxx##$QR88uE 9=4$,,=> '88ucJ 9=4$,,=> & >>s CCc|jjd}tj|d}t |}|j |dy)Nz#ar)r rrfindNodesNamedlenr)rrrYrs r,test_findNodesNamedz(DOMHelpersTestsMixin.test_findNodesNamedsBxx##$IJ--dE: Y #r2cVd}d}|jtj||y)Nz9this string " contains many & characters> xml< won't likezHthis string " contains many & characters> xml< won't like)rrescaperjrs r, test_escapez DOMHelpersTestsMixin.test_escapes, H V  **1-x8r2cVd}d}|jtj||y)NzTthis string " has && entities > < and some characters xml won't like < and some characters xml won't like<)rrunescaperos r, test_unescapez"DOMHelpersTestsMixin.test_unescapes, b T  ,,Q/:r2c|jjd}|jtj|dy)z| L{getNodeText} returns the concatenation of all the text data at or beneath the node passed to it. z(bazquuxbazquuxN)r rrr getNodeText)rr$s r,test_getNodeTextz%DOMHelpersTestsMixin.test_getNodeTexts4 xx##$NO //5yAr2)__name__ __module__ __qualname____doc__r rr__annotations__r-r1r<rLrPrSrZrargrlrqrtrxr2r,r r s[ C#6+p+6 3U" )3?&('$ 9;Br2r c"eZdZeZdZdZdZy)MicroDOMHelpersTestscd}|jj|}tj|}d}|j ||tj|j }|j ||y)z Microdom discards whitespace-only text nodes, so L{gatherTextNodes} returns only the text from nodes which had non-whitespace characters. z? stuff z stuff Nr/)rr)r*rrs r,#test_gatherTextNodesDropsWhitespacez8MicroDOMHelpersTests.test_gatherTextNodesDropsWhitespacesj xx##H-++D1$ *++D,@,@A *r2cd}|jj|}tj|}d}|j ||tj|j }|j ||y)zB Microdom does not decode entities in text nodes. Souffl&z Souffl&Nr/rdoc5_xmldoc5rrs r,test_textEntitiesNotDecodedz0MicroDOMHelpersTests.test_textEntitiesNotDecodedsh(xx##H-++D1  *++D,@,@A *r2ctt|j|jg}|j dt ||j d|ddy)z? An import will raise the deprecation warning. rVz8twisted.web.domhelpers was deprecated at Twisted 23.10.0rmessageN)rr flushWarningstest_deprecationrrk)rwarningss r,rz%MicroDOMHelpersTests.test_deprecationsV z%%t'<'<&=> CM*  F QK " r2N)ryrzr{r r rrrr~r2r,rrs C+( +  r2rceZdZeZdZdZy)MiniDOMHelpersTestscd}|jj|}tj|}d}|j ||tj|j }|j ||y)z= Minidom does decode entities in text nodes. rzSouffl&Nr/rs r,test_textEntitiesDecodedz,MiniDOMHelpersTests.test_textEntitiesDecodedsh(xx##H-++D1 *++D,@,@A *r2c|jjd}tj|}|j |d|j |t |jjdj}tj|}|j |d|j |t y)z L{domhelpers.getNodeText} returns a C{unicode} string when text nodes are represented in the DOM with unicode, whether or not there are non-ASCII characters present. zbarrAuu☃N)r rrrwrassertIsInstancestrencode)rr$texts r,test_getNodeUnicodeTextz+MiniDOMHelpersTests.test_getNodeUnicodeText#s xx##$45%%d+ u% dC(xx##$<$C$C$EF%%d+ }- dC(r2N)ryrzr{rr rrr~r2r,rrs C +)r2rN)r| importlibrtypingrrxml.domrtwisted.trial.unittestr twisted.webrr r rrr~r2r,rsI  +,QBQBh- /- `).)r2