Ϫf=*jddlmZddlmZddlmZddlmZddlm Z GddejZ y) )unittest)xpath)Element) XPathQuery) SyntaxErrorceZdZddZddZddZddZddZddZddZ dd Z dd Z dd Z dd Z dd ZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZy) XPathTestsNctd|_d|jd<d|jd<|jjd|jjd|_|jjd|_|j jd |_|j jd |jjd |jjd|_d |jd <|jjd|_|jjd|_ |jjd |_ |jjd|jjd|_ |jjd|_ d|jd<d|jd<|jjd|_ |jjd |_|jjd|jjd|_d|jd<d|jd<|jjd|_|jjd |_|j"jd|jjd|_d|j$d<d|j$d<d|j$d<|j$jd|_|j&jdy)N)testnsfoovalue1attrib1zuser@host/resourceattrib3 somecontentbarr garDEFsomemorecontentvalue2attrib2ABCvalue4attrib4value5attrib5JKLMNOvalue6áattrib6quuxu☃)re addContent addElementbar1subfoogar1bar2bar3subfoo2gar2bar4bar5subfoo3gar3bar6subfoo4gar4bar7r!selfs ?/usr/lib/python3/dist-packages/twisted/words/test/test_xpath.pysetUpzXPathTests.setUp s|8*+$y0y -(FF%%e, ii**51 KK**51  U# +,FF%%e, ' )II((/ yy++E2 II((/  U#FF%%e, FF%%e, ' )' )yy++E2 II((/  U#FF%%e, ' )' )yy++E2 II((/  U#FF%%e, ' )' )# )II((0  ]+c  |jtjd|jd|jtjd|j|j |j |j|j|j|jg|jtjd|jd|jtjd|jddgy)z= Test basic operation of the static methods. /foo/barT/foorrN) assertEqualrmatchesr" queryForNodesr%r(r,r-r0r3queryForStringqueryForStringListr4s r6test_staticMethodszXPathTests.test_staticMethodsLs z466:DA     DFF 3 YY 499diiDII N  --fdff=}M   $ $VTVV 4}FW6X r8cptd}|j|j|jdy)z3 Test matching foo with child bar. r:Nrr<r=r"r5xps r6test_locationFooBarzXPathTests.test_locationFooBarZs+ # DFF+Q/r8ctd}|j|j|jd|j|j |j|j |j |jgy)z8 Test finding foos at the second level. z /foo/bar/foorCN)rr<r=r"r>r&r.r1rEs r6test_locationFooBarFooz!XPathTests.test_locationFooBarFooas` ' DFF+Q/    TVV $t{{DLL$,,&O r8cptd}|j|j|jdy)z( Test not finding bar3. z /foo/bar3rNrDrEs r6test_locationNoBar3zXPathTests.test_locationNoBar3ks+ $ DFF+Q/r8c Jtd}|j|j|jd|j|j |j|j |j |j|j|j|jgy)z- Test finding childs of foo. z/foo/*TN) rr<r=r"r>r%r(r,r-r0r3rEs r6test_locationAllChildsz!XPathTests.test_locationAllChildsrss ! DFF+T2    TVV $ YY 499diiDII N r8cptd}|j|j|jdy)z3 Test matching foo with attribute. z/foo[@attrib1]TNrDrEs r6test_attributezXPathTests.test_attribute}s,( ) DFF+T2r8ctd}|j|j|jd|j|j |j|j gy)z> Test find nodes with attribute having value. z/foo/*[@attrib2='value2']TN)rr<r=r"r>r(rEs r6test_attributeWithValueAnyz%XPathTests.test_attributeWithValueAnyQ3 4 DFF+T2 ))$&&1DII;?r8ctd}|j|j|jd|j|j |j|j gy)zI Nodes' attributes can be matched with non-ASCII values. u/foo/*[@attrib6='á']TN)rr<r=r"r>r3rEs r6test_locationWithValueUnicodez(XPathTests.test_locationWithValueUnicodesQ/ 0 DFF+T2 ))$&&1DII;?r8cptd}|j|j|jdy)z4 Test matching node with namespace. z/foo[@xmlns='testns']/barrCNrDrEs r6test_namespaceFoundzXPathTests.test_namespaceFound,3 4 DFF+Q/r8cptd}|j|j|jdy)z> Test not matching node with wrong namespace. z/foo[@xmlns='badns']/bar2rNrDrEs r6test_namespaceNotFoundz!XPathTests.test_namespaceNotFoundrWr8cptd}|j|j|jdy)zA Test matching node with attribute having value. z/foo[@attrib1='value1']rCNrDrEs r6test_attributeWithValuez"XPathTests.test_attributeWithValues,1 2 DFF+Q/r8cptd}|j|j|jdy)zM queryforString on absolute paths returns their first CDATA. r;rN)rr<r?r"rEs r6test_queryForStringzXPathTests.test_queryForStrings-  **4662MBr8cttd}|j|j|jddgy)zO queryforStringList on absolute paths returns all their CDATA. r;rrNrr<r@r"rEs r6test_queryForStringListz"XPathTests.test_queryForStringLists6    ! !$&& )M;L+M r8cttd}|j|j|jddgy)zO queryforStringList on relative paths returns all their CDATA. z//foorrNr_rEs r6"test_queryForStringListAnyLocationz-XPathTests.test_queryForStringListAnyLocations6    ! !$&& )M;L+M r8c td}|j|j|j|j|j |j |j|j|jgy)z% Test finding nodes. r:N) rr<r>r"r%r(r,r-r0r3rEs r6test_queryForNodeszXPathTests.test_queryForNodessV #    TVV $ YY 499diiDII N r8cptd}|j|j|jdy)z7 Test matching a node with given text. z/foo[text() = 'somecontent']TNrDrEs r6test_textConditionzXPathTests.test_textConditions,6 7 DFF+T2r8ctd}|j|j|jd|j|j |j|j gy)zK A node can be matched by text with non-ascii code points. u//*[text()='☃']TN)rr<r=r"r>r!rEs r6test_textConditionUnicodez$XPathTests.test_textConditionUnicoderRr8cptd}|j|j|jdy)z( Test for not operator. z/foo[not(@nosuchattrib)]TNrDrEs r6test_textNotOperatorzXPathTests.test_textNotOperators,2 3 DFF+T2r8cxtd}|j|j|jd|j|j |j|j |j |j|jg|j|j|jgdy)zS Test finding any nodes named gar and getting their text contents. z//garT)rrrrN) rr<r=r"r>r'r+r/r2r@rEs r6test_anyLocationAndTextz"XPathTests.test_anyLocationAndTexts  DFF+T2    TVV $tyy$))TYY &R  ..tvv68TUr8c `td}|j|j|jd|j|j |j|j |j |j|j|j|j|jgy)z3 Test finding any nodes named bar. //barTN) rr<r=r"r>r%r(r)r,r-r0r3rEs r6test_anyLocationzXPathTests.test_anyLocations  DFF+T2    TVV $         r8c\td}|jt|jdy)zn L{XPathQuery.queryForString} should raise a L{NotImplementedError} for any location. rnN)r assertRaisesNotImplementedErrorr?rEs r6test_anyLocationQueryForStringz)XPathTests.test_anyLocationQueryForStrings'   -r/@/@$Gr8ctd}|j|j|jd|j|j |j|j gy)z9 Test boolean and operator in condition. z.//bar[@attrib4='value4' and @attrib5='value5']TN)rr<r=r"r>r-rEs r6test_andOperatorzXPathTests.test_andOperatorsQH I DFF+T2 ))$&&1DII;?r8ctd}|j|j|jd|j|j |j|j |j gy)z8 Test boolean or operator in condition. z-//bar[@attrib5='value4' or @attrib5='value5']TN)rr<r=r"r>r-r0rEs r6test_orOperatorzXPathTests.test_orOperatorsXG H DFF+T2 ))$&&1DIItyy3IJr8ctd}|j|j|jd|j|j |j|j |j gy)zK Test multiple boolean operators in condition with parens. zf//bar[@attrib4='value4' and (@attrib5='value4' or @attrib5='value6')]TN)rr<r=r"r>r0r3rEs r6test_booleanOperatorsParensz&XPathTests.test_booleanOperatorsParenss_ N  DFF+T2 ))$&&1DIItyy3IJr8ctd}|j|j|jd|j|j |j|j |j |jgy)zN Test multiple boolean operators in condition without parens. z//bar[@attrib5='value4' or @attrib5='value5' or @attrib5='value6']TN)rr<r=r"r>r-r0r3rEs r6test_booleanOperatorsNoParensz(XPathTests.test_booleanOperatorsNoParens#sd 7  DFF+T2 ))$&&1DIItyy$))3TUr8c|jttd}|j|jj dd|jzy)z} A missing closing bracket raises a SyntaxError. This test excercises the most common failure mode. z//bar[@attrib1zTrying to find one ofzCSyntaxError message '%s' doesn't start with 'Trying to find one of'N)rqrr assertTruemsg startswith)r5excs r6test_badXPathNoClosingBracketz(XPathTests.test_badXPathNoClosingBracket/sG  Z9MN  GG  6 7 Ugg  r8)returnN)__name__ __module__ __qualname__r7rArGrIrKrMrOrQrTrVrYr[r]r`rbrdrfrhrjrlrorsrurwryr{rr8r6r r s=,~  0 0  3@@000C   3@3 V &H@K K V  r8r N) twisted.trialrtwisted.words.xishrtwisted.words.xish.domishrtwisted.words.xish.xpathrtwisted.words.xish.xpathparserrTestCaser rr8r6rs* #$-/6n ""n r8