o
    ¼>h=*  ã                   @   sR   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„ dej
ƒZdS )	é    )Úunittest)Úxpath)ÚElement)Ú
XPathQuery)ÚSyntaxErrorc                   @   s  e Zd Zd9dd„Zd9dd„Zd9dd„Zd9d	d
„Zd9dd„Zd9dd„Zd9dd„Z	d9dd„Z
d9dd„Zd9dd„Zd9dd„Zd9dd„Zd9dd„Zd9dd„Zd9dd „Zd9d!d"„Zd9d#d$„Zd9d%d&„Zd9d'd(„Zd9d)d*„Zd9d+d,„Zd9d-d.„Zd9d/d0„Zd9d1d2„Zd9d3d4„Zd9d5d6„Zd9d7d8„ZdS ):Ú
XPathTestsÚreturnNc                 C   s¦  t dƒ| _d| jd< d| jd< | j d¡ | j d¡| _| j d¡| _| j d	¡| _| j d
¡ | j d¡ | j d¡| _d| jd< | j d¡| _| j d¡| _	| j d	¡| _
| j
 d¡ | j d¡| _| j d¡| _d| jd< d| jd< | j d¡| _| j d	¡| _| j d¡ | j d¡| _d| jd< d| jd< | j d¡| _| j d	¡| _| j d¡ | j d¡| _d| jd< d| jd< d| jd< | j d¡| _| j d¡ d S )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   ©Úself© r4   ú}/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/test/test_xpath.pyÚsetUp   sD   










zXPathTests.setUpc              	   C   sx   |   t d| j¡d¡ |   t d| j¡| j| j| j| j| j	| j
g¡ |   t d| j¡d¡ |   t d| j¡ddg¡ dS )z=
        Test basic operation of the static methods.
        ú/foo/barTú/foor   r   N)ÚassertEqualr   Úmatchesr    ÚqueryForNodesr#   r&   r*   r+   r.   r1   ÚqueryForStringÚqueryForStringListr2   r4   r4   r5   Útest_staticMethodsL   s   þÿzXPathTests.test_staticMethodsc                 C   ó    t dƒ}|  | | j¡d¡ dS )z3
        Test matching foo with child bar.
        r7   é   N©r   r9   r:   r    ©r3   Úxpr4   r4   r5   Útest_locationFooBarZ   ó   zXPathTests.test_locationFooBarc                 C   ó@   t dƒ}|  | | j¡d¡ |  | | j¡| j| j| jg¡ dS )z8
        Test finding foos at the second level.
        z/foo/bar/foor@   N)r   r9   r:   r    r;   r$   r,   r/   rB   r4   r4   r5   Útest_locationFooBarFooa   s
   ÿz!XPathTests.test_locationFooBarFooc                 C   r?   )z(
        Test not finding bar3.
        z	/foo/bar3r   NrA   rB   r4   r4   r5   Útest_locationNoBar3k   rE   zXPathTests.test_locationNoBar3c              	   C   sL   t dƒ}|  | | j¡d¡ |  | | j¡| j| j| j| j| j	| j
g¡ dS )z-
        Test finding childs of foo.
        z/foo/*TN)r   r9   r:   r    r;   r#   r&   r*   r+   r.   r1   rB   r4   r4   r5   Útest_locationAllChildsr   s   
þz!XPathTests.test_locationAllChildsc                 C   r?   )z3
        Test matching foo with attribute.
        z/foo[@attrib1]TNrA   rB   r4   r4   r5   Útest_attribute}   rE   zXPathTests.test_attributec                 C   ó8   t dƒ}|  | | j¡d¡ |  | | j¡| jg¡ dS )z>
        Test find nodes with attribute having value.
        z/foo/*[@attrib2='value2']TN)r   r9   r:   r    r;   r&   rB   r4   r4   r5   Útest_attributeWithValueAny„   ó   z%XPathTests.test_attributeWithValueAnyc                 C   rK   )zI
        Nodes' attributes can be matched with non-ASCII values.
        u   /foo/*[@attrib6='Ã¡']TN)r   r9   r:   r    r;   r1   rB   r4   r4   r5   Útest_locationWithValueUnicodeŒ   rM   z(XPathTests.test_locationWithValueUnicodec                 C   r?   )z4
        Test matching node with namespace.
        z/foo[@xmlns='testns']/barr@   NrA   rB   r4   r4   r5   Útest_namespaceFound”   rE   zXPathTests.test_namespaceFoundc                 C   r?   )z>
        Test not matching node with wrong namespace.
        z/foo[@xmlns='badns']/bar2r   NrA   rB   r4   r4   r5   Útest_namespaceNotFound›   rE   z!XPathTests.test_namespaceNotFoundc                 C   r?   )zA
        Test matching node with attribute having value.
        z/foo[@attrib1='value1']r@   NrA   rB   r4   r4   r5   Útest_attributeWithValue¢   rE   z"XPathTests.test_attributeWithValuec                 C   r?   )zM
        queryforString on absolute paths returns their first CDATA.
        r8   r   N)r   r9   r<   r    rB   r4   r4   r5   Útest_queryForString©   rE   zXPathTests.test_queryForStringc                 C   ó$   t dƒ}|  | | j¡ddg¡ dS )zO
        queryforStringList on absolute paths returns all their CDATA.
        r8   r   r   N©r   r9   r=   r    rB   r4   r4   r5   Útest_queryForStringList°   ó   ÿz"XPathTests.test_queryForStringListc                 C   rS   )zO
        queryforStringList on relative paths returns all their CDATA.
        z//foor   r   NrT   rB   r4   r4   r5   Ú"test_queryForStringListAnyLocation¹   rV   z-XPathTests.test_queryForStringListAnyLocationc              	   C   s8   t dƒ}|  | | j¡| j| j| j| j| j| j	g¡ dS )z%
        Test finding nodes.
        r7   N)
r   r9   r;   r    r#   r&   r*   r+   r.   r1   rB   r4   r4   r5   Útest_queryForNodesÂ   s
   
þzXPathTests.test_queryForNodesc                 C   r?   )z7
        Test matching a node with given text.
        z/foo[text() = 'somecontent']TNrA   rB   r4   r4   r5   Útest_textConditionÌ   rE   zXPathTests.test_textConditionc                 C   rK   )zK
        A node can be matched by text with non-ascii code points.
        u   //*[text()='â˜ƒ']TN)r   r9   r:   r    r;   r   rB   r4   r4   r5   Útest_textConditionUnicodeÓ   rM   z$XPathTests.test_textConditionUnicodec                 C   r?   )z(
        Test for not operator.
        z/foo[not(@nosuchattrib)]TNrA   rB   r4   r4   r5   Útest_textNotOperatorÛ   rE   zXPathTests.test_textNotOperatorc                 C   s\   t dƒ}|  | | j¡d¡ |  | | j¡| j| j| j| jg¡ |  | 	| j¡g d¢¡ dS )zS
        Test finding any nodes named gar and getting their text contents.
        z//garT)r   r   r   r   N)
r   r9   r:   r    r;   r%   r)   r-   r0   r=   rB   r4   r4   r5   Útest_anyLocationAndTextâ   s   ÿz"XPathTests.test_anyLocationAndTextc              
   C   sP   t dƒ}|  | | j¡d¡ |  | | j¡| j| j| j| j| j	| j
| jg¡ dS )z3
        Test finding any nodes named bar.
        ú//barTN)r   r9   r:   r    r;   r#   r&   r'   r*   r+   r.   r1   rB   r4   r4   r5   Útest_anyLocationí   s   
ùþzXPathTests.test_anyLocationc                 C   s   t dƒ}|  t|jd¡ dS )zn
        L{XPathQuery.queryForString} should raise a L{NotImplementedError}
        for any location.
        r]   N)r   ÚassertRaisesÚNotImplementedErrorr<   rB   r4   r4   r5   Útest_anyLocationQueryForString   s   z)XPathTests.test_anyLocationQueryForStringc                 C   rK   )z9
        Test boolean and operator in condition.
        z.//bar[@attrib4='value4' and @attrib5='value5']TN)r   r9   r:   r    r;   r+   rB   r4   r4   r5   Útest_andOperator  rM   zXPathTests.test_andOperatorc                 C   ó<   t dƒ}|  | | j¡d¡ |  | | j¡| j| jg¡ dS )z8
        Test boolean or operator in condition.
        z-//bar[@attrib5='value4' or @attrib5='value5']TN)r   r9   r:   r    r;   r+   r.   rB   r4   r4   r5   Útest_orOperator  s    zXPathTests.test_orOperatorc                 C   rc   )zK
        Test multiple boolean operators in condition with parens.
        zf//bar[@attrib4='value4' and
                                 (@attrib5='value4' or @attrib5='value6')]TN)r   r9   r:   r    r;   r.   r1   rB   r4   r4   r5   Útest_booleanOperatorsParens  s
   ÿ z&XPathTests.test_booleanOperatorsParensc                 C   rF   )zN
        Test multiple boolean operators in condition without parens.
        z„//bar[@attrib5='value4' or
                                 @attrib5='value5' or
                                 @attrib5='value6']TN)r   r9   r:   r    r;   r+   r.   r1   rB   r4   r4   r5   Útest_booleanOperatorsNoParens#  s
   ÿ$z(XPathTests.test_booleanOperatorsNoParensc                 C   s,   |   ttd¡}|  |j d¡d|j ¡ dS )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)r_   r   r   Ú
assertTrueÚmsgÚ
startswith)r3   Úexcr4   r4   r5   Útest_badXPathNoClosingBracket/  s   
ÿþz(XPathTests.test_badXPathNoClosingBracket)r   N)Ú__name__Ú
__module__Ú__qualname__r6   r>   rD   rG   rH   rI   rJ   rL   rN   rO   rP   rQ   rR   rU   rW   rX   rY   rZ   r[   r\   r^   ra   rb   rd   re   rf   rk   r4   r4   r4   r5   r      s8    

?













	
	










r   N)Útwisted.trialr   Útwisted.words.xishr   Útwisted.words.xish.domishr   Útwisted.words.xish.xpathr   Útwisted.words.xish.xpathparserr   ÚTestCaser   r4   r4   r4   r5   Ú<module>   s   