Ϫf'dZddlmZddlmZGddZGddeej ZGdd eej ZGd d eej Z y ) z& Tests for L{twisted.python.urlpath}. )urlpath)unittestc\eZdZdZdZdZefdZdZdZ dZ dZ d Z d Z d Zd Zd Zy)_BaseURLPathTestsz5 Tests for instantiated L{urlpath.URLPath}s. c|j|jjt|j|jjt|j|jjt|j|jj t|j|jj ty)zQ All of the attributes of L{urlpath.URLPath} should be L{bytes}. NassertIsInstancepathschemebytesnetlocqueryfragmentselfs B/usr/lib/python3/dist-packages/twisted/python/test/test_urlpath.pytest_partsAreBytesz$_BaseURLPathTests.test_partsAreBytes dii..6 dii..6 diinne4 diioou5 dii00%8cr|jt|jjty)zQ Calling C{str()} with a L{URLPath} will always return a L{str}. N) assertEqualtyper __str__strrs rtest_strReturnsStrz$_BaseURLPathTests.test_strReturnsStrs& dii//12C8rc\|d|j_|jt|jd|d|j_|jt|jd|d|j_|jt|jd|d|j_|jt|jd|d |j_|jt|jd y ) 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#footerzanother.example.invalidzz<_BaseURLPathTests.test_mutabilityWithBytes..Jsqxx/@rN)r rs rtest_mutabilityWithBytesz*_BaseURLPathTests.test_mutabilityWithBytesFs $$%@Arc|j|jjt|j|jjt|j|jjt|j|jj t|j|jj ty)z< A created L{URLPath} has bytes attributes. Nrrs rtest_allAttributesAreBytesz,_BaseURLPathTests.test_allAttributesAreBytesLrrcN|jt|jdy)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)rrr rs rtest_stringConversionz'_BaseURLPathTests.test_stringConversionVs   NM rc^|jt|jjdd|jt|jjdjdd|jt|jjdddy) z Calling C{str()} with a C{URLPath.child()} will return a URL which is the child of the URL it was instantiated with. shelloz http://example.com/foo/bar/hellorz!http://example.com/foo/bar/hello/T keepQueryz.http://example.com/foo/bar/hello?yes=no&no=yesN)rrr childrs rtest_childStringz"_BaseURLPathTests.test_childString_s   ) *,N    )//4 5 /    D9 : < rc^|jt|jjdd|jt|jjddd|jt|jj djddy) z Calling C{str()} with a C{URLPath.sibling()} will return a URL which is the sibling of the URL it was instantiated with. bazzhttp://example.com/foo/bazTr.z(http://example.com/foo/baz?yes=no&no=yesrzhttp://example.com/foo/bar/bazN)rrr siblingr0rs rtest_siblingStringz$_BaseURLPathTests.test_siblingStringps TYY..v679UV   !!&D!9 : 6    $,,V4 57W rc|jt|jjd|jt|jjdd|jt|jj djd|jt|jj djd|jt|jjjjjjdy) z Calling C{str()} with a C{URLPath.parent()} will return a URL which is the parent of the URL it was instantiated with. zhttp://example.com/Tr.z!http://example.com/?yes=no&no=yesrhttp://example.com/foo/r3N)rrr parentr0rs rtest_parentStringz#_BaseURLPathTests.test_parentStrings TYY--/02GH     4 0 13V  TYY__S188:;=VW   '..0 13L      "))+224;;=DDF G ! rcX|jt|jjd|jt|jjdd|jt|jj djdy)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. r7Tr.z%http://example.com/foo/?yes=no&no=yesrzhttp://example.com/foo/bar/N)rrr herer0rs rtest_hereStringz!_BaseURLPathTests.test_hereStrings~ TYY^^-.0IJ   . /1X    $))+ ,.K rc|jt|jjdj ddy)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#shttp://example.com/hello/worldN)rrr clickr$rs rtest_doubleSlashz"_BaseURLPathTests.test_doubleSlashs5   0 1 8 8 A - rcn|j|jjdjgd|j|jjdjdgd|j|jjdjdgdy) zL L{urlpath.URLPath.pathList} returns a L{list} of L{bytes}. %00%01%02)rfoobarrAF)copyT)unquote)rrBrCsN)rr r0pathListrs r test_pathListz_BaseURLPathTests.test_pathLists  IIOOL ) 2 2 4 /   IIOOL ) 2 2 2 > /   IIOOL ) 2 24 2 @ 2 rN)__name__ __module__ __qualname____doc__rrrr r'r)r,r1r5r9r<r?rGrrrr sJ99 25" HB 9  " & (     rrc.eZdZdZdZdZdZdZdZy)BytesURLPathTestszL Tests for interacting with a L{URLPath} created with C{fromBytes}. cLtjjd|_y)Ns/http://example.com/foo/bar?yes=no&no=yes#footer)rURLPath fromBytesr rs rsetUpzBytesURLPathTests.setUpsOO-- >  rc(|jt5tjj dddd|jt5tjj ddddy#1swYGxYw#1swYyxYw)zE L{URLPath.fromBytes} must take a L{bytes} argument. Nsomeurl) assertRaises ValueErrorrrPrQrs rtest_mustBeBytesz"BytesURLPathTests.test_mustBeBytessu  z * , OO % %d + ,  z * 1 OO % %i 0 1 1 , , 1 1 A< B<BBcbtj}|jt|dy)zp An instantiation with no arguments creates a usable L{URLPath} with default arguments. zhttp://localhost/N)rrPrrrurls rtest_withoutArgumentsz'BytesURLPathTests.test_withoutArgumentss% oo S#67rctjjd}|j|jd|j|j d|j|j d|j|jd|j|jd|jt|dy)z Leaving some optional arguments unfilled makes a L{URLPath} with those optional arguments filled with defaults. shttp://google.comshttps google.com/rzhttp://google.com/N) rrPrQrr r r rrrrZs rtest_partialArgumentsz'BytesURLPathTests.test_partialArgumentssoo''(<= W- ]3 4( s+ C( S#78rcxtjjd}|jt |dy)zW L{URLPath.fromBytes} can interpret non-ASCII bytes as percent-encoded shttp://example.com/zhttp://example.com/%FF%00N)rrPrQrrrZs rtest_nonASCIIBytesz$BytesURLPathTests.test_nonASCIIBytess.oo''(FG S#>?rN) rHrIrJrKrRrWr\r_rarLrrrNrNs! 18 9@rrNceZdZdZdZdZy)StringURLPathTestsg Tests for interacting with a L{URLPath} created with C{fromString} and a L{str} argument. cLtjjd|_yNr+rrP fromStringr rs rrRzStringURLPathTests.setUpOO.. =  rc(|jt5tjj dddd|jt5tjj ddddy#1swYGxYw#1swYyxYw)zN C{URLPath.fromString} must take a L{str} or L{str} argument. Nssomeurl)rUrVrrPrhrs rtest_mustBeStrz!StringURLPathTests.test_mustBeStrsu  z * - OO & &t , -  z * 3 OO & &z 2 3 3 - - 3 3rXN)rHrIrJrKrRrkrLrrrcrcs  3rrcceZdZdZdZdZy)UnicodeURLPathTestsrdcLtjjd|_yrfrgrs rrRzUnicodeURLPathTests.setUprircxtjjd}|jt |dy)zF L{URLPath.fromString} can load non-ASCII characters. uhttp://example.com/ÿzhttp://example.com/%C3%BF%00N)rrPrhrrrZs rtest_nonASCIICharactersz+UnicodeURLPathTests.test_nonASCIICharacterss.oo(()FG S#ABrN)rHrIrJrKrRrprLrrrmrms  CrrmN) rKtwisted.pythonr twisted.trialrrTestCaserNrcrmrLrrrtsc #"x x v0@)8+<+<0@f3*H,=,=3,C+X->->Cr