a zeV@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dddZ Gd d d Z Gd d d e ejZGd dde ZGdddejZedkredS)z3 Tests common to genericpath, ntpath and posixpath N)support)assert_python_ok)FakePathfoocCs:t|dd}||Wdn1s,0YdS)Nxbr)openwrite)filenamedatafpr I/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_genericpath.py create_filesrc@seZdZgdZgZddZddZddZdd Zd d Z e e e d d ddZddZddZddZddZejddZddZddZddZejd d!Zd"d#Zd$d%Zd&S)' GenericTest) commonprefixgetsizegetatimegetctimegetmtimeexistsisdirisfilec Csd|j|jD]R}|t4t|j||d|jj|Wdq 1sT0Yq dS)Nz!{}.{}() did not raise a TypeError) common_attributes attributes assertRaises TypeErrorgetattr pathmoduleZfailformat__name__)selfattrr r r test_no_arguments  zGenericTest.test_no_argumentc Cs|jj}||gd||ddgd||ddgd||ddgd||ddgd ||d d gd ||d d gd ||d dgd||ddgd||ddgd||ddgd||ddgd||ddgdgd}|D]t}|D]h}|||g}||||||||krt|}||||d|||dqqdS)Nz/home/swenson/spamz/home/swen/spamz /home/swenz/home/swen/eggsz /home/swen/zhome:swenson:spamzhome:swen:spamz home:swenz:home:swen:spamz:home:swen:eggsz :home:swen:s/home/swenson/spams/home/swen/spams /home/swens/home/swen/eggss /home/swen/shome:swenson:spamshome:swen:spams home:swens:home:swen:spams:home:swen:eggss :home:swen:) r#abcZXbcdZXbZXYZabcdZaXcZabdabZaXZabcX)rr assertEqual assertTrue startswithlenZassertNotEqual)r rZtestlists1s2pnr r r test_commonprefix s|              zGenericTest.test_commonprefixcCs^tj}|tj|t|d||j|dt |t|d||j|ddS)NsHellos Hello World! ) rTESTFN addCleanupunlinkrr'rrosremove)r r r r r test_getsizecs   zGenericTest.test_getsizecCstj}|tj|t|dt|dd}|dWdn1sJ0Yt|dd}|}Wdn1s~0Y||d| |j ||j |dS)Nrr%rbarrbsfoobar) rr2r3r4rrrreadr'ZassertLessEqualrrr)r r fr r r r test_filetimens (&   zGenericTest.test_filetimecCsntj}t|}|tj|||j|d||j|dt |||j|d||j|d||j|dd||j|dd||j|dd||j|dd|jt urj||j |d||j |d||j |dd||j |dd||j |dd||j |dddS)NFT) rr2r5fsencoder3r4assertIsrrr genericpathlexistsr r Z bfilenamer r r test_existss&  zGenericTest.test_existspipezrequires os.pipe()c Csdt\}}z*||j|Wt|t|nt|t|0||j|dSN)r5rGr(rrclose assertFalse)r rwr r r test_exists_fds    zGenericTest.test_exists_fdc Cs6tj}t|}||j|d||j|d||j|dd||j|dd||j|dd||j|ddz>t|||j|d||j|dWt|n t|0z@t |||j|d||j|dWt |n t |0dSNFr=r>r?r@T) rr2r5rArBrrrr4mkdirrmdirrEr r r test_isdirs$  zGenericTest.test_isdirc Cs6tj}t|}||j|d||j|d||j|dd||j|dd||j|dd||j|ddz>t|||j|d||j|dWt|n t|0z@t |||j|d||j|dWt |n t |0dSrN) rr2r5rArBrrrr4rOrPrEr r r test_isfiles$  zGenericTest.test_isfilecCsxtj}tjd}|tj||tj|t|||j||t|||j||| t |jjdSN2) rr2r3r4rr(rsamefilerJrr)r Zfile1Zfile2r r r test_samefiles zGenericTest.test_samefilecCs|tj}tjd}|tj||tj|t||||||j||t |t|| |j||dSrS) rr2r3r4rr(rrUr5r6rJr functest_fn1test_fn2r r r _test_samefile_on_link_funcs   z'GenericTest._test_samefile_on_link_funccCs|tjdSrH)r[r5symlinkr r r r test_samefile_on_symlinksz$GenericTest.test_samefile_on_symlinkc CsHz|tjWn2tyB}z|d|WYd}~n d}~00dSNz os.link(): %s)r[r5linkPermissionErrorskipTestr er r r test_samefile_on_linksz!GenericTest.test_samefile_on_linkcCstj}tjd}|tj||tj|t|t|}||j |t|t|t|}| |j ||| t |jj dSrS) rr2r3r4rr5statr(rsamestatrJrr)r rYrZZstat1Zstat2r r r test_samestats   zGenericTest.test_samestatcCstjd}tjd}|tj||tj|t||||||jt |t |t |t|| |jt |t |dS)N1rT) rr2r3r4rr(rrgr5rfr6rJrWr r r _test_samestat_on_link_funcs    z'GenericTest._test_samestat_on_link_funccCs|tjdSrH)rjr5r\r]r r r test_samestat_on_symlinksz$GenericTest.test_samestat_on_symlinkc CsHz|tjWn2tyB}z|d|WYd}~n d}~00dSr_)rjr5r`rarbrcr r r test_samestat_on_link"sz!GenericTest.test_samestat_on_linkc Cstj}|tj|t|t|dd`}|}t|dd,}|}||j ||Wdn1sp0YWdn1s0YdS)Nr9r) rr2r3r4rrfilenor(r sameopenfile)r r fp1fd1fp2fd2r r r test_sameopenfile(szGenericTest.test_sameopenfileN)r __module__ __qualname__rrr"r/r7r<rFunittest skipUnlesshasattrr5rMrQrRrVr[rZskip_unless_symlinkr^rerhrjrkrlrsr r r r rs,C    rc@seZdZeZddZdS)TestGenericTestc CsXtjD]J}|dkrqt|j|}|j|d|dvr\|d|d|d|dn|ttf|dWdn1s0Y|ttf|dWdn1s0Y| t d|dWdn1s0Y| t d|dWdn1s(0YWdq1sH0YqdS) Nr)r!)rrru /tmpabcdss /tmpabcdsz /tmpabcdss /tmpabcdsz embedded null) rrrrZsubTestrOSErrorUnicodeEncodeErrorUnicodeDecodeErrorassertRaisesRegex ValueError)r r!rXr r r test_invalid_paths:s$   &&&z"TestGenericTest.test_invalid_pathsN)rrtrurCrrr r r r ry4sryc@seZdZejgdZddZddZddZe e j dd d Z d d Z d dZddZddZddZddZddZddZdS) CommonTest)curdirpardirextsepseppathsepdefpathaltsepdevnullnormcase splitdrive expandvarsnormpathabspathjoinsplitsplitextisabsbasenamedirnamerDislinkismount expanduserrrealpathcCs||jj}dD]}||}||||q ||dd||ddddddgtdddhfD]}|t||qddS)N)z FoO/./BaRs FoO/./BaRr#Trg@o)rrr' bytearrayrr)r rr-pathr r r test_normcase^szCommonTest.test_normcasecCsl|jj}||dd||dd||dd||dd||d d ||d d dS) N/foo/bar)r#rfoo:bar)r#r:foo:bar)r#r/foo/bar)rrfoo:bar)rr:foo:bar)rr)rrr')r rr r r test_splitdrivelszCommonTest.test_splitdrivecCs|jj}t}|d|d<d|d<d|d<||dd||dd||d d ||d d ||d d ||d d ||dd||dd||dd||dd ||dd||dd||dd||dd||dd||dd||dd||dd||dd||d d!||d"d||d#d#Wdn1s0YdS)$NZbarfooZbaz1z{fooZbaz2z{foo}z$foo barzbar barz ${foo}barZbarbarz $[foo]barz$bar barz$?barz$foo}barzbar}barz${fooz${{foo}}zbaz1}z$foo$fooz$bar$barrs$foo barsbar bars ${foo}barsbarbars $[foo]bars$bar bars$?bars$foo}barsbar}bars${foos${{foo}}sbaz1}s$foo$foos$bar$bar)rrrEnvironmentVarGuardclearr')r renvr r r test_expandvarsws8 zCommonTest.test_expandvarszneed support.FS_NONASCIIcsNjjfdd}t}|tj}||d<d|||<||||dd||dd||d |d ||d |d ||d d ||t|t||dtd||dtd||td |td ||td |td ||dtd |Wdn1s@0YdS)Ncs||dSrH)r')valueZexpectedrr r r checksz2CommonTest.test_expandvars_nonascii..checkZspamZhamz $spam barz%s barz ${spam}barz%sbarz${%s}barzham%sbarz $bar%s barz $spam}barz%s}bars $spam bars ${spam}bars $spam}bar)rrrrr FS_NONASCIIr5rA)r rrZnonasciir rr test_expandvars_nonasciis.     z#CommonTest.test_expandvars_nonasciicCs|d|jdt0tdt|d|jdWdn1sR0Ytjdkrjdnd}tDtdtdd|ddfD]}| |j|t qWdn1s0YdS) Nrignorerwin32rsfs/foosC:\) assertInrrwarningscatch_warnings simplefilterDeprecationWarningsysplatformassertIsInstancebytes)r Zundecodable_pathrr r r test_abspaths  2  zCommonTest.test_abspathcCs`|d|jdt0tdt|d|jdWdn1sR0YdS)Nrrr)rrrrrrrr]r r r test_realpaths  zCommonTest.test_realpathcCs"dD]}||j|tqdS)N)r#./\z///foo/.//bar//)rrrstr)r rr r r test_normpath_issue5827sz"CommonTest.test_normpath_issue5827c Cs|jj}dD]}|||tq d}zt|WnttfyJYnF0t |*dD]}|||tq\Wdn1s0YdS)N)r#Zfuuufùùz/fuuzU:\uçwð) rrrrr5rAAttributeErrorr{rtemp_cwd)r rrZunicwdr r r test_abspath_issue3426s z!CommonTest.test_abspath_issue3426c Cstjrtjdvrtj}ntjr&tj}n |dtNtdt t || Wdn1sn0YWdn1s0YdS)N)rdarwinzneed support.TESTFN_NONASCIIr) rZTESTFN_UNDECODABLErrZTESTFN_NONASCIIrbrrrrrr)r namer r r test_nonascii_abspaths    z CommonTest.test_nonascii_abspathc Cstjdtfddd}|t||jddWdn1sJ0Y|t||jddWdn1s0Y|td|jddWdn1s0Y|td|jddWdn1s0Y|td|jdWdn1s20Y|td |jgWdn1sl0Y|td &|jtd td Wdn1s0YWdn1s0YdS) Nr#Tquiet.Can't mix strings and bytes in path componentsbytesrint*listrrr8)rcheck_warnings BytesWarningr}rrrrr errmsgr r r test_join_errorss ,,,,,,zCommonTest.test_join_errorsc Csntjdttffdd@d}|t||jddWdn1sN0Y|t||jddWdn1s0Y|td|jddWdn1s0Y|td|jddWdn1s0Y|td &|jtd td Wdn1s@0YWdn1s`0YdS) Nr#Trrrrrrrrr8) rrrrr}rrrelpathrrr r r test_relpath_errorss ,,,,zCommonTest.test_relpath_errorscCstddd|jjdS)Nz-Sz-czimport )rrrr]r r r test_importszCommonTest.test_importN)rrtrurrrrrrvrwrrrrrrrrrrrr r r r rSs    rc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS) PathLikeTestscCs4tj|_ttj|_|tj|jt|jddS)Nstest_genericpath.PathLikeTests)rr2 file_namer file_pathr3r4rr]r r r setUps zPathLikeTests.setUpcCs|||j||jdSrH)r'rr)r rXr r r assertPathEqualszPathLikeTests.assertPathEqualcCs|tjjdSrH)rr5rrr]r r r test_path_exists!szPathLikeTests.test_path_existscCs|tjjdSrH)rr5rrr]r r r test_path_isfile$szPathLikeTests.test_path_isfilecCs|tjjdSrH)rr5rrr]r r r test_path_isdir'szPathLikeTests.test_path_isdircCs"|tj|j|jg|jdSrH)r'r5rrrrr]r r r test_path_commonprefix*sz$PathLikeTests.test_path_commonprefixcCs|tjjdSrH)rr5rrr]r r r test_path_getsize.szPathLikeTests.test_path_getsizecCs|tjjdSrH)rr5rrr]r r r test_path_getmtime1sz PathLikeTests.test_path_getmtimecCs|tjjdSrH)rr5rrr]r r r test_path_getctime4sz PathLikeTests.test_path_getctimecCs|tj|j|jdSrH)r(r5rrUrrr]r r r test_path_samefile7sz PathLikeTests.test_path_samefileN) rrtrurrrrrrrrrrr r r r rsr__main__)r)__doc__rCr5rrvrtestrZtest.support.script_helperrZ test.supportrrrZTestCaseryrrrmainr r r r s$    "D%