a zet@sddlZddlZddlZddlmZmZmZmZddlmZm Z ddl m Z ddlm Z z ddl Z WneyzdZ Yn0eejZddZdd ZGd d d ejZGd d d e jejZGdddejZedkredS)N)realpathabspathdirnamebasename)supporttest_genericpath)FakePath)mockcCs"dtv}d}|t||g|S)z On Windows, posixpath.abspath still returns paths with backslashes instead of posix forward slashes. If this is the case, several tests fail, so skip them. \z'ABSTFN is not a posix path - tests fail)ABSTFNunittestskip)testZfound_backslashmsgrG/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_posixpath.py!skip_if_ABSTFN_contains_backslashsrcCs&zt|Wnty Yn0dSN)osrmdirOSError)rrrr safe_rmdirs rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZeedddZeedudddZeedudd d!Zd"d#Zd$d%Zd&d'Zd(d)Zed*d+Zed,d-Zeee d.d/ed0d1Z!eee d.d/ed2d3Z"eee d.d/ed4d5Z#eee d.d/ed6d7Z$eee d.d/ed8d9Z%eee d.d/ed:d;Z&eee d.d/edd?Z(d@dAZ)dBdCZ*dDdEZ+dS)F PosixPathTestcCs |dSr)tearDownselfrrrsetUp&szPosixPathTest.setUpcCs,dD]"}ttj|ttj|qdS)N)12)runlinkTESTFNr)rsuffixrrrr)szPosixPathTest.tearDowncCs|tddddd|tdddd|tddd d |td d d dd|td d dd|tdddddS)N/foobarz/barZbazz/bar/bazz /foo/bar/bazz/foo/zbar/zbaz/z /foo/bar/baz//foobars/barsbazs/bar/bazs /foo/bar/bazs/foo/sbar/sbaz/s /foo/bar/baz/) assertEqual posixpathjoinrrrr test_join.s zPosixPathTest.test_joincCs|tdd|tdd|tdd|tdd|td d |td d |td d|tdd|tdd|tdddS)N/foo/bar)r#r$/)r,rfoo)rr-////foo)////r- //foo//bar)//foor$/foo/bar)r%r&/)r3foo)r4r5////foo)////r5 //foo//bar)//foor&)r'r(splitrrrr test_split<szPosixPathTest.test_splitcCs|t|||f|td|d||f|td|d||f|td|d||f|td|d||f|t|d||ddft|d}t|d}t|d}|t|||f|td|d||f|td|d||f|td |d ||f|td |d ||f|t|d||dd fdS) Nr,zabc/zabc.def/z /abc.def/rASCIIr3sabc/sabc.def/s /abc.def/r4)r'r(splitextbytes)rpathfilenameextrrr splitextTestIsB          zPosixPathTest.splitextTestcCs|ddd|ddd|ddd|dd d |d d d |d d d |ddd |ddd|ddd |ddd |ddd |d d d dS)Nzfoo.barr-z.barz foo.boo.barzfoo.boozfoo.boo.biff.barz foo.boo.biffz.csh.rcz.cshz.rcZnodotsrz.cshrcz ...manydotsz...manydots.extz.ext...z........)rBrrrr test_splitexteszPosixPathTest.test_splitextcCs|tdd|tdd|tdd|tdd|tdd|tdd|td d|td d|td d|td ddS) NrFr,Tr#r+zfoo/barr4r3r%r2sfoo/bar)assertIsr(isabsrrrr test_isabssszPosixPathTest.test_isabscCs|tdd|tdd|tdd|tdd|tdd|tdd |td d |td d |td d |tdd dS)Nr+r$r,rr-r.r0r2r&r3r4r5r6r8)r'r(rrrrr test_basenameszPosixPathTest.test_basenamecCs|tdd|tdd|tdd|tdd|tdd |td d |td d |td d|tdd|tdddS)Nr+r#r,r-rr.r/r0r1r2r%r3r5r4r6r7r8r9)r'r(rrrrr test_dirnameszPosixPathTest.test_dirnamecCs|ttjdd|ttjddttjdd}|dWdn1s`0Y|ttjddtrt tjdtjd|ttjddt tjd|ttjdd|t tjdd|ttjdd|ttjdd|tt tjdd|ttjd d|tt tjd ddS) NrFrwbr5Tu)rFr(islinkrr!lexistsopenwrite can_symlinkrsymlinkremoveexistsfsencode)rfrrr test_islinks ( zPosixPathTest.test_islinkcCs(|tdd|tdddS)Nr,Tr3)rFr(ismountrrrr test_ismountszPosixPathTest.test_ismountcCs|ttdz(tt|ttdWttn tt0|tdd|tdd|tdd|tdddS)NFu/s/z/s/)rFr(rZr rmkdirrrrrrtest_ismount_non_existents z'PosixPathTest.test_ismount_non_existentzTest requires symlink supportc Cs>z,tdt|ttdWttn tt0dS)Nr,F)rrTr rFr(rZr rrrrtest_ismount_symlinkss z#PosixPathTest.test_ismount_symlinksNzTest requires posix modulecCs>tj}dd}z"|t_|ttdW|t_n|t_0dS)Nc Ss6d}d}|tkrd}d}td||dddddddf S)Nr)r posix stat_resultr?st_inost_devrrr fake_lstats z?PosixPathTest.test_ismount_different_device..fake_lstatTrlstatrFr(rZr rZ save_lstatrerrrtest_ismount_different_devices z+PosixPathTest.test_ismount_different_devicecCs>tj}dd}z"|t_|ttdW|t_n|t_0dS)Nc SsPd}d}|tr"|tkr"td|tkr2d}d}td||dddddddf S)Nrz!Fake [Errno 13] Permission deniedr_) startswithr rr`rarbrrrreszEPosixPathTest.test_ismount_directory_not_readable..fake_lstatTrfrhrrr#test_ismount_directory_not_readables  z1PosixPathTest.test_ismount_directory_not_readablecCs(|tdd|tdddS)Nr-r5)r'r( expanduserrrrrtest_expanduserszPosixPathTest.test_expanduserc Cst}d|d<|tddd|d<|tdddD]n}|j|dN||d<|tdd|tdd|td d WdqB1s0YqBWdn1s0YdS) Nz /home/victorHOME~z /home/victor/)r,r/////)homer,~/z~/foor#)rEnvironmentVarGuardr'r(rlZsubTest)renvrrrrrtest_expanduser_home_envvars z)PosixPathTest.test_expanduser_home_envvarc Cstd}|tdt|tdttddkrt|tddtd|tddtd|tdt|td t|td t|td tt}|d =| t j }| dpd}|td|tjj|d tdbtjj|dtd.dD]}|t||q(Wdn1sX0YWdn1sx0YWdn1s0YdS)Npwdrss~/ror,~r3z~root/z~foo/s~root/s~foo/rngetpwuid)Z side_effectgetpwnam)roz~/.localz ~vstinner/)r import_moduleZassertIsInstancer(rlstrr>r'rtryrgetuidpw_dirrstripr ZpatchobjectKeyError)rrwrurrr?rrrtest_expanduser_pwds4    z!PosixPathTest.test_expanduser_pwdcCs|tdd|tdd|tdd|tdd|tdd|tdd |td d|td d |td d |tdd|tdd |tdd|tdd|tdddS)NrrCr,rprqz///foo/.//bar//r+z///foo/.//bar//.//..//.//bazz/foo/bazz///..//./foo/.//barr4.r3s//s///s///foo/.//bar//r2s///foo/.//bar//.//..//.//bazs/foo/bazs///..//./foo/.//bar)r'r(normpathrrrr test_normpath.s(   zPosixPathTest.test_normpathcCs|tdt|tdt|tddgdt|tdt|tdt|tddgdtdS)NrCz./.r,drs./.r3)r'rrgetcwdr)getcwdbrrrrtest_realpath_curdirBs  z"PosixPathTest.test_realpath_curdircCs|tdtt|tdttt|tddgdd|tdtt|tdttt|tddgdddS)NrDz../..r,rs..s../..r3)r'rrrrr)rrrrrtest_realpath_pardirLs z"PosixPathTest.test_realpath_pardirrTzMissing symlink implementationc CsDz2ttdt|tttdWttn tt0dSNr)rrTr r'rrr rrrrtest_realpath_basicVsz!PosixPathTest.test_realpath_basicc CsJz8tttdt|tttdWttn tt0dSr) rrTr(relpathr r'rrr rrrrtest_realpath_relativeasz$PosixPathTest.test_realpath_relativec Csz(ttt|tttttdtdttdtd|ttdtd|ttdtd|ttdtd|ttdtt|ttdttdttdtd|ttd ttdtd|ttd ttdtdtttd td |ttd td td tttd ttdtd|ttdtdttt$|ttttWdn1s0YWt tt tdt tdt tdt tdt td nRt tt tdt tdt tdt tdt td 0dS)Nrrz1/xz1/..z1/../x/xxyz1/../a/ba../r,c) rrTr r'rrrr change_cwdr rrrrtest_realpath_symlink_loopsksR 6  z)PosixPathTest.test_realpath_symlink_loopsc Cszntttdtttdtdtd|ttdtWttdttdt tn&ttdttdt t0dS)Nrz/selfzself/self/selfz/link) rr\r rTrr'rrr rrrrr(test_realpath_repeated_indirect_symlinkss  z6PosixPathTest.test_realpath_repeated_indirect_symlinksc Csd}zttt|D],}tdd|gdtd|dqtdtd|ttd|tt t$|td|tWdn1s0YWt|dD]}t td|qt tn.t|dD]}t td|qt t0dS)N r,z%dz/%dr_rCz/0) rr\r rangerTr)r'rrrr r)rdepthirrrtest_realpath_deep_recursions  * 4 z*PosixPathTest.test_realpath_deep_recursionc Cszttttdttdtdttd$|tdtdWdn1sf0YWttdt tdt tn$ttdt tdt t0dS)Nz/y/krz/y/a) rr\r rTrrr'rr rrrrrtest_realpath_resolve_parentss 4   z+PosixPathTest.test_realpath_resolve_parentsc Cszttttdttdttdtd|ttdtdttt,|tt tdtdWdn1s0YWt tdt tdt tdt tn0t tdt tdt tdt t0dS)Nrz/k/yz/link-yz /link-y/..) rr\r rTr'rrrrrr rrrrr(test_realpath_resolve_before_normalizings$  $     z6PosixPathTest.test_realpath_resolve_before_normalizingc CszttttdtttdtttDtt}|t |dt|t |dtdWdn1s0YWt tdt tdt tn$t tdt tdt t0dS)Nrlinkzlink/k) rr\r rTrrrrr'rr r)rbaserrrtest_realpath_resolve_firsts 8   z)PosixPathTest.test_realpath_resolve_firstcCstjdd}t_ztjtd}|ttjd|tdd|tt dd|tdd|tdd|tddd |d |tdd d |d |tdd d|tddd|tddd|tddd|tddd|tddd|tddd|tddd|tddd|td d d|td d dW|t_n|t_0dS)NcSsdS)Nz/home/user/barrrrrrr4z,PosixPathTest.test_relpath..rrrz../a/bz../brz/az../cz/a/bzb/cz../../arCz /foo/bar/batz/x/y/zz../../../foo/bar/batr+Zbatr,z foo/bar/batz../../..rz../foo/bar/batz ../../../x) rrr?r: assertRaises ValueErrorr(rr'r)rZ real_getcwdcurdirrrr test_relpaths0 zPosixPathTest.test_relpathcCstjdd}t_ztjtd}|ttjd|tdd|tt dd|tdd|tdd|tddd |d |tdd d |d |tdd d|tddd|tddd|tddd|tddd|tddd|tddd|tddd|tddd|td d d|td d d|t tjdd|t tjddW|t_n|t_0dS)NcSsdS)Ns/home/user/barrrrrrrr4z2PosixPathTest.test_relpath_bytes..rr4asa/bs../a/bs../bs../s/as../cs/a/bsb/cs../../ars /foo/bar/bats/x/y/zs../../../foo/bar/batr2sbatr3s foo/bar/bats../../..s/xs../foo/bar/bats ../../../xsbytesr|) rrr?r:rrr(rr'r TypeError)rZ real_getcwdbrrrrtest_relpath_bytess8  z PosixPathTest.test_relpath_bytescsfdd}fdd}ttjg|tddg|tddg|dgd|ddgd|ddgd|ddgd|d d gd|d d gd|d dgd |ddgd |ddgd|ddgd|ddgd|ddgd|dgd|ddgd|ddgd|ddgd|ddgd|ddgd|gdd|gdd|dgd|dd gd|tdd!gttjd"dgttjd"d#gttjd$dgttjdd%gttjdd&gttjd'd%gdS)(Ncs8t||tdd|Dt|dS)NcSsg|]}t|qSrrrW.0prrr 8r4z@PosixPathTest.test_commonpath..check..)r'r( commonpathrrW)pathsZexpectedrrrcheck6sz,PosixPathTest.test_commonpath..checkcs.|tj||tjdd|DdS)NcSsg|]}t|qSrrrrrrr=r4zFPosixPathTest.test_commonpath..check_error..)rr(r)excrrrr check_error:s  z2PosixPathTest.test_commonpath..check_errorz/usrZusrz /usr/localz /usr/local/z /usr//localz //usr/localz /usr/./localz /./usr/localr,z/devz /usr/lib/z/usr/lib/python3z/usr/libz /usr/lib64/z /usr/lib64Zspamalotrand/jamand/spamandzand//jamz and/spam//z and/./jamz ./and/spam)rrr)rrrz spam/alotz /spam/alots /usr/lib/zusr/lib/python3susr/lib/s/usr/lib/python3susr/lib/python3zusr/lib/)rrr(rr)rrrrrrtest_commonpath5s\           zPosixPathTest.test_commonpath),__name__ __module__ __qualname__rrr*r;rBrErHrIrJrYr[r]r Z skipUnlessrrSr^ZskipIfr`rirkrmrvrrrrrhasattrrrrrrrrrrrrrrrrrr$s        '       '         rc@seZdZeZgdZdS)PosixCommonTest)rsamefile sameopenfilesamestatN)rrrr(Z pathmoduleZ attributesrrrrrlsrc@seZdZeZddZddZddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)S)* PathLikeTestscCs`tj|_ttj|_|tj|jt|jdd}|dWdn1sR0YdS)Nxbrstest_posixpath.PathLikeTests) rr! file_namer file_pathZ addCleanupr rQrR)rfilerrrrus  zPathLikeTests.setUpcCs|||j||jdSr)r'rr)rfuncrrrassertPathEqual|szPathLikeTests.assertPathEqualcCs||jjdSr)rr?normcaserrrrtest_path_normcasesz PathLikeTests.test_path_normcasecCs||jjdSr)rr?rGrrrrtest_path_isabsszPathLikeTests.test_path_isabscCs,||jdtdd|jddddS)Nrbr)r'r?r)rrrrrtest_path_joinszPathLikeTests.test_path_joincCs||jjdSr)rr?r:rrrrtest_path_splitszPathLikeTests.test_path_splitcCs||jjdSr)rr?r=rrrrtest_path_splitextsz PathLikeTests.test_path_splitextcCs||jjdSr)rr? splitdriverrrrtest_path_splitdrivesz"PathLikeTests.test_path_splitdrivecCs||jjdSr)rr?rrrrrtest_path_basenamesz PathLikeTests.test_path_basenamecCs||jjdSr)rr?rrrrrtest_path_dirnameszPathLikeTests.test_path_dirnamecCs||jjdSr)rr?rOrrrrtest_path_islinkszPathLikeTests.test_path_islinkcCs||jjdSr)rr?rPrrrrtest_path_lexistsszPathLikeTests.test_path_lexistscCs||jjdSr)rr?rZrrrrtest_path_ismountszPathLikeTests.test_path_ismountcCs||jjdSr)rr?rlrrrrtest_path_expandusersz"PathLikeTests.test_path_expandusercCs||jjdSr)rr? expandvarsrrrrtest_path_expandvarssz"PathLikeTests.test_path_expandvarscCs||jjdSr)rr?rrrrrtest_path_normpathsz PathLikeTests.test_path_normpathcCs||jjdSr)rr?rrrrrtest_path_abspathszPathLikeTests.test_path_abspathcCs||jjdSr)rr?rrrrrtest_path_realpathsz PathLikeTests.test_path_realpathcCs||jjdSr)rr?rrrrrtest_path_relpathszPathLikeTests.test_path_relpathcCs&|j|j|jg}|||jdSr)r?rrrr')rZ common_pathrrrtest_path_commonpathsz"PathLikeTests.test_path_commonpathN)rrrr(r?rrrrrrrrrrrrrrrrrrrrrrrrrqs*r__main__)rr(r rrrrrrrZ test.supportrr r` ImportErrorr!r rrZTestCaserZ CommonTestrrrmainrrrrs,       LG