o
    ¯bà  ã                   @   sV   d Z ddlmZ ddlmZ G dd„ dejƒZG dd„ dejƒZG dd	„ d	ejƒZd
S )z2
Tests for L{twisted.words.protocols.jabber.jid}.
é    )Úunittest)Újidc                   @   sD   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S )ÚJIDParsingTestsc                 C   s¸   |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d	¡d
¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ dS )z/
        Test different forms of JIDs.
        úuser@host/resource©ÚuserÚhostÚresourceú	user@host©r   r   Nr   ©Nr   Núhost/resource©Nr   r	   zfoo/bar@baz)NÚfooúbar@bazzboo@foo/bar@baz)Úboor   r   zboo@foo/bar/baz)r   r   zbar/bazzboo/foo@bar@baz)Nr   zfoo@bar@bazzboo/foo/bar)Nr   zfoo/barzboo//foo)Nr   z/fooN)ÚassertEqualr   Úparse©Úself© r   úC/usr/lib/python3/dist-packages/twisted/words/test/test_jabberjid.pyÚ
test_parse   s   zJIDParsingTests.test_parsec                 C   ó   |   tjtjd¡ dS )z3
        Test for failure on no host part.
        zuser@N©ÚassertRaisesr   ÚInvalidFormatr   r   r   r   r   Útest_noHost   s   zJIDParsingTests.test_noHostc                 C   r   )z˜
        Test for failure on double @ signs.

        This should fail because @ is not a valid character for the host
        part of the JID.
        z
user@@hostNr   r   r   r   r   Útest_doubleAt%   ó   zJIDParsingTests.test_doubleAtc                 C   r   )z•
        Test for failure on two @ signs.

        This should fail because @ is not a valid character for the host
        part of the JID.
        zuser@host@hostNr   r   r   r   r   Útest_multipleAt.   r   zJIDParsingTests.test_multipleAtc                 C   ó   |   t ddd¡d¡ dS )z@
        Test case mapping of the user part of the JID.
        ÚUsErr   r	   r   N©r   r   Úprepr   r   r   r   Útest_prepCaseMapUser:   ó   ÿz$JIDParsingTests.test_prepCaseMapUserc                 C   r!   )z@
        Test case mapping of the host part of the JID.
        r   ÚhoSTr	   r   Nr#   r   r   r   r   Útest_prepCaseMapHostB   r&   z$JIDParsingTests.test_prepCaseMapHostc                 C   s0   |   t ddd¡d¡ |  t ddd¡d¡ dS )zH
        Test no case mapping of the resourcce part of the JID.
        r   r'   r	   r   r   ÚResourceN)r   r   r$   ÚassertNotEqualr   r   r   r   Útest_prepNoCaseMapResourceJ   s   ÿÿz*JIDParsingTests.test_prepNoCaseMapResourceN)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r    r%   r(   r+   r   r   r   r   r      s    	r   c                   @   s”   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#S )$ÚJIDTestsc                 C   s   |   ttj¡ dS )zC
        Test that using no arguments raises an exception.
        N)r   ÚRuntimeErrorr   ÚJIDr   r   r   r   Útest_noneArgumentsW   s   zJIDTests.test_noneArgumentsc                 C   s8   t  d¡}|  |jd¡ |  |jd¡ |  |jd¡ dS )zI
        Test that the attributes correspond with the JID parts.
        r   r   r   r	   N)r   r1   r   r   r   r	   ©r   Újr   r   r   Útest_attributes]   s   
zJIDTests.test_attributesc                 C   ó   t  d¡}|  d| ¡ ¡ dS )z6
        Test the extraction of the bare JID.
        r   r
   N©r   r1   r   Úuserhostr3   r   r   r   Útest_userhostf   ó   
zJIDTests.test_userhostc                 C   r6   )zU
        Test the extraction of the bare JID of the full form host/resource.
        r   r   Nr7   r3   r   r   r   Útest_userhostOnlyHostm   r:   zJIDTests.test_userhostOnlyHostc                 C   s(   t  d¡}t  d¡}|  || ¡ ¡ dS )z<
        Test getting a JID object of the bare JID.
        r   r
   N)r   r1   Ú	internJIDÚassertIdenticalÚuserhostJID©r   Új1Új2r   r   r   Útest_userhostJIDt   s   

zJIDTests.test_userhostJIDc                 C   s   t  d¡}|  || ¡ ¡ dS )zW
        Test getting a JID object of the bare JID when there was no resource.
        r
   N)r   r1   r=   r>   r3   r   r   r   Útest_userhostJIDNoResource|   r:   z#JIDTests.test_userhostJIDNoResourcec                 C   ó    t jdd�}|  d| ¡ ¡ dS )zW
        Test giving a string representation of the JID with only a host part.
        r   ©Útupler   N©r   r1   r   Úfullr3   r   r   r   Útest_fullHostƒ   ó   zJIDTests.test_fullHostc                 C   rD   )zU
        Test giving a string representation of the JID with host, resource.
        r   rE   r   NrG   r3   r   r   r   Útest_fullHostResourceŠ   rJ   zJIDTests.test_fullHostResourcec                 C   rD   )zQ
        Test giving a string representation of the JID with user, host.
        r   rE   r
   NrG   r3   r   r   r   Útest_fullUserHost‘   rJ   zJIDTests.test_fullUserHostc                 C   rD   )zA
        Test giving a string representation of the JID.
        r   rE   r   NrG   r3   r   r   r   Útest_fullAll˜   rJ   zJIDTests.test_fullAllc                 C   s0   t  d¡}t  d¡}|  ||¡ |  ||¡ dS ©z$
        Test JID equality.
        r   N)r   r1   ÚassertNotIdenticalr   r?   r   r   r   Útest_equalityŸ   s   

zJIDTests.test_equalityc                 C   s   t  d¡}|  |dk¡ dS rN   )r   r1   ÚassertFalser3   r   r   r   Útest_equalityWithNonJIDs¨   s   
z!JIDTests.test_equalityWithNonJIDsc                 C   s$   t  d¡}t  d¡}|  ||¡ dS )z&
        Test JID inequality.
        zuser1@host/resourcezuser2@host/resourceN©r   r1   r*   r?   r   r   r   Útest_inequality¯   ó   

zJIDTests.test_inequalityc                 C   s   t  d¡}|  |d¡ dS rN   rS   r3   r   r   r   Útest_inequalityWithNonJIDs·   s   
z#JIDTests.test_inequalityWithNonJIDsc                 C   s,   t  d¡}t  d¡}|  t|ƒt|ƒ¡ dS )z'
        Test JID hashability.
        r   N)r   r1   r   Úhashr?   r   r   r   Útest_hashable¾   s   

zJIDTests.test_hashablec                 C   s    t jdd�}|  dt|ƒ¡ dS )z6
        Test unicode representation of JIDs.
        r   rE   r   N)r   r1   r   Ústrr3   r   r   r   Útest_strÆ   rJ   zJIDTests.test_strc                 C   s(   t jdd�}|  dtdƒ t|ƒ¡ dS )z5
        Test representation of JID objects.
        r   rE   zJID(%s)r   N)r   r1   r   Úreprr3   r   r   r   Ú	test_reprÍ   s   zJIDTests.test_reprN)r,   r-   r.   r2   r5   r9   r;   rB   rC   rI   rK   rL   rM   rP   rR   rT   rV   rX   rZ   r\   r   r   r   r   r/   V   s$    		r/   c                   @   s   e Zd Zdd„ ZdS )ÚInternJIDTestsc                 C   s$   t  d¡}t  d¡}|  ||¡ dS )zD
        Test that two interned JIDs yield the same object.
        r
   N)r   r<   r=   r?   r   r   r   Útest_identityÖ   rU   zInternJIDTests.test_identityN)r,   r-   r.   r^   r   r   r   r   r]   Õ   s    r]   N)	Ú__doc__Útwisted.trialr   Útwisted.words.protocols.jabberr   ÚTestCaser   r/   r]   r   r   r   r   Ú<module>   s   J