o
    ¯bå'  ã                   @   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   óT   |   | 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©ÚassertIsInstanceÚpathÚschemeÚbytesÚnetlocÚqueryÚfragment©Úself© r   úB/usr/lib/python3/dist-packages/twisted/python/test/test_urlpath.pyÚtest_partsAreBytes   ó
   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   Ú
stringTyper   r   r   Útest_mutabilityWithText"   s.   

ÿþ
ÿþþ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   s   
 z<_BaseURLPathTests.test_mutabilityWithBytes.<locals>.<lambda>N)r   r   r   r   r   Útest_mutabilityWithBytesF   s   z*_BaseURLPathTests.test_mutabilityWithBytesc                 C   r   )z<
        A created L{URLPath} has bytes attributes.
        Nr   r   r   r   r   Útest_allAttributesAreBytesL   r   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/helloó    z!http://example.com/foo/bar/hello/T©Ú	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   Ú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   Úclickr   r   r   r   r   Útest_doubleSlash¦   s   þz"_BaseURLPathTests.test_doubleSlashc                 C   s`   |   | j d¡ ¡ g d¢¡ |   | j d¡jddg d¢¡ |   | j d¡jddg d¢¡ dS )	zL
        L{urlpath.URLPath.pathList} returns a L{list} of L{bytes}.
        ó	   %00%01%02)r%   ó   fooó   barr4   F)ÚcopyT)Úunquote)r%   r5   r6   s    N)r   r   r(   Ú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/   r1   r3   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   ó   t j d¡| _d S )Ns/   http://example.com/foo/bar?yes=no&no=yes#footer)r   ÚURLPathÚ	fromBytesr   r   r   r   r   ÚsetUpÍ   ó   
ÿzBytesURLPathTests.setUpc                 C   ór   |   t¡ tj d¡ W d  ƒ n1 sw   Y  |   t¡ tj d¡ W d  ƒ dS 1 s2w   Y  dS )zE
        L{URLPath.fromBytes} must take a L{bytes} argument.
        NÚsomeurl)ÚassertRaisesÚ
ValueErrorr   rA   rB   r   r   r   r   Útest_mustBeBytesÒ   ó   ÿ"ÿ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   rA   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   rA   rB   r   r	   r   r   r   r   r   rK   r   r   r   Útest_partialArgumentsä   s   z'BytesURLPathTests.test_partialArgumentsc                 C   ó    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   rA   rB   r   r   rK   r   r   r   Útest_nonASCIIBytesó   ó   z$BytesURLPathTests.test_nonASCIIBytesN)	r;   r<   r=   r>   rC   rI   rM   rO   rQ   r   r   r   r   r?   È   s    
r?   c                   @   ó    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   r@   ©Nr#   ©r   rA   Ú
fromStringr   r   r   r   r   rC     rD   zStringURLPathTests.setUpc                 C   rE   )zN
        C{URLPath.fromString} must take a L{str} or L{str} argument.
        Ns   someurl)rG   rH   r   rA   rX   r   r   r   r   Útest_mustBeStr  rJ   z!StringURLPathTests.test_mustBeStrN)r;   r<   r=   r>   rC   rY   r   r   r   r   rT   û   ó    rT   c                   @   rS   )ÚUnicodeURLPathTestsrU   c                 C   r@   rV   rW   r   r   r   r   rC     rD   zUnicodeURLPathTests.setUpc                 C   rP   )zF
        L{URLPath.fromString} can load non-ASCII characters.
        u   http://example.com/Ã¿ zhttp://example.com/%C3%BF%00N)r   rA   rX   r   r   rK   r   r   r   Útest_nonASCIICharacters  rR   z+UnicodeURLPathTests.test_nonASCIICharactersN)r;   r<   r=   r>   rC   r\   r   r   r   r   r[     rZ   r[   N)
r>   Útwisted.pythonr   Útwisted.trialr   r   ÚTestCaser?   rT   r[   r   r   r   r   Ú<module>   s    <3