
    Vh=*                     j    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d dej                        Zy)	    )unittest)xpath)Element)
XPathQuery)SyntaxErrorc                       e Zd ZddZddZddZddZddZddZddZ	dd	Z
dd
ZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZy)
XPathTestsNc                    t        d      | _        d| j                  d<   d| j                  d<   | j                  j                  d       | j                  j                  d      | _        | j                  j                  d      | _        | j
                  j                  d	      | _        | j                  j                  d
       | j                  j                  d       | j                  j                  d      | _        d| j                  d<   | j                  j                  d      | _        | j                  j                  d      | _	        | j                  j                  d	      | _
        | j                  j                  d       | j                  j                  d      | _        | j                  j                  d      | _        d| j                  d<   d| j                  d<   | j                  j                  d      | _        | j                  j                  d	      | _        | j                  j                  d       | j                  j                  d      | _        d| j                  d<   d| j                  d<   | j                  j                  d      | _        | j                  j                  d	      | _        | j"                  j                  d       | j                  j                  d      | _        d| j$                  d<   d| j$                  d<   d| j$                  d<   | j$                  j                  d      | _        | j&                  j                  d       y )N)testnsfoovalue1attrib1zuser@host/resourceattrib3somecontentbarr   garDEFsomemorecontentvalue2attrib2ABCvalue4attrib4value5attrib5JKLMNOvalue6   áattrib6quuxu   ☃)r   e
addContent
addElementbar1subfoogar1bar2bar3subfoo2gar2bar4bar5subfoo3gar3bar6subfoo4gar4bar7r!   selfs    M/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_xpath.pysetUpzXPathTests.setUp   s|   8 *+$y0y-(FF%%e,	ii**51KK**51			U#+,FF%%e,	'		)II((/	yy++E2II((/			U#FF%%e,	FF%%e,	'		)'		)yy++E2II((/			U#FF%%e,	'		)'		)yy++E2II((/			U#FF%%e,	'		)'		)#		)II((0			]+    c           	         | j                  t        j                  d| j                        d       | j                  t        j                  d| j                        | j
                  | j                  | j                  | j                  | j                  | j                  g       | j                  t        j                  d| j                        d       | j                  t        j                  d| j                        ddg       y)z=
        Test basic operation of the static methods.
        /foo/barT/foor   r   N)assertEqualr   matchesr"   queryForNodesr%   r(   r,   r-   r0   r3   queryForStringqueryForStringListr4   s    r6   test_staticMethodszXPathTests.test_staticMethodsL   s     	z466:DA
DFF3YY		499diiDIIN	
 	--fdff=}M$$VTVV4}FW6X	
r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z3
        Test matching foo with child bar.
        r:      Nr   r<   r=   r"   r5   xps     r6   test_locationFooBarzXPathTests.test_locationFooBarZ   s+     
#DFF+Q/r8   c                    t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  | j                  g       y)z8
        Test finding foos at the second level.
        z/foo/bar/foorC   N)r   r<   r=   r"   r>   r&   r.   r1   rE   s     r6   test_locationFooBarFooz!XPathTests.test_locationFooBarFooa   s`     'DFF+Q/TVV$t{{DLL$,,&O	
r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z(
        Test not finding bar3.
        z	/foo/bar3r   NrD   rE   s     r6   test_locationNoBar3zXPathTests.test_locationNoBar3k   s+     $DFF+Q/r8   c           	      J   t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  | j                  | j                  | j                  | j                  g       y)z-
        Test finding childs of foo.
        z/foo/*TN)r   r<   r=   r"   r>   r%   r(   r,   r-   r0   r3   rE   s     r6   test_locationAllChildsz!XPathTests.test_locationAllChildsr   ss     !DFF+T2TVV$YY		499diiDIIN	
r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z3
        Test matching foo with attribute.
        z/foo[@attrib1]TNrD   rE   s     r6   test_attributezXPathTests.test_attribute}   s,     ()DFF+T2r8   c                     t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  g       y)z>
        Test find nodes with attribute having value.
        z/foo/*[@attrib2='value2']TN)r   r<   r=   r"   r>   r(   rE   s     r6   test_attributeWithValueAnyz%XPathTests.test_attributeWithValueAny   Q     34DFF+T2))$&&1DII;?r8   c                     t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  g       y)zI
        Nodes' attributes can be matched with non-ASCII values.
        u   /foo/*[@attrib6='á']TN)r   r<   r=   r"   r>   r3   rE   s     r6   test_locationWithValueUnicodez(XPathTests.test_locationWithValueUnicode   sQ     /0DFF+T2))$&&1DII;?r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z4
        Test matching node with namespace.
        z/foo[@xmlns='testns']/barrC   NrD   rE   s     r6   test_namespaceFoundzXPathTests.test_namespaceFound   ,     34DFF+Q/r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z>
        Test not matching node with wrong namespace.
        z/foo[@xmlns='badns']/bar2r   NrD   rE   s     r6   test_namespaceNotFoundz!XPathTests.test_namespaceNotFound   rW   r8   c                 p    t        d      }| j                  |j                  | j                        d       y)zA
        Test matching node with attribute having value.
        z/foo[@attrib1='value1']rC   NrD   rE   s     r6   test_attributeWithValuez"XPathTests.test_attributeWithValue   s,     12DFF+Q/r8   c                 p    t        d      }| j                  |j                  | j                        d       y)zM
        queryforString on absolute paths returns their first CDATA.
        r;   r   N)r   r<   r?   r"   rE   s     r6   test_queryForStringzXPathTests.test_queryForString   s-     **4662MBr8   c                 t    t        d      }| j                  |j                  | j                        ddg       y)zO
        queryforStringList on absolute paths returns all their CDATA.
        r;   r   r   Nr   r<   r@   r"   rE   s     r6   test_queryForStringListz"XPathTests.test_queryForStringList   s6     !!$&&)M;L+M	
r8   c                 t    t        d      }| j                  |j                  | j                        ddg       y)zO
        queryforStringList on relative paths returns all their CDATA.
        z//foor   r   Nr_   rE   s     r6   "test_queryForStringListAnyLocationz-XPathTests.test_queryForStringListAnyLocation   s6      !!$&&)M;L+M	
r8   c           	          t        d      }| j                  |j                  | j                        | j                  | j
                  | j                  | j                  | j                  | j                  g       y)z%
        Test finding nodes.
        r:   N)
r   r<   r>   r"   r%   r(   r,   r-   r0   r3   rE   s     r6   test_queryForNodeszXPathTests.test_queryForNodes   sV     
#TVV$YY		499diiDIIN	
r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z7
        Test matching a node with given text.
        z/foo[text() = 'somecontent']TNrD   rE   s     r6   test_textConditionzXPathTests.test_textCondition   s,     67DFF+T2r8   c                     t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  g       y)zK
        A node can be matched by text with non-ascii code points.
        u   //*[text()='☃']TN)r   r<   r=   r"   r>   r!   rE   s     r6   test_textConditionUnicodez$XPathTests.test_textConditionUnicode   rR   r8   c                 p    t        d      }| j                  |j                  | j                        d       y)z(
        Test for not operator.
        z/foo[not(@nosuchattrib)]TNrD   rE   s     r6   test_textNotOperatorzXPathTests.test_textNotOperator   s,     23DFF+T2r8   c                 x   t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  | j                  | j                  g       | j                  |j                  | j                        g d       y)zS
        Test finding any nodes named gar and getting their text contents.
        z//garT)r   r   r   r   N)
r   r<   r=   r"   r>   r'   r+   r/   r2   r@   rE   s     r6   test_anyLocationAndTextz"XPathTests.test_anyLocationAndText   s      DFF+T2TVV$tyy$))TYY		&R	
 	..tvv68TUr8   c           
      `   t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  | j                  | j                  | j                  | j                  | j                  g       y)z3
        Test finding any nodes named bar.
        //barTN)r   r<   r=   r"   r>   r%   r(   r)   r,   r-   r0   r3   rE   s     r6   test_anyLocationzXPathTests.test_anyLocation   s      DFF+T2TVV$															
r8   c                 \    t        d      }| j                  t        |j                  d       y)zn
        L{XPathQuery.queryForString} should raise a L{NotImplementedError}
        for any location.
        rn   N)r   assertRaisesNotImplementedErrorr?   rE   s     r6   test_anyLocationQueryForStringz)XPathTests.test_anyLocationQueryForString   s'    
  -r/@/@$Gr8   c                     t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  g       y)z9
        Test boolean and operator in condition.
        z.//bar[@attrib4='value4' and @attrib5='value5']TN)r   r<   r=   r"   r>   r-   rE   s     r6   test_andOperatorzXPathTests.test_andOperator  sQ     HIDFF+T2))$&&1DII;?r8   c                     t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  g       y)z8
        Test boolean or operator in condition.
        z-//bar[@attrib5='value4' or @attrib5='value5']TN)r   r<   r=   r"   r>   r-   r0   rE   s     r6   test_orOperatorzXPathTests.test_orOperator  sX     GHDFF+T2))$&&1DIItyy3IJr8   c                     t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  g       y)zK
        Test multiple boolean operators in condition with parens.
        zf//bar[@attrib4='value4' and
                                 (@attrib5='value4' or @attrib5='value6')]TN)r   r<   r=   r"   r>   r0   r3   rE   s     r6   test_booleanOperatorsParensz&XPathTests.test_booleanOperatorsParens  s_     N
 	DFF+T2))$&&1DIItyy3IJr8   c                    t        d      }| j                  |j                  | j                        d       | j                  |j	                  | j                        | j
                  | j                  | j                  g       y)zN
        Test multiple boolean operators in condition without parens.
        z//bar[@attrib5='value4' or
                                 @attrib5='value5' or
                                 @attrib5='value6']TN)r   r<   r=   r"   r>   r-   r0   r3   rE   s     r6   test_booleanOperatorsNoParensz(XPathTests.test_booleanOperatorsNoParens#  sd     7

 	DFF+T2))$&&1DIItyy$))3TUr8   c                     | j                  t        t        d      }| j                  |j                  j                  d      d|j                  z         y)z}
        A missing closing bracket raises a SyntaxError.

        This test excercises the most common failure mode.
        z//bar[@attrib1zTrying to find one ofzCSyntaxError message '%s' doesn't start with 'Trying to find one of'N)rq   r   r   
assertTruemsg
startswith)r5   excs     r6   test_badXPathNoClosingBracketz(XPathTests.test_badXPathNoClosingBracket/  sG     Z9MNGG67Ugg	
r8   )returnN)__name__
__module____qualname__r7   rA   rG   rI   rK   rM   rO   rQ   rT   rV   rY   r[   r]   r`   rb   rd   rf   rh   rj   rl   ro   rs   ru   rw   ry   r{   r    r8   r6   r	   r	      s    =,~
0
0	
3@@000C


3@3	V
&H@K	K
V
r8   r	   N)twisted.trialr   twisted.words.xishr   twisted.words.xish.domishr   twisted.words.xish.xpathr   twisted.words.xish.xpathparserr   TestCaser	   r   r8   r6   <module>r      s*   
 # $ - / 6n
"" n
r8   