U
    P|jå'  ã                   @   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-audpp6lv/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