U
    Acjå'  ć                   @   sj   d Z ddlmZ ddlmZ G dd d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}.
é    )Śurlpath)Śunittestc                   @   st   e Zd ZdZdd Zdd Ze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   śD/tmp/pip-unpacked-wheel-nrvc_22y/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_strReturnsStrc                 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 )a?  
        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{str} and returning
            L{str} or L{bytes}.
        Ś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_allAttributesAreBytesL   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_stringConversionV   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_childString_   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_siblingStringp   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)Ś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   Ś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 )ŚStringURLPathTestsśg
    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   sH   |   t” tj d” W 5 Q R X |   t” tj d” W 5 Q R X dS )zN
        C{URLPath.fromString} must take a L{str} or L{str} argument.
        Ns   someurl)r8   r9   r   r5   rE   r   r   r   r   Śtest_mustBeStr  s    z!StringURLPathTests.test_mustBeStrN)r0   r1   r2   r3   r7   rF   r   r   r   r   rA   ū   s   rA   c                   @   s    e Zd ZdZdd Zdd ZdS )ŚUnicodeURLPathTestsrB   c                 C   s   t j d”| _d S rC   rD   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   rE   r   r   r;   r   r   r   Śtest_nonASCIICharacters  s    z+UnicodeURLPathTests.test_nonASCIICharactersN)r0   r1   r2   r3   r7   rH   r   r   r   r   rG     s   rG   N)
r3   Ztwisted.pythonr   Ztwisted.trialr   r   ZTestCaser4   rA   rG   r   r   r   r   Ś<module>   s    <3