o
    Óó·i=*  ã                   @   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)ZtestnsÚfooZvalue1Zattrib1zuser@host/resourceZattrib3ÚsomecontentÚbarr	   ZgarÚDEFÚsomemorecontentZvalue2Zattrib2ÚABCZvalue4Zattrib4Zvalue5Zattrib5ÚJKLÚMNOZvalue6õ   Ã¡Zattrib6Úquuxu   â˜ƒ)r   ÚeZ
addContentZ
addElementÚbar1ÚsubfooÚgar1Úbar2Úbar3Zsubfoo2Úgar2Úbar4Úbar5Úsubfoo3Úgar3Úbar6Úsubfoo4Úgar4Úbar7r   ©Úself© r$   úcC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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   r!   ÚqueryForStringÚqueryForStringListr"   r$   r$   r%   Útest_staticMethodsL   s   þÿzXPathTests.test_staticMethodsc                 C   ó    t dƒ}|  | | j¡d¡ dS )z3
        Test matching foo with child bar.
        r'   é   N©r   r)   r*   r   ©r#   Zxpr$   r$   r%   Ú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/foor0   N)r   r)   r*   r   r+   r   r   r   r2   r$   r$   r%   Útest_locationFooBarFooa   s
   ÿz!XPathTests.test_locationFooBarFooc                 C   r/   )z(
        Test not finding bar3.
        z	/foo/bar3r   Nr1   r2   r$   r$   r%   Útest_locationNoBar3k   r4   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   r)   r*   r   r+   r   r   r   r   r   r!   r2   r$   r$   r%   Útest_locationAllChildsr   s   
þz!XPathTests.test_locationAllChildsc                 C   r/   )z3
        Test matching foo with attribute.
        z/foo[@attrib1]TNr1   r2   r$   r$   r%   Útest_attribute}   r4   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   r)   r*   r   r+   r   r2   r$   r$   r%   Útest_attributeWithValueAny„   ó   z%XPathTests.test_attributeWithValueAnyc                 C   r:   )zI
        Nodes' attributes can be matched with non-ASCII values.
        u   /foo/*[@attrib6='Ã¡']TN)r   r)   r*   r   r+   r!   r2   r$   r$   r%   Útest_locationWithValueUnicodeŒ   r<   z(XPathTests.test_locationWithValueUnicodec                 C   r/   )z4
        Test matching node with namespace.
        z/foo[@xmlns='testns']/barr0   Nr1   r2   r$   r$   r%   Útest_namespaceFound”   r4   zXPathTests.test_namespaceFoundc                 C   r/   )z>
        Test not matching node with wrong namespace.
        z/foo[@xmlns='badns']/bar2r   Nr1   r2   r$   r$   r%   Útest_namespaceNotFound›   r4   z!XPathTests.test_namespaceNotFoundc                 C   r/   )zA
        Test matching node with attribute having value.
        z/foo[@attrib1='value1']r0   Nr1   r2   r$   r$   r%   Útest_attributeWithValue¢   r4   z"XPathTests.test_attributeWithValuec                 C   r/   )zM
        queryforString on absolute paths returns their first CDATA.
        r(   r
   N)r   r)   r,   r   r2   r$   r$   r%   Útest_queryForString©   r4   zXPathTests.test_queryForStringc                 C   ó$   t dƒ}|  | | j¡ddg¡ dS )zO
        queryforStringList on absolute paths returns all their CDATA.
        r(   r
   r   N©r   r)   r-   r   r2   r$   r$   r%   Útest_queryForStringList°   ó   ÿz"XPathTests.test_queryForStringListc                 C   rB   )zO
        queryforStringList on relative paths returns all their CDATA.
        z//foor
   r   NrC   r2   r$   r$   r%   Ú"test_queryForStringListAnyLocation¹   rE   z-XPathTests.test_queryForStringListAnyLocationc              	   C   s8   t dƒ}|  | | j¡| j| j| j| j| j| j	g¡ dS )z%
        Test finding nodes.
        r'   N)
r   r)   r+   r   r   r   r   r   r   r!   r2   r$   r$   r%   Útest_queryForNodesÂ   s
   
þzXPathTests.test_queryForNodesc                 C   r/   )z7
        Test matching a node with given text.
        z/foo[text() = 'somecontent']TNr1   r2   r$   r$   r%   Útest_textConditionÌ   r4   zXPathTests.test_textConditionc                 C   r:   )zK
        A node can be matched by text with non-ascii code points.
        u   //*[text()='â˜ƒ']TN)r   r)   r*   r   r+   r   r2   r$   r$   r%   Útest_textConditionUnicodeÓ   r<   z$XPathTests.test_textConditionUnicodec                 C   r/   )z(
        Test for not operator.
        z/foo[not(@nosuchattrib)]TNr1   r2   r$   r$   r%   Útest_textNotOperatorÛ   r4   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   r)   r*   r   r+   r   r   r   r    r-   r2   r$   r$   r%   Ú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   r)   r*   r   r+   r   r   r   r   r   r   r!   r2   r$   r$   r%   Ú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.
        rL   N)r   ÚassertRaisesÚNotImplementedErrorr,   r2   r$   r$   r%   Útest_anyLocationQueryForString   s   z)XPathTests.test_anyLocationQueryForStringc                 C   r:   )z9
        Test boolean and operator in condition.
        z.//bar[@attrib4='value4' and @attrib5='value5']TN)r   r)   r*   r   r+   r   r2   r$   r$   r%   Útest_andOperator  r<   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   r)   r*   r   r+   r   r   r2   r$   r$   r%   Útest_orOperator  s    zXPathTests.test_orOperatorc                 C   rR   )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+   r   r!   r2   r$   r$   r%   Útest_booleanOperatorsParens  s
   ÿ z&XPathTests.test_booleanOperatorsParensc                 C   r5   )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   r   r!   r2   r$   r$   r%   Ú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)rN   r   r   Ú
assertTrueÚmsgÚ
startswith)r#   Úexcr$   r$   r%   Útest_badXPathNoClosingBracket/  s   
ÿþz(XPathTests.test_badXPathNoClosingBracket)r   N)Ú__name__Ú
__module__Ú__qualname__r&   r.   r3   r6   r7   r8   r9   r;   r=   r>   r?   r@   rA   rD   rF   rG   rH   rI   rJ   rK   rM   rP   rQ   rS   rT   rU   rZ   r$   r$   r$   r%   r      s8    

?













	
	


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