U
    
W[*  ć                   @   sb   d Z ddlm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}.
é    )Śunicode)Ś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   s   |   tjtjd” dS )z3
        Test for failure on no host part.
        zuser@N©ŚassertRaisesr   ZInvalidFormatr   r   r   r   r   Śtest_noHost*   s    zJIDParsingTests.test_noHostc                 C   s   |   tjtjd” dS )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_doubleAt0   s    zJIDParsingTests.test_doubleAtc                 C   s   |   tjtjd” dS )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_multipleAt9   s    zJIDParsingTests.test_multipleAtc                 C   s   |   t ddd”d” dS )z@
        Test case mapping of the user part of the JID.
        ZUsErr	   r
   r   N©r   r   Śprepr   r   r   r   Śtest_prepCaseMapUserE   s    ’z$JIDParsingTests.test_prepCaseMapUserc                 C   s   |   t ddd”d” dS )z@
        Test case mapping of the host part of the JID.
        r   ŚhoSTr
   r   Nr   r   r   r   r   Śtest_prepCaseMapHostL   s    ’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	   ZResourceN)r   r   r    ŚassertNotEqualr   r   r   r   Śtest_prepNoCaseMapResourceS   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_noneArguments^   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   r+   r   r   r	   r
   ©r   Śjr   r   r   Śtest_attributesd   s    
zJIDTests.test_attributesc                 C   s   t  d”}|  d| ” ” dS )z6
        Test the extraction of the bare JID.
        r   r   N©r   r+   r   Zuserhostr-   r   r   r   Śtest_userhostm   s    
zJIDTests.test_userhostc                 C   s   t  d”}|  d| ” ” dS )zU
        Test the extraction of the bare JID of the full form host/resource.
        r   r	   Nr0   r-   r   r   r   Śtest_userhostOnlyHostt   s    
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   r+   Ś	internJIDŚassertIdenticalŚuserhostJID©r   Zj1Zj2r   r   r   Śtest_userhostJID{   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   r+   r4   r5   r-   r   r   r   Śtest_userhostJIDNoResource   s    
z#JIDTests.test_userhostJIDNoResourcec                 C   s    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   r+   r   Zfullr-   r   r   r   Śtest_fullHost   s    zJIDTests.test_fullHostc                 C   s    t jdd}|  d| ” ” dS )zU
        Test giving a string representation of the JID with host, resource.
        r   r9   r   Nr;   r-   r   r   r   Śtest_fullHostResource   s    zJIDTests.test_fullHostResourcec                 C   s    t jdd}|  d| ” ” dS )zQ
        Test giving a string representation of the JID with user, host.
        r   r9   r   Nr;   r-   r   r   r   Śtest_fullUserHost   s    zJIDTests.test_fullUserHostc                 C   s    t jdd}|  d| ” ” dS )zA
        Test giving a string representation of the JID.
        r   r9   r   Nr;   r-   r   r   r   Śtest_fullAll   s    zJIDTests.test_fullAllc                 C   s0   t  d”}t  d”}|  ||” |  ||” dS ©z$
        Test JID equality.
        r   N)r   r+   ZassertNotIdenticalr   r6   r   r   r   Śtest_equality¦   s    

zJIDTests.test_equalityc                 C   s   t  d”}|  |dk” dS r@   )r   r+   ZassertFalser-   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   r+   r$   r6   r   r   r   Śtest_inequality¶   s    

zJIDTests.test_inequalityc                 C   s   t  d”}|  |d” dS r@   rC   r-   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   r+   r   Śhashr6   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   r9   r   N)r   r+   r   r   r-   r   r   r   Śtest_unicodeĶ   s    zJIDTests.test_unicodec                 C   s(   t jdd}|  dtd t|” dS )z5
        Test representation of JID objects.
        r   r9   zJID(%s)r   N)r   r+   r   Śreprr-   r   r   r   Ś	test_reprŌ   s    zJIDTests.test_reprN)r&   r'   r(   r,   r/   r1   r2   r7   r8   r<   r=   r>   r?   rA   rB   rD   rE   rG   rH   rJ   r   r   r   r   r)   \   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   r3   r4   r6   r   r   r   Śtest_identityÜ   s    

zInternJIDTests.test_identityN)r&   r'   r(   rL   r   r   r   r   rK   Ū   s   rK   N)Ś__doc__Ztwisted.python.compatr   Ztwisted.trialr   Ztwisted.words.protocols.jabberr   ZTestCaser   r)   rK   r   r   r   r   Ś<module>   s   O