U
    
W[X(  ć                   @   sx   d Z ddlmZ ddlmZ ddlmZ G dd deZG dd deej	Z
G d	d
 d
eej	ZG dd deej	ZdS )z&
Tests for L{twisted.python.urlpath}.
é    )Śunittest)Śurlpath)Ś_PY3c                   @   sx   e Zd ZdZdd Zdd Zedf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 )Ś_BaseURLPathTestsz5
    Tests for instantiated L{urlpath.URLPath}s.
    c                 C   sT   |   | jjt” |   | jjt” |   | jjt” |   | jjt” |   | jjt” dS )zQ
        All of the attributes of L{urlpath.URLPath} should be L{bytes}.
        N©ZassertIsInstanceŚpathŚschemeŚbytesŚnetlocŚqueryŚfragment©Śself© r   śB/usr/lib/python3/dist-packages/twisted/python/test/test_urlpath.pyŚtest_partsAreBytes   s
    z$_BaseURLPathTests.test_partsAreBytesc                 C   s   |   t| j ” t” dS )zQ
        Calling C{str()} with a L{URLPath} will always return a L{str}.
        N)ŚassertEqualŚtyper   Ś__str__Śstrr   r   r   r   Śtest_strReturnsStr   s    z$_BaseURLPathTests.test_strReturnsStrŚ c                 C   s   |d| j _|  t| j d” |d| j _|  t| j d” |d| j _ |  t| j d” |d| j _|  t| j d” |d	| j _|  t| j d
” dS )aC  
        Setting attributes on L{urlpath.URLPath} should change the value
        returned by L{str}.

        @param stringType: a callable to parameterize this test for different
            text types.
        @type stringType: 1-argument callable taking L{unicode} and returning
            L{str} or L{bytes}.
        Zhttpsz0https://example.com/foo/bar?yes=no&no=yes#footerzanother.example.invalidz<https://another.example.invalid/foo/bar?yes=no&no=yes#footerz/helloz:https://another.example.invalid/hello?yes=no&no=yes#footerzalpha=omega&opposites=samezGhttps://another.example.invalid/hello?alpha=omega&opposites=same#footerŚheaderzGhttps://another.example.invalid/hello?alpha=omega&opposites=same#headerN)r   r   r   r   r
   r   r   )r   Z
stringTyper   r   r   Śtest_mutabilityWithText$   s2    
žžžžžz)_BaseURLPathTests.test_mutabilityWithTextc                 C   s   |   dd ” dS )zC
        Same as L{test_mutabilityWithText} but for bytes.
        c                 S   s
   |   d”S )NŚascii)Śencode)Śxr   r   r   Ś<lambda>J   ó    z<_BaseURLPathTests.test_mutabilityWithBytes.<locals>.<lambda>N)r   r   r   r   r   Śtest_mutabilityWithBytesF   s    z*_BaseURLPathTests.test_mutabilityWithBytesc                 C   sT   |   | jjt” |   | jjt” |   | jjt” |   | jjt” |   | jjt” dS )z<
        A created L{URLPath} has bytes attributes.
        Nr   r   r   r   r   Śtest_allAttributesAreBytesM   s
    z,_BaseURLPathTests.test_allAttributesAreBytesc                 C   s   |   t| jd” dS )zs
        Calling C{str()} with a L{URLPath} will return the same URL that it was
        constructed with.
        ś/http://example.com/foo/bar?yes=no&no=yes#footerN)r   r   r   r   r   r   r   Śtest_stringConversionX   s    ’z'_BaseURLPathTests.test_stringConversionc                 C   sV   |   t| j d”d” |   t| j d” d”d” |   t| jjdddd” dS )	z
        Calling C{str()} with a C{URLPath.child()} will return a URL which is
        the child of the URL it was instantiated with.
        s   helloz http://example.com/foo/bar/hellor   z!http://example.com/foo/bar/hello/T©Z	keepQueryz.http://example.com/foo/bar/hello?yes=no&no=yesN)r   r   r   Śchildr   r   r   r   Śtest_childStringa   s    ’’’z"_BaseURLPathTests.test_childStringc                 C   sV   |   t| j d”d” |   t| jjdddd” |   t| j d” d”d” dS )	z
        Calling C{str()} with a C{URLPath.sibling()} will return a URL which is
        the sibling of the URL it was instantiated with.
        ó   bazzhttp://example.com/foo/bazTr#   z(http://example.com/foo/baz?yes=no&no=yesr   zhttp://example.com/foo/bar/bazN)r   r   r   Zsiblingr$   r   r   r   r   Śtest_siblingStringn   s    ’’’z$_BaseURLPathTests.test_siblingStringc                 C   s   |   t| j ” d” |   t| jjddd” |   t| j d” ” d” |   t| j d” ” d” |   t| j ”  ”  ”  ”  ” d” dS )	z
        Calling C{str()} with a C{URLPath.parent()} will return a URL which is
        the parent of the URL it was instantiated with.
        zhttp://example.com/Tr#   z!http://example.com/?yes=no&no=yesr   śhttp://example.com/foo/r&   N)r   r   r   Śparentr$   r   r   r   r   Śtest_parentString   s     ’’’’žz#_BaseURLPathTests.test_parentStringc                 C   sP   |   t| j ” d” |   t| jjddd” |   t| j d” ” d” dS )z³
        Calling C{str()} with a C{URLPath.here()} will return a URL which is
        the URL that it was instantiated with, without any file, query, or
        fragment.
        r(   Tr#   z%http://example.com/foo/?yes=no&no=yesr   zhttp://example.com/foo/bar/N)r   r   r   Śherer$   r   r   r   r   Śtest_hereString   s    ’’z!_BaseURLPathTests.test_hereStringc                 C   s"   |   t| j d” d”d” dS )zź
        Calling L{urlpath.URLPath.click} on a L{urlpath.URLPath} with a
        trailing slash with a relative URL containing a leading slash will
        result in a URL with a single slash at the start of the path portion.
        s   /hello/worldr   s   http://example.com/hello/worldN)r   r   r   Zclickr   r   r   r   r   Śtest_doubleSlash¢   s    žz"_BaseURLPathTests.test_doubleSlashc                 C   sl   |   | j d” ” ddddg” |   | j d”jddddddg” |   | j d”jdddddd	g” d
S )zL
        L{urlpath.URLPath.pathList} returns a L{list} of L{bytes}.
        s	   %00%01%02r   s   foos   barF)ŚcopyT)Zunquotes    N)r   r   r$   ZpathListr   r   r   r   Śtest_pathList®   s    
ž	
ž
žz_BaseURLPathTests.test_pathListN)Ś__name__Ś
__module__Ś__qualname__Ś__doc__r   r   r   r   r   r    r"   r%   r'   r*   r,   r-   r/   r   r   r   r   r      s   "	r   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )ŚBytesURLPathTestszL
    Tests for interacting with a L{URLPath} created with C{fromBytes}.
    c                 C   s   t j d”| _d S )Ns/   http://example.com/foo/bar?yes=no&no=yes#footer)r   ŚURLPathŚ	fromBytesr   r   r   r   r   ŚsetUpŹ   s    ’zBytesURLPathTests.setUpc              	   C   sH   |   t” tj d” W 5 Q R X |   t” tj d” W 5 Q R X dS )zE
        L{URLPath.fromBytes} must take a L{bytes} argument.
        NZsomeurl)ŚassertRaisesŚ
ValueErrorr   r5   r6   r   r   r   r   Śtest_mustBeBytesĻ   s    z"BytesURLPathTests.test_mustBeBytesc                 C   s   t  ” }|  t|d” dS )zp
        An instantiation with no arguments creates a usable L{URLPath} with
        default arguments.
        zhttp://localhost/N)r   r5   r   r   ©r   Zurlr   r   r   Śtest_withoutArgumentsŚ   s    z'BytesURLPathTests.test_withoutArgumentsc                 C   sf   t j d”}|  |jd” |  |jd” |  |jd” |  |jd” |  |jd” |  t	|d” dS )z
        Leaving some optional arguments unfilled makes a L{URLPath} with those
        optional arguments filled with defaults.
        s   http://google.coms   https
   google.comó   /r   zhttp://google.com/N)
r   r5   r6   r   r   r
   r   r   r   r   r;   r   r   r   Śtest_partialArgumentsć   s    z'BytesURLPathTests.test_partialArgumentsc                 C   s    t j d”}|  t|d” dS )zW
        L{URLPath.fromBytes} can interpret non-ASCII bytes as percent-encoded
        s   http://example.com/’ zhttp://example.com/%FF%00N)r   r5   r6   r   r   r;   r   r   r   Śtest_nonASCIIBytesó   s    z$BytesURLPathTests.test_nonASCIIBytesN)	r0   r1   r2   r3   r7   r:   r<   r>   r?   r   r   r   r   r4   Ę   s   	r4   c                   @   s    e Zd ZdZdd Zdd ZdS )ŚStringURLPathTestszg
    Tests for interacting with a L{URLPath} created with C{fromString} and a
    L{str} argument.
    c                 C   s   t j d”| _d S ©Nr!   ©r   r5   Ś
fromStringr   r   r   r   r   r7     s    ’zStringURLPathTests.setUpc              	   C   sL   |   t” tj d” W 5 Q R X trH|   t” tj d” W 5 Q R X dS )zR
        C{URLPath.fromString} must take a L{str} or L{unicode} argument.
        Ns   someurl)r8   r9   r   r5   rC   r   r   r   r   r   Śtest_mustBeStr  s
    z!StringURLPathTests.test_mustBeStrN)r0   r1   r2   r3   r7   rD   r   r   r   r   r@   ü   s   r@   c                   @   s    e Zd ZdZdd Zdd ZdS )ŚUnicodeURLPathTestszk
    Tests for interacting with a L{URLPath} created with C{fromString} and a
    L{unicode} argument.
    c                 C   s   t j d”| _d S rA   rB   r   r   r   r   r7     s    ’zUnicodeURLPathTests.setUpc                 C   s    t j d”}|  t|d” dS )zF
        L{URLPath.fromString} can load non-ASCII characters.
        u   http://example.com/Ćæ zhttp://example.com/%C3%BF%00N)r   r5   rC   r   r   r;   r   r   r   Śtest_nonASCIICharacters  s    z+UnicodeURLPathTests.test_nonASCIICharactersN)r0   r1   r2   r3   r7   rF   r   r   r   r   rE     s   rE   N)r3   Ztwisted.trialr   Ztwisted.pythonr   Ztwisted.python.compatr   Śobjectr   ZTestCaser4   r@   rE   r   r   r   r   Ś<module>   s    96