a
    zeK                     @   s<  d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
 d dlmZ zd dlZW n eyv   dZY n0 z
e j W n ey   dZY n0 dZzd dlZW n ey   dZY n0 dZdd Zd	d
 Zdd ZG dd dejZG dd deZG dd de
jejZG dd deZedkr8e  dS )    N)
TestFailedFakePath)supporttest_genericpath)TemporaryFileFTc                 C   sn   t jdddj}t jt jt jg|_t j|_|| d d}|sLtdt 	 t 
|}|| ||}|d | S )NZkernel32T)Zuse_last_errorr   z&failed to get short path name 0x{:08X})ctypesZWinDLLZGetShortPathNameWZ	c_wchar_pZc_uint32argtypesZrestypeOSErrorformatZget_last_errorZcreate_unicode_buffer)pathZGSPNZ
result_lenresult r   &/usr/lib/python3.9/test/test_ntpath.py_getshortpathname   s    
r   c                 C   sB   t | tttjfr"tt| S t| dr>t	dd | D S | S )N__iter__c                 s   s   | ]}t t|V  qd S N)ntpathnormcaseosfsdecode.0pr   r   r   	<genexpr>/       z_norm.<locals>.<genexpr>)

isinstancebytesstrr   PathLiker   r   r   hasattrtuple)r   r   r   r   _norm+   s
    
r!   c                 C   s$  |  dd} t| }||krJt|t|krJtdt| t|t|f |  dd} |  dd} |  dd	} |  d
d} |  dd} |  dd} t| d} | ddd} t	
 $ t	dt t| }W d    n1 s0    Y  t|t|kr tdt| t|t|f d S )N\\\z%%s should return: %s but returned: %sz('z(b'z("z(b"z['z[b'z["z[b"z, 'z, b'z, "z, b"latin1asciibackslashreplaceignore)replaceevalr!   r   r   r   fsencodedecodeencodewarningscatch_warningssimplefilterDeprecationWarningrepr)fnZ
wantResultZ	gotResultr   r   r   tester3   s*    
&r3   c                   @   s   e Zd Zdd Zdd ZdS )NtpathTestCasec                 C   s,   ||kst |t |krd S | || d S r   )r!   assertEqual)selfZpath1Zpath2r   r   r   assertPathEqualL   s    zNtpathTestCase.assertPathEqualc                 C   s   |  t|t| d S r   )ZassertInr!   )r6   r   Zpathsetr   r   r   assertPathInQ   s    zNtpathTestCase.assertPathInN)__name__
__module____qualname__r7   r8   r   r   r   r   r4   K   s   r4   c                   @   s  e Z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ejeeddd Zejeeddd Zejeeddd Zejeeddd Zejeeddd Zeeddd Zeedeed d!d" Zd#d$ Zeejd%d&d' Zd(d) Zeed*d+d, Zd-d. Zd/d0 Z d1d2 Z!d3d4 Z"d5d6 Z#eed7d8d9 Z$d:S );
TestNtpathc                 C   sh   t dd t dd t dd t dd t d	d
 t dd t dd t dd t dd t dd d S )Nzntpath.splitext("foo.ext"))foo.extzntpath.splitext("/foo/foo.ext"))z/foo/foor>   zntpath.splitext(".ext"))r>    zntpath.splitext("\foo.ext\foo"))z\foo.ext\foor?   zntpath.splitext("foo.ext\"))zfoo.ext\r?   zntpath.splitext(""))r?   r?   zntpath.splitext("foo.bar.ext"))zfoo.barr>   z!ntpath.splitext("xx/foo.bar.ext"))z
xx/foo.barr>   z!ntpath.splitext("xx\foo.bar.ext"))z
xx\foo.barr>   zntpath.splitext("c:a/b\c.d"))zc:a/b\cz.dr3   r6   r   r   r   test_splitextV   s    








zTestNtpath.test_splitextc                 C   sf   t dd t dd t dd t dd t d	d
 t dd t dd t dd | tdd d S )Nzntpath.splitdrive("c:\foo\bar"))c:\foo\barzntpath.splitdrive("c:/foo/bar"))rC   /foo/barz/ntpath.splitdrive("\\conky\mountpoint\foo\bar"))z\\conky\mountpointrD   z/ntpath.splitdrive("//conky/mountpoint/foo/bar"))z//conky/mountpointrE   z0ntpath.splitdrive("\\\conky\mountpoint\foo\bar"))r?   z\\\conky\mountpoint\foo\barz0ntpath.splitdrive("///conky/mountpoint/foo/bar"))r?   z///conky/mountpoint/foo/barz0ntpath.splitdrive("\\conky\\mountpoint\foo\bar"))r?   z\\conky\\mountpoint\foo\barz0ntpath.splitdrive("//conky//mountpoint/foo/bar"))r?   z//conky//mountpoint/foo/baru   //conky/MOUNTPOİNT/foo/bar)u   //conky/MOUNTPOİNTrE   )r3   r5   r   
splitdriverA   r   r   r   test_splitdriveb   s6    zTestNtpath.test_splitdrivec                 C   s@   t dd t dd t dd t dd t d	d
 t dd d S )Nzntpath.split("c:\foo\bar"))zc:\foobarz*ntpath.split("\\conky\mountpoint\foo\bar"))z\\conky\mountpoint\foorH   zntpath.split("c:\"))c:\r?   z#ntpath.split("\\conky\mountpoint\"))z\\conky\mountpoint\r?   zntpath.split("c:/"))c:/r?   z#ntpath.split("//conky/mountpoint/"))z//conky/mountpoint/r?   r@   rA   r   r   r   
test_splitw   s    


zTestNtpath.test_splitc                 C   s,   t dd t dd t dd t dd d S )Nzntpath.isabs("c:\")   z#ntpath.isabs("\\conky\mountpoint\")zntpath.isabs("\foo")zntpath.isabs("\foo\bar")r@   rA   r   r   r   
test_isabs   s    


zTestNtpath.test_isabsc                 C   s"   t dd t dd t dd d S )Nz>ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])z
/home/swenz;ntpath.commonprefix(["\home\swen\spam", "\home\swen\eggs"])z\home\swen\z;ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])z/home/swen/spamr@   rA   r   r   r   test_commonprefix   s    zTestNtpath.test_commonprefixc                 C   s6  t dd t dd t dd t dd t dd	 t d
d t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t d d t d!d" t d#d$ t d%d& t d'd( t d)d* t d+d, t d-d. t d/d0 t d1d2 t d3d4 t d5d6 t d7d8 t d9d: t d;d< t d=d< t d>d0 t d?d0 t d@d0 t dAd0 t dBd8 t dCd8 t dDd8 t dEdF t dGdH t dIdJ t dKdL dMD ]$}dND ]}t dO||f | qؐqt dPdQ t dRdQ t dSdQ t dTdU t dVdW t dXdY d S )ZNzntpath.join("")r?   zntpath.join("", "", "")zntpath.join("a")azntpath.join("/a")z/azntpath.join("\a")\azntpath.join("a:")za:zntpath.join("a:", "\b")za:\bzntpath.join("a", "\b")z\bzntpath.join("a", "b", "c")za\b\czntpath.join("a\", "b", "c")zntpath.join("a", "b\", "c")zntpath.join("a", "b", "\c")z\czntpath.join("d:\", "\pleep")zd:\pleepzntpath.join("d:\", "a", "b")zd:\a\bzntpath.join('', 'a')z ntpath.join('', '', '', '', 'a')zntpath.join('a', '')za\z ntpath.join('a', '', '', '', '')zntpath.join('a\', '')z!ntpath.join('a\', '', '', '', '')zntpath.join('a/', '')za/zntpath.join('a/b', 'x/y')za/b\x/yzntpath.join('/a/b', 'x/y')z/a/b\x/yzntpath.join('/a/b/', 'x/y')z/a/b/x/yzntpath.join('c:', 'x/y')zc:x/yzntpath.join('c:a/b', 'x/y')z	c:a/b\x/yzntpath.join('c:a/b/', 'x/y')z	c:a/b/x/yzntpath.join('c:/', 'x/y')zc:/x/yzntpath.join('c:/a/b', 'x/y')z
c:/a/b\x/yzntpath.join('c:/a/b/', 'x/y')z
c:/a/b/x/yz&ntpath.join('//computer/share', 'x/y')z//computer/share\x/yz'ntpath.join('//computer/share/', 'x/y')z//computer/share/x/yz*ntpath.join('//computer/share/a/b', 'x/y')z//computer/share/a/b\x/yzntpath.join('a/b', '/x/y')z/x/yzntpath.join('/a/b', '/x/y')zntpath.join('c:', '/x/y')zntpath.join('c:a/b', '/x/y')zntpath.join('c:/', '/x/y')zntpath.join('c:/a/b', '/x/y')z'ntpath.join('//computer/share', '/x/y')z(ntpath.join('//computer/share/', '/x/y')z)ntpath.join('//computer/share/a', '/x/y')zntpath.join('c:', 'C:x/y')zC:x/yzntpath.join('c:a/b', 'C:x/y')z	C:a/b\x/yzntpath.join('c:/', 'C:x/y')zC:/x/yzntpath.join('c:/a/b', 'C:x/y')z
C:/a/b\x/y)
r?   za/bz/a/brC   zc:a/brJ   zc:/a/bz//computer/sharez//computer/share/z//computer/share/a/b)zd:zd:x/yzd:/zd:/x/yz//machine/commonz//machine/common/z//machine/common/x/yzntpath.join(%r, %r)z*ntpath.join('\\computer\share\', 'a', 'b')z\\computer\share\a\bz)ntpath.join('\\computer\share', 'a', 'b')z&ntpath.join('\\computer\share', 'a\b')z*ntpath.join('//computer/share/', 'a', 'b')z//computer/share/a\bz)ntpath.join('//computer/share', 'a', 'b')z//computer/share\a\bz&ntpath.join('//computer/share', 'a/b')z//computer/share\a/br@   )r6   xyr   r   r   	test_join   sn    


















































zTestNtpath.test_joinc                 C   s   t dd t dd t dd t dd t dd t d	d
 t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t d d! t d"d# t d$d% t d&d' d S )(Nz$ntpath.normpath('A//////././//.//B')zA\Bzntpath.normpath('A/./B')zntpath.normpath('A/foo/../B')zntpath.normpath('C:A//B')zC:A\Bzntpath.normpath('D:A/./B')zD:A\Bzntpath.normpath('e:A/foo/../B')ze:A\Bzntpath.normpath('C:///A//B')zC:\A\Bzntpath.normpath('D:///A/./B')zD:\A\Bz"ntpath.normpath('e:///A/foo/../B')ze:\A\Bzntpath.normpath('..')..zntpath.normpath('.').zntpath.normpath('')zntpath.normpath('/')r"   zntpath.normpath('c:/')rI   zntpath.normpath('/../.././..')zntpath.normpath('c:/../../..')zntpath.normpath('../.././..')..\..\..zntpath.normpath('K:../.././..')z
K:..\..\..zntpath.normpath('C:////a/b')zC:\a\bz'ntpath.normpath('//machine/share//a/b')z\\machine\share\a\bzntpath.normpath('\\.\NUL')\\.\NULzntpath.normpath('\\?\D:/XY\Z')z\\?\D:/XY\Zr@   rA   r   r   r   test_normpath   s,    




















zTestNtpath.test_normpathc                 C   sD   t t }td| td| td| td| td| d S )Nzntpath.realpath('.')zntpath.realpath('./.')z&ntpath.realpath('/'.join(['.'] * 100))zntpath.realpath('.\.')z&ntpath.realpath('\'.join(['.'] * 100)))r   normpathr   getcwdr3   r6   expectedr   r   r   test_realpath_curdir   s    



zTestNtpath.test_realpath_curdirc                 C   s~   t t }tdt | tdt t | tdt |d d  tdt t | tdt |d d  d S )Nzntpath.realpath('..')zntpath.realpath('../..')z&ntpath.realpath('/'.join(['..'] * 50))r   r"   zntpath.realpath('..\..')z&ntpath.realpath('\'.join(['..'] * 50)))r   rY   r   rZ   r3   dirnamerF   r[   r   r   r   test_realpath_pardir   s    zTestNtpath.test_realpath_pardirzneed _getfinalpathnamec                 C   s   t tj}t|d  | tj| | tj|d  t	||d  | 
t |d | | 
t t|d t| d S Nwb1)r   abspathr   TESTFNopenclose
addCleanupunlinkr   symlinkr7   realpathr*   r6   ABSTFNr   r   r   test_realpath_basic  s    zTestNtpath.test_realpath_basicc                 C   sj   t tj}t|d  | tj| | tj|d  t	|t 
|d  | t |d | d S r`   )r   rc   r   rd   re   rf   rg   rh   r   ri   relpathr7   rj   rk   r   r   r   test_realpath_relative  s    z!TestNtpath.test_realpath_relativec                 C   st  t tj}t| | tj| t|. td t	d t
dd t
dd t	d t
dd t
dd t
d	d
 t
dd t
dd t
|d d t
dd | t d|d  | t d|d  | t d
|d  | t d|d  | t d|d  | t d|d  | t d|d  | t d|d  | t dt|d  | t dt|d  | t dt|d  | t dt|d  | t dt|d  | t d t|d  | t d!t|d  | t d"t|d  W d    n1 sf0    Y  d S )#NZsubdirrU   	recursiverT   parentr6   missingbrokenz
broken\barZbroken1zself\self\brokenZbroken2z"subdir\parent\subdir\parent\brokenZbroken3z\brokenZbroken4zrecursive\..\brokenZbroken5z\missingz
broken\fooz\missing\fooz\broken\barzbroken1\bazz\broken\bar\bazz\self\self\missingz$\subdir\parent\subdir\parent\missings   brokens
   broken\foos   broken1s   broken1\bazs   broken2s   broken3s   broken4s   broken5)r   rc   r   rd   r   mkdirrg   rmtree
change_cwdchdirri   r7   rj   r*   rk   r   r   r   test_realpath_broken_symlinks  s    



z(TestNtpath.test_realpath_broken_symlinksc                 C   sN  t tj}| tj| | tj|d  | tj|d  | tj|d  | tj|d  | tj|d  t|| | t 	|| t|d |d  t|d |d  |d |d f}| 
t 	|d | | 
t 	|d | | 
t 	|d dd |D  | t 	|d	 t | | t 	|d
 t |d  t|d |d  | t 	|d t | d |d  | 
t 	|d t | d | tt |d |d  | t 	|d |d  tdt t | d t | d |d  | t 	|d |d  | t 	t || d S )Nrb   2rR   crO   z1\xc                 s   s   | ]}t |d V  qdS )rQ   N)r   join)r   rr   r   r   r   i  r   z9TestNtpath.test_realpath_symlink_loops.<locals>.<genexpr>z1\..z1\..\xz\xrQ   z1\..\a\b..\r"   )r   rc   r   rd   rg   rh   r   ri   r7   rj   r8   r^   basename)r6   rl   r\   r   r   r   test_realpath_symlink_loopsR  sf    z&TestNtpath.test_realpath_symlink_loopsc                 C   s  t tj}| tj|d  | tjd| d  | tj|d  | tj|d  t|d d}|d W d    n1 s0    Y  t	|d |d  td| d d}|d W d    n1 s0    Y  t	d| d |d  | 
t |d |d  | 
t |d d| d  tt |d d	 }| | d W d    n1 sl0    Y  tt |d d	 }| | d W d    n1 s0    Y  | 
t d| d d| d  | 
t d| d d| d  d S )
N3z\\?\z3.Z3linkz3.linkra      0   1rb)r   rc   r   rd   rg   rh   re   writer   ri   r7   rj   r5   read)r6   rl   fr   r   r   test_realpath_symlink_prefix  s6    ((
00

z'TestNtpath.test_realpath_symlink_prefixc                 C   s   t dd d S )Nzntpath.realpath('NUL')rW   r@   rA   r   r   r   test_realpath_nul  s    zTestNtpath.test_realpath_nulzneed _getshortpathnamec                 C   st  t tj}t| t| t| | tj| t 	|d}t| t
|}t 	|d}t 	|d}t|d}|d W d    n1 s0    Y  | |t | t|" | |t d W d    n1 s0    Y  t| " | |t d W d    n1 s(0    Y  t|" | |t d W d    n1 sf0    Y  d S )NZMyVeryLongDirectoryNamezfile.txtra   s   content)r   rc   r   rd   rh   ru   r   rt   rg   r{   r   re   r   r7   rj   rv   lower)r6   rl   Ztest_dir_longZtest_dir_shortZtest_file_longZtest_file_shortr   r   r   r   test_realpath_cwd  s&    



(02zTestNtpath.test_realpath_cwdc                 C   s
  t  }|  d|d< d|d< d|d< tdd tdd	 td
d tdd tdd tdd tdd tdd tdd tdd tdd tdd	 tdd tdd tdd td d! td"d# td$d% td&d' W d    n1 s0    Y  d S )(NrH   r=   Zbaz1z{fooZbaz2z{foo}zntpath.expandvars("foo")zntpath.expandvars("$foo bar")zbar barzntpath.expandvars("${foo}bar")Zbarbarzntpath.expandvars("$[foo]bar")z	$[foo]barzntpath.expandvars("$bar bar")z$bar barzntpath.expandvars("$?bar")z$?barzntpath.expandvars("$foo}bar")zbar}barzntpath.expandvars("${foo")z${foozntpath.expandvars("${{foo}}")zbaz1}zntpath.expandvars("$foo$foo")zntpath.expandvars("$bar$bar")z$bar$barzntpath.expandvars("%foo% bar")zntpath.expandvars("%foo%bar")zntpath.expandvars("%foo%%foo%")z$ntpath.expandvars("%%foo%%foo%foo%")z%foo%foobarzntpath.expandvars("%?bar%")z%?bar%zntpath.expandvars("%foo%%bar")zbar%barz ntpath.expandvars("'%foo%'%bar")z'%foo%'%barzntpath.expandvars("bar'%foo%")z	bar'%foo%)r   EnvironmentVarGuardclearr3   r6   envr   r   r   test_expandvars  s0    


















zTestNtpath.test_expandvarszneed support.FS_NONASCIIc                 C   s   dd }t  }|  t j}||d< d| ||< |dd|  |d| d|  |dd	|  |d
| d|  |dd|  |d| d|  |dd|  |d|d|  |dd	|  |d|d|  W d    n1 s0    Y  d S )Nc                 S   s   t d|  | d S )Nzntpath.expandvars(%r)r@   )valuer\   r   r   r   check  s    z2TestNtpath.test_expandvars_nonascii.<locals>.checkspamZhamz	$spam barz%s barz$%s barz
${spam}barz%sbarz${%s}barzham%sbarz	$spam}barz%s}barz$%s}barz
%spam% barz%{}% barz	ham%s barz	%spam%barz%{}%bar)r   r   r   FS_NONASCIIr
   )r6   r   r   Znonasciir   r   r   test_expandvars_nonascii  s     
z#TestNtpath.test_expandvars_nonasciic                 C   s   t dd t }|  t dd d|d< d|d< t dd	 t d
d |d= t dd t d
d |  d|d< t dd	 t d
d t dd t dd t dd t dd |  d|d< d|d< t dd	 t d
d W d    n1 s0    Y  d S )Nzntpath.expanduser("test")testzntpath.expanduser("~test")z~testz	eric\idleHOMEPATHC:\	HOMEDRIVEzC:\eric\testzntpath.expanduser("~")zC:\eric\idlez	eric\testUSERPROFILEz"ntpath.expanduser("~test\foo\bar")zC:\eric\test\foo\barz"ntpath.expanduser("~test/foo/bar")zC:\eric\test/foo/barzntpath.expanduser("~\foo\bar")zC:\eric\idle\foo\barzntpath.expanduser("~/foo/bar")zC:\eric\idle/foo/barzF:\HOME)r3   r   r   r   r   r   r   r   test_expanduser  s@    









zTestNtpath.test_expanduserzabspath requires 'nt' modulec                 C   s|   t dd ttjR}t d| t d|d  t d|d  t|\}}t d|d	  W d    n1 sn0    Y  d S )
Nzntpath.abspath("C:\")r   zntpath.abspath("")zntpath.abspath(" ")z\ zntpath.abspath("?")z\?zntpath.abspath("/abc/")z\abc)r3   r   temp_cwdrd   r   rF   )r6   cwd_dirdrive_r   r   r   test_abspath  s    

zTestNtpath.test_abspathc                 C   s  t dd t dd t dd t dd ttj>}t|}t dd	| d
  t dd	| d  W d    n1 sx0    Y  t dd t dd t dd t dd t dd t dd t dd t dd t dd t dd t d d t d!d t d"d t d#d d S )$Nzntpath.relpath("a")rO   z#ntpath.relpath(ntpath.abspath("a"))zntpath.relpath("a/b")r}   zntpath.relpath("../a/b")z..\a\bzntpath.relpath("a", "../b")r~   rP   zntpath.relpath("a/b", "../c")z\a\bzntpath.relpath("a", "b/c")z..\..\az*ntpath.relpath("c:/foo/bar/bat", "c:/x/y")z..\..\foo\bar\batz@ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")zntpath.relpath("a", "a")rU   z(ntpath.relpath("/foo/bar/bat", "/x/y/z")z..\..\..\foo\bar\batz*ntpath.relpath("/foo/bar/bat", "/foo/bar")Zbatz#ntpath.relpath("/foo/bar/bat", "/")zfoo\bar\batz#ntpath.relpath("/", "/foo/bar/bat")rV   z$ntpath.relpath("/foo/bar/bat", "/x")z..\foo\bar\batz$ntpath.relpath("/x", "/foo/bar/bat")z
..\..\..\xzntpath.relpath("/", "/")zntpath.relpath("/a", "/a")zntpath.relpath("/a/b", "/a/b")z"ntpath.relpath("c:/foo", "C:/FOO"))r3   r   r   rd   r   r   )r6   r   Z
currentdirr   r   r   test_relpath  s,    




0












zTestNtpath.test_relpathc                    sZ  dd } fdd}  ttjg  |tddg |tddg |tddg |tddg |dgd |ddgd |d	dgd |d	d	gd |d
dgd |ddgd |ddgd |ddgd |ddgd |ddgd |ddgd |d	dgd |ddgd |ddgd |ddgd |tddg |dgd |ddgd |ddgd |ddgd |ddgd |dd gd |g d!d |g d"d |d#d$gd% |dgd |dd&gd |tdd'g   ttjd(dg   ttjd(d)g   ttjd*dg   ttjdd+g   ttjdd,g   ttjdd+g d S )-Nc                 S   s   t d|  dd| d S )Nzntpath.commonpath(%r)r#   r"   )r3   r(   )pathsr\   r   r   r   r   8  s    z)TestNtpath.test_commonpath.<locals>.checkc                    s.     | tj|   | tjdd |D  d S )Nc                 S   s   g | ]}t |qS r   )r   r*   r   r   r   r   
<listcomp>>  r   zCTestNtpath.test_commonpath.<locals>.check_error.<locals>.<listcomp>)assertRaisesr   
commonpath)excr   rA   r   r   check_error;  s    
z/TestNtpath.test_commonpath.<locals>.check_errorzC:\Program FileszProgram FileszC:Program Filesz\Program FileszC:\Program Files\zC:\\Program FileszC:\Program Files\\zC:\.\Program FileszC:\Program Files\.r   zC:\binzC:\Program Files\BarzC:\Program Files\FoozC:\ProjectszC:/Program Files/Barzc:/program files/barzc:\program fileszD:\Program Filesr   alotr?   and\jamand\spamandzand\\jamz
and\spam\\z	and\.\jamz
.\and\spam)r   r   r   )r   r   r   z	C:and\jamz
C:and\spamzC:andz	spam\alotz
\spam\alots   C:\Program FileszProgram Files\Foos   Program Filess   C:\Program Files\Foos   Program Files\Foo)r   
ValueErrorr   r   	TypeError)r6   r   r   r   rA   r   test_commonpath7  s    





zTestNtpath.test_commonpathc              
   C   s   t  }t  }| t| |  | t| |  tjdkr| t	 tdd W d    n1 sz0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nwin32)
r   
assertTruer   sameopenfilefilenoassertFalsesysplatformr   r	   )r6   Ztf1Ztf2r   r   r   test_sameopenfile|  s    
zTestNtpath.test_sameopenfilec                 C   s  |  td |  td |  td |  td |  td |  td |  td |  td |  td	 |  td
 |  td |  td t  }| t| W d    n1 s0    Y  tjdkrttj	\}}t
ttj	8 | t|  | t|  W d    n1 sf0    Y  |  td |  td |  td |  td d S )NrI   r   rJ   zC:/z\\.\c:\z\\.\C:\s   c:\s   C:\s   c:/s   C:/s   \\.\c:\s   \\.\C:\r   z\\localhost\c$z\\localhost\c$\s   \\localhost\c$s   \\localhost\c$\)r   r   ismountr   Ztemp_dirr   r   r   rF   
executablerv   r^   r   upper)r6   dr   r   r   r   r   test_ismount  s.    
.4zTestNtpath.test_ismountc                 C   s   |  | |  d S r   )r5   r   )r6   s1s2r   r   r   assertEqualCI  s    zTestNtpath.assertEqualCIzOS helpers require 'nt' modulec                 C   s  t tj}|t|fD ]6}t |}t|d }t|d }| 	|| qt 
tj\}}| |d | |d t 
tj \}}	| || | |	d tjtjfD ]T}t |}
| |
t | t|
d t | }| |t | t|d qd S )Nr   )nt_getfinalpathnamer   r   r   r*   _getvolumepathnamer   rF   r   Z_getdiskusageexec_prefixZassertGreaterr,   r5   prefixZassertIsInstancer   lenr   )r6   r   r   Zvolume_path
path_driveZvolume_path_driveZcapfreeZb_capZb_freeZ
final_pathZb_final_pathr   r   r   test_nt_helpers  s&    

zTestNtpath.test_nt_helpersN)%r9   r:   r;   rB   rG   rK   rM   rN   rS   rX   r]   r_   r   Zskip_unless_symlinkunittestZ
skipUnlessHAVE_GETFINALPATHNAMErm   ro   rx   r   r   r   HAVE_GETSHORTPATHNAMEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r<   U   sT   A

	
7
,
 




$

	E#
r<   c                   @   s   e Zd ZeZdgZdS )NtCommonTestrn   N)r9   r:   r;   r   Z
pathmoduleZ
attributesr   r   r   r   r     s   r   c                   @   s   e Zd Ze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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'd( Zd)d* Zd+S ),PathLikeTestsc                 C   s`   t j| _tt j| _| t j| j t| jdd}|d W d    n1 sR0    Y  d S )Nxbr   s   test_ntpath.PathLikeTests)	r   rd   	file_namer   	file_pathrg   rh   re   r   )r6   filer   r   r   setUp  s
    zPathLikeTests.setUpc                 C   s   |  || j|| j d S r   )r7   r   r   )r6   funcr   r   r   _check_function  s    zPathLikeTests._check_functionc                 C   s   |  | jj d S r   )r   r   r   rA   r   r   r   test_path_normcase  s    z PathLikeTests.test_path_normcasec                 C   s   |  | jj d S r   )r   r   isabsrA   r   r   r   test_path_isabs  s    zPathLikeTests.test_path_isabsc                 C   s,   |  | jdtdd| jddd d S )NrO   brz   )r5   r   r{   r   rA   r   r   r   test_path_join  s    zPathLikeTests.test_path_joinc                 C   s   |  | jj d S r   )r   r   splitrA   r   r   r   test_path_split  s    zPathLikeTests.test_path_splitc                 C   s   |  | jj d S r   )r   r   splitextrA   r   r   r   test_path_splitext  s    z PathLikeTests.test_path_splitextc                 C   s   |  | jj d S r   )r   r   rF   rA   r   r   r   test_path_splitdrive  s    z"PathLikeTests.test_path_splitdrivec                 C   s   |  | jj d S r   )r   r   r   rA   r   r   r   test_path_basename  s    z PathLikeTests.test_path_basenamec                 C   s   |  | jj d S r   )r   r   r^   rA   r   r   r   test_path_dirname  s    zPathLikeTests.test_path_dirnamec                 C   s   |  | jj d S r   )r   r   islinkrA   r   r   r   test_path_islink  s    zPathLikeTests.test_path_islinkc                 C   s   |  | jj d S r   )r   r   lexistsrA   r   r   r   test_path_lexists  s    zPathLikeTests.test_path_lexistsc                 C   s   |  | jj d S r   )r   r   r   rA   r   r   r   test_path_ismount   s    zPathLikeTests.test_path_ismountc                 C   s   |  | jj d S r   )r   r   
expanduserrA   r   r   r   test_path_expanduser  s    z"PathLikeTests.test_path_expanduserc                 C   s   |  | jj d S r   )r   r   
expandvarsrA   r   r   r   test_path_expandvars  s    z"PathLikeTests.test_path_expandvarsc                 C   s   |  | jj d S r   )r   r   rY   rA   r   r   r   test_path_normpath	  s    z PathLikeTests.test_path_normpathc                 C   s   |  | jj d S r   )r   r   rc   rA   r   r   r   test_path_abspath  s    zPathLikeTests.test_path_abspathc                 C   s   |  | jj d S r   )r   r   rj   rA   r   r   r   test_path_realpath  s    z PathLikeTests.test_path_realpathc                 C   s   |  | jj d S r   )r   r   rn   rA   r   r   r   test_path_relpath  s    zPathLikeTests.test_path_relpathc                 C   s&   | j | j| jg}| || j d S r   )r   r   r   r   r7   )r6   Zcommon_pathr   r   r   test_path_commonpath  s    z"PathLikeTests.test_path_commonpathc                 C   s   |  | jj d S r   )r   r   isdirrA   r   r   r   test_path_isdir  s    zPathLikeTests.test_path_isdirN)r9   r:   r;   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s,   r   __main__)r   r   r   r   r-   Ztest.supportr   r   r   r   r   tempfiler   r   ImportErrorr   AttributeErrorr   r   r   r   r!   r3   ZTestCaser4   r<   Z
CommonTestr   r   r9   mainr   r   r   r   <module>   sD   




    }J
