o
    gE                     @   sN  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 d dlmZ d dlm	Z	 d dl
mZ d dlmZ zd dlZW n eyC   dZY nw ze j W n eyT   dZY nw dZzd dlZW n eyh   dZY nw 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re  dS dS )    N)	os_helper)
TestFailed)FakePath)test_genericpath)TemporaryFileFTc                 C   sn   t jdddj}t jt jt jg|_t j|_|| d d}|s&t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   F/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/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>1   s    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r%t|t|kr%t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 ssw   Y  t|t|krt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   tester5   s.   

r2   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   assertPathEqualN   s   zNtpathTestCase.assertPathEqualc                 C   s   |  t|t| d S r   )ZassertInr    )r5   r   Zpathsetr   r   r   assertPathInS   s   zNtpathTestCase.assertPathInN)__name__
__module____qualname__r6   r7   r   r   r   r   r3   M   s    r3   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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/d0 Z d1d2 Z!d3d4 Z"d5d6 Z#d7d8 Z$d9d: Z%eed;d<d= 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r2   r5   r   r   r   test_splitextX   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"))rB   /foo/barz/ntpath.splitdrive("\\conky\mountpoint\foo\bar"))z\\conky\mountpointrC   z/ntpath.splitdrive("//conky/mountpoint/foo/bar"))z//conky/mountpointrD   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İNTrD   )r2   r4   r   
splitdriver@   r   r   r   test_splitdrived   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\foorG   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?   r@   r   r   r   
test_splity   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?   r@   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?   r@   r   r   r   test_commonprefix   s   zTestNtpath.test_commonprefixc                 C   s2  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 | qqt 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/brB   zc:a/brI   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?   )r5   xyr   r   r   	test_join   sp   


















































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:/')rH   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?   r@   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   getcwdr2   r5   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   rX   r   rY   r2   dirnamerE   rZ   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   symlinkr6   realpathr)   r5   ABSTFNr   r   r   test_realpath_basic  s   zTestNtpath.test_realpath_basicc                 C   sZ   t tj}t|d | | tj| | jt	t j
|dd | jt	t j
|d dd d S )Nra   Tstrict2)r   rb   r   rc   r   rh   rf   rg   assertRaisesFileNotFoundErrorri   rj   r   r   r   test_realpath_strict  s
   zTestNtpath.test_realpath_strictc                 C   sj   t tj}t|d  | tj| | tj|d  t	|t 
|d  | t |d | d S r_   )r   rb   r   rc   rd   re   rf   rg   r   rh   relpathr6   ri   rj   r   r   r   test_realpath_relative  s   z!TestNtpath.test_realpath_relativec                 C   sv  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    d S 1 s4w   Y  d S )#NZsubdirrT   	recursiverS   parentr5   Z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   rb   r   rc   r   mkdirrf   rmtree
change_cwdchdirrh   r6   ri   r)   rj   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 )Nra   ro   rQ   crN   1\xc                 s   s    | ]	}t |d V  qdS )rP   N)r   join)r   rr   r   r   r   w  s    z9TestNtpath.test_realpath_symlink_loops.<locals>.<genexpr>1\..1\..\xz\xrP   1\..\a\b..\r!   )r   rb   r   rc   rf   rg   r   rh   r6   ri   r7   r]   basename)r5   rk   r[   r   r   r   test_realpath_symlink_loops_  sf   z&TestNtpath.test_realpath_symlink_loopsc                 C   s6  t tj}| tj| | tj|d  | tj|d  | tj|d  | tj|d  | tj|d  t|| | jt	t j
|dd t|d |d  t|d |d  | jt	t j
|d dd | jt	t j
|d dd | jt	t j
|d dd | t j
|d	 ddt | | jt	t j
|d
 dd t|d |d  | jt	t j
|d t | d dd | jt	t j
|d t | d dd tt |d |d  | jt	t j
|d dd tdt t | d t | d |d  | jt	t j
|d dd | jt	t j
t |dd d S )Nra   ro   rQ   r}   rN   Trm   r~   r   r   rP   r   r   r   r!   )r   rb   r   rc   rf   rg   r   rh   rp   r	   ri   r6   r]   r   rj   r   r   r   "test_realpath_symlink_loops_strict  sZ   

z-TestNtpath.test_realpath_symlink_loops_strictc                 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 sCw   Y  t	|d |d  td| d d}|d W d    n1 skw   Y  t	d| d |d  | 
t |d |d  | 
t |d d| d  tt |d d	}| | d W d    n1 sw   Y  tt |d d	}| | d W d    n1 sw   Y  | 
t d| d d| d  | 
t d| d d| d  d S )
N3z\\?\z3.Z3linkz3.linkr`      0   1rb)r   rb   r   rc   rf   rg   rd   writer   rh   r6   ri   r4   read)r5   rk   fr   r   r   test_realpath_symlink_prefix  s>   


z'TestNtpath.test_realpath_symlink_prefixc                 C   s   t dd d S )Nzntpath.realpath('NUL')rV   r?   r@   r   r   r   test_realpath_nul  s   zTestNtpath.test_realpath_nulzneed _getshortpathnamec                 C   sr  t tj}t| t| t| | tj| t 	|d}t| t
|}t 	|d}t 	|d}t|d}|d W d    n1 sLw   Y  | |t | t| | |t d W d    n1 ssw   Y  t|  | |t d W d    n1 sw   Y  t| | |t d W d    d S 1 sw   Y  d S )NZMyVeryLongDirectoryNamezfile.txtr`   s   content)r   rb   r   rc   rg   ry   r   rx   rf   r   r   rd   r   r6   ri   rz   lower)r5   rk   Ztest_dir_longZtest_dir_shortZtest_file_longZtest_file_shortr   r   r   r   test_realpath_cwd  s.   



"zTestNtpath.test_realpath_cwdc                 C   s  t  x}|  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    d S 1 sw   Y  d S )(NrG   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clearr2   r5   envr   r   r   test_expandvars  s2   


















"zTestNtpath.test_expandvarszneed os_helper.FS_NONASCIIc                 C   s   dd }t  l}|  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    d S 1 sww   Y  d S )Nc                 S   s   t d|  | d S )Nzntpath.expandvars(%r)r?   )valuer[   r   r   r   check     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
   )r5   r   r   Znonasciir   r   r   test_expandvars_nonascii  s"   
"z#TestNtpath.test_expandvars_nonasciic                 C   sD  t dd t }|  t dd d|d< d|d< d	|d
< t dd t dd |d= t dd 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 |  d|d< d|d< d	|d
< t dd t dd |  d|d< d|d
< t dd t dd W d    d S 1 sw   Y  d S )Nzntpath.expanduser("test")testzntpath.expanduser("~test")z~testC:\	HOMEDRIVEz
Users\ericHOMEPATHZericUSERNAMEzC:\Users\testzntpath.expanduser("~")zC:\Users\ericz
Users\testUSERPROFILEz"ntpath.expanduser("~test\foo\bar")zC:\Users\test\foo\barz"ntpath.expanduser("~test/foo/bar")zC:\Users\test/foo/barzntpath.expanduser("~\foo\bar")zC:\Users\eric\foo\barzntpath.expanduser("~/foo/bar")zC:\Users\eric/foo/barzF:\HOMEZidle)r2   r   r   r   r   r   r   r   test_expanduser+  sR   











"zTestNtpath.test_expanduserzabspath requires 'nt' modulec                 C   s~   t dd ttj*}t d| t d|d  t d|d  t|\}}t d|d	  W d    d S 1 s8w   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)r2   r   temp_cwdrc   r   rE   )r5   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 s<w   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")rN   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   rO   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")rT   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")rU   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"))r2   r   r   rc   r   r   )r5   r   Z
currentdirr   r   r   test_relpathf  s.   

















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!   )r2   r'   )pathsr[   r   r   r   r     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>  s    zCTestNtpath.test_commonpath.<locals>.check_error.<locals>.<listcomp>)rp   r   
commonpath)excr   r@   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)rp   
ValueErrorr   r   	TypeError)r5   r   r   r   r@   r   test_commonpath~  s   





zTestNtpath.test_commonpathc              
   C   s   t  ^}t  B}| t| |  | t| |  tjdkrB| t	 tdd W d    n1 s=w   Y  W d    n1 sLw   Y  W d    d S W d    d S 1 sdw   Y  d S )Nwin32)
r   
assertTruer   sameopenfilefilenoassertFalsesysplatformrp   r	   )r5   Ztf1Ztf2r   r   r   test_sameopenfile  s   
Pz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 sww   Y  tjdkrttj	\}}t
ttj	 | t|  | t|  W d    n1 sw   Y  |  td |  td |  td |  td d S d S )NrH   r   rI   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   rE   
executablerz   r]   r   upper)r5   dr   r   r   r   r   test_ismount  s4   

zTestNtpath.test_ismountc                 C   s   |  | |  dS )z<Assert that two strings are equal ignoring case differences.N)r4   r   )r5   s1s2r   r   r   assertEqualCI  s   zTestNtpath.assertEqualCIzOS helpers require 'nt' modulec                 C   s  t tj}|t|fD ]}t |}t|d }t|d }| 	|| qt 
tj\}}| |d | |d t 
tj \}}	| || | |	d tjtjfD ]*}t |}
| |
t | t|
d t | }| |t | t|d qYd S )Nr   )nt_getfinalpathnamer   r   r   r)   _getvolumepathnamer   rE   r   Z_getdiskusageexec_prefixZassertGreaterr+   r4   prefixZassertIsInstancer   lenr   )r5   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)'r8   r9   r:   rA   rF   rJ   rL   rM   rR   rW   r\   r^   r   Zskip_unless_symlinkunittestZ
skipUnlessHAVE_GETFINALPATHNAMErl   rr   rt   r|   r   r   r   r   HAVE_GETSHORTPATHNAMEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   W   sb    A

	
	
7
-
*

 




1
	E#
r;   c                   @   s   e Zd ZeZdgZdS )NtCommonTestrs   N)r8   r9   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   sb   t j| _tt j| _| t j| j t| jdd}|d W d    d S 1 s*w   Y  d S )Nxbr   s   test_ntpath.PathLikeTests)	r   rc   	file_namer   	file_pathrf   rg   rd   r   )r5   filer   r   r   setUp  s   "zPathLikeTests.setUpc                 C   s   |  || j|| j d S r   )r6   r   r   )r5   funcr   r   r   _check_function%  s   zPathLikeTests._check_functionc                 C      |  | jj d S r   )r   r   r   r@   r   r   r   test_path_normcase(  r   z PathLikeTests.test_path_normcasec                 C   r   r   )r   r   isabsr@   r   r   r   test_path_isabs+  r   zPathLikeTests.test_path_isabsc                 C   s,   |  | jdtdd| jddd d S )NrN   br}   )r4   r   r   r   r@   r   r   r   test_path_join.  s   zPathLikeTests.test_path_joinc                 C   r   r   )r   r   splitr@   r   r   r   test_path_split2  r   zPathLikeTests.test_path_splitc                 C   r   r   )r   r   splitextr@   r   r   r   test_path_splitext5  r   z PathLikeTests.test_path_splitextc                 C   r   r   )r   r   rE   r@   r   r   r   test_path_splitdrive8  r   z"PathLikeTests.test_path_splitdrivec                 C   r   r   )r   r   r   r@   r   r   r   test_path_basename;  r   z PathLikeTests.test_path_basenamec                 C   r   r   )r   r   r]   r@   r   r   r   test_path_dirname>  r   zPathLikeTests.test_path_dirnamec                 C   r   r   )r   r   islinkr@   r   r   r   test_path_islinkA  r   zPathLikeTests.test_path_islinkc                 C   r   r   )r   r   lexistsr@   r   r   r   test_path_lexistsD  r   zPathLikeTests.test_path_lexistsc                 C   r   r   )r   r   r   r@   r   r   r   test_path_ismountG  r   zPathLikeTests.test_path_ismountc                 C   r   r   )r   r   
expanduserr@   r   r   r   test_path_expanduserJ  r   z"PathLikeTests.test_path_expanduserc                 C   r   r   )r   r   
expandvarsr@   r   r   r   test_path_expandvarsM  r   z"PathLikeTests.test_path_expandvarsc                 C   r   r   )r   r   rX   r@   r   r   r   test_path_normpathP  r   z PathLikeTests.test_path_normpathc                 C   r   r   )r   r   rb   r@   r   r   r   test_path_abspathS  r   zPathLikeTests.test_path_abspathc                 C   r   r   )r   r   ri   r@   r   r   r   test_path_realpathV  r   z PathLikeTests.test_path_realpathc                 C   r   r   )r   r   rs   r@   r   r   r   test_path_relpathY  r   zPathLikeTests.test_path_relpathc                 C   s&   | j | j| jg}| || j d S r   )r   r   r   r   r6   )r5   Zcommon_pathr   r   r   test_path_commonpath\  s   z"PathLikeTests.test_path_commonpathc                 C   r   r   )r   r   isdirr@   r   r   r   test_path_isdir`  r   zPathLikeTests.test_path_isdirN)r8   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     s.    r   __main__) r   r   r   r   r,   Ztest.supportr   r   Ztest.support.os_helperr   r   r   tempfiler   r   ImportErrorr   AttributeErrorr   r   r   r   r    r2   ZTestCaser3   r;   Z
CommonTestr   r   r8   mainr   r   r   r   <module>   sT    

     CJ