a
     Rhy                     @   sX  d dl Z 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m	Z	 d dl
mZmZ d dlmZ zd dlZW n ey   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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rTe!  dS )    N)ALLOW_MISSING)
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   8/opt/python-3.9.24/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>1       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   tester5   s*    
&r4   c                     s    fdd}|S )aq  Simplistic decorator to parametrize a test

    Runs the decorated test multiple times in subTest, with a value from
    'parameters' passed as an extra positional argument.
    Calls doCleanups() after each run.

    Not for general use. Intended to avoid indenting for easier backports.

    See https://discuss.python.org/t/91827 for discussing generalizations.
    c                    s    fdd}|S )Nc              	      sZ   D ]P}|  |*  | g||R i | W d    n1 sB0    Y  |   qd S r   )subTestZ
doCleanups)selfargskwargsZ	parameter)func
parametersr   r   _parameterizedY   s    8zE_parameterize.<locals>._parametrize_decorator.<locals>._parameterizedr   )r9   r;   r:   )r9   r   _parametrize_decoratorX   s    z-_parameterize.<locals>._parametrize_decoratorr   )r:   r=   r   r<   r   _parameterizeM   s    r>   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)r6   Zpath1Zpath2r   r   r   assertPathEqualc   s    zNtpathTestCase.assertPathEqualc                 C   s   |  t|t| d S r   )ZassertInr"   )r6   r   Zpathsetr   r   r   assertPathInh   s    zNtpathTestCase.assertPathInN)__name__
__module____qualname__rA   rB   r   r   r   r   r?   b   s   r?   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dd Zdd Zdd Zdd Zejeedei ddideidd Zejeedd d! Zejeedei ddidei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ei ddideid,d- Zeedd.d/ Zeedee d0d1d2 Z!d3d4 Z"eej#d5d6d7 Z$d8d9 Z%ee&d:d;d< Z'd=d> Z(d?d@ Z)dAdB Z*dCdD Z+dEdF Z,ee&dGdHdI Z-dJS )K
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/foorH   zntpath.splitext(".ext"))rH    zntpath.splitext("\foo.ext\foo"))z\foo.ext\foorI   zntpath.splitext("foo.ext\"))zfoo.ext\rI   zntpath.splitext(""))rI   rI   zntpath.splitext("foo.bar.ext"))zfoo.barrH   z!ntpath.splitext("xx/foo.bar.ext"))z
xx/foo.barrH   z!ntpath.splitext("xx\foo.bar.ext"))z
xx\foo.barrH   zntpath.splitext("c:a/b\c.d"))zc:a/b\cz.dr4   r6   r   r   r   test_splitextm   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"))rM   /foo/barz/ntpath.splitdrive("\\conky\mountpoint\foo\bar"))z\\conky\mountpointrN   z/ntpath.splitdrive("//conky/mountpoint/foo/bar"))z//conky/mountpointrO   z0ntpath.splitdrive("\\\conky\mountpoint\foo\bar"))rI   z\\\conky\mountpoint\foo\barz0ntpath.splitdrive("///conky/mountpoint/foo/bar"))rI   z///conky/mountpoint/foo/barz0ntpath.splitdrive("\\conky\\mountpoint\foo\bar"))rI   z\\conky\\mountpoint\foo\barz0ntpath.splitdrive("//conky//mountpoint/foo/bar"))rI   z//conky//mountpoint/foo/baru   //conky/MOUNTPOİNT/foo/bar)u   //conky/MOUNTPOİNTrO   )r4   r@   r   
splitdriverK   r   r   r   test_splitdrivey   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\foorR   zntpath.split("c:\"))c:\rI   z#ntpath.split("\\conky\mountpoint\"))z\\conky\mountpoint\rI   zntpath.split("c:/"))c:/rI   z#ntpath.split("//conky/mountpoint/"))z//conky/mountpoint/rI   rJ   rK   r   r   r   
test_split   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")rJ   rK   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/spamrJ   rK   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("")rI   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)
rI   za/bz/a/brM   zc:a/brT   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/brJ   )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:/')rS   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\ZrJ   rK   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   getcwdr4   r6   expectedr   r   r   test_realpath_curdir  s    



zTestNtpath.test_realpath_curdirc                 C   sD   t t }td| td| td| td| td| d S )Nz!ntpath.realpath('.', strict=True)z#ntpath.realpath('./.', strict=True)z3ntpath.realpath('/'.join(['.'] * 100), strict=True)z#ntpath.realpath('.\.', strict=True)z3ntpath.realpath('\'.join(['.'] * 100), strict=True)rc   rf   r   r   r   test_realpath_curdir_strict  s    



z&TestNtpath.test_realpath_curdir_strictc                 C   sD   t t }td| td| td| td| td| d S )Nz*ntpath.realpath('.', strict=ALLOW_MISSING)z,ntpath.realpath('./.', strict=ALLOW_MISSING)z<ntpath.realpath('/'.join(['.'] * 100), strict=ALLOW_MISSING)z,ntpath.realpath('.\.', strict=ALLOW_MISSING)z<ntpath.realpath('\'.join(['.'] * 100), strict=ALLOW_MISSING)rc   rf   r   r   r   test_realpath_curdir_missing_ok  s     z*TestNtpath.test_realpath_curdir_missing_okc                 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   rd   r   re   r4   dirnamerP   rf   r   r   r   test_realpath_pardir!  s    zTestNtpath.test_realpath_pardirc                 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('..', strict=True)z%ntpath.realpath('../..', strict=True)z3ntpath.realpath('/'.join(['..'] * 50), strict=True)r   r#   z%ntpath.realpath('..\..', strict=True)z3ntpath.realpath('\'.join(['..'] * 50), strict=True)rk   rf   r   r   r   test_realpath_pardir_strict-  s    z&TestNtpath.test_realpath_pardir_strictc                 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('..', strict=ALLOW_MISSING)z.ntpath.realpath('../..', strict=ALLOW_MISSING)z<ntpath.realpath('/'.join(['..'] * 50), strict=ALLOW_MISSING)r   r#   z.ntpath.realpath('..\..', strict=ALLOW_MISSING)z<ntpath.realpath('\'.join(['..'] * 50), strict=ALLOW_MISSING)rk   rf   r   r   r   test_realpath_pardir_missing_ok9  s     z*TestNtpath.test_realpath_pardir_missing_okzneed _getfinalpathnamestrictTc                 C   s   t tj}t|d  | tj| | tj|d  t	||d  | 
t j|d fi || | 
t jt|d fi |t| d S Nwb1)r   abspathr   TESTFNopenclose
addCleanupunlinkr   symlinkrA   realpathr+   r6   r8   ABSTFNr   r   r   test_realpath_basicF  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 )Nrs   Trp   2)r   rt   r   ru   r   rz   rx   ry   assertRaisesFileNotFoundErrorr{   r6   r}   r   r   r   test_realpath_strictT  s
    zTestNtpath.test_realpath_strictc                 C   sr   t tj}t|d  | tj| | tj|d  t	|t 
|d  | t j|d fi || d S rq   )r   rt   r   ru   rv   rw   rx   ry   r   rz   relpathrA   r{   r|   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subdirr_   	recursiver^   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   rt   r   ru   r   mkdirrx   rmtree
change_cwdchdirrz   rA   r{   r+   r   r   r   r   test_realpath_broken_symlinksk  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 )Nrs   r   r\   crY   1\xc                 s   s   | ]}t |d V  qdS )r[   N)r   join)r   rr   r   r   r     r   z9TestNtpath.test_realpath_symlink_loops.<locals>.<genexpr>1\..1\..\x\xr[   1\..\a\b..\r#   )r   rt   r   ru   rx   ry   r   rz   rA   r{   rB   rl   basename)r6   r}   rg   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 )Nrs   r   r\   r   rY   Tr   r   r   r   r[   r   r   r   r#   )r   rt   r   ru   rx   ry   r   rz   r   r
   r{   rA   rl   r   r   r   r   r   "test_realpath_symlink_loops_strict  sZ    
z-TestNtpath.test_realpath_symlink_loops_strictc                 C   sN  t tj}| tj| | tj|d  | tj|d  | tj|d  | tj|d  | tj|d  | tj|d  t|| | jt	t j
|td t|d |d  t|d |d  | jt	t j
|d td | jt	t j
|d td | jt	t j
|d td | t 
|d	 t | | t 
|d
 t |d  t|d |d  | t 
|d t | d |d  | jt	t j
|d t | d td tt |d |d  | jt	t j
|d td tdt t | d t | d |d  | jt	t j
|d td | jt	t j
t |td d S )Nrs   r   r\   r   rY   r[   r   r   r   r   r   r   r   r   r#   )r   rt   r   ru   rx   ry   r   rz   r   r
   r{   r   rA   rl   r   r   r   r   r   !test_realpath_symlink_loops_raise  sv    z,TestNtpath.test_realpath_symlink_loops_raisec                 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 j|d fi ||d  | 
t j|d fi |d| d  tt |d d	 }| | d W d    n1 s|0    Y  tt |d d	 }| | d W d    n1 s0    Y  | 
t jd| d fi |d| d  | 
t jd| d fi |d| d  d S )
N3z\\?\z3.Z3linkz3.linkrr      0   1rb)r   rt   r   ru   rx   ry   rv   writer   rz   rA   r{   r@   read)r6   r8   r}   fr   r   r   test_realpath_symlink_prefix5  s6    ((
00

z'TestNtpath.test_realpath_symlink_prefixc                 C   s,   t dd t dd t dd t dd d S )Nzntpath.realpath('NUL')ra   z$ntpath.realpath('NUL', strict=False)z#ntpath.realpath('NUL', strict=True)z,ntpath.realpath('NUL', strict=ALLOW_MISSING)rJ   rK   r   r   r   test_realpath_nulX  s    


zTestNtpath.test_realpath_nulzneed _getshortpathnamec              
   C   s  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 | i ddidtifD ]}| jf i | t|( | |t jdi | W d    n1 s0    Y  t| ( | |t jdi | W d    n1 s`0    Y  t|( | |t jd	i | W d    n1 s0    Y  W d    q1 s0    Y  qd S )
NZMyVeryLongDirectoryNamefile.txtrr   s   contentrp   T)r   )r   )r   )r   rt   r   ru   ry   r   r   r   rx   r   r   rv   r   rA   r{   r   r5   r   lower)r6   r}   Ztest_dir_longZtest_dir_shortZtest_file_longZtest_file_shortr   r8   r   r   r   test_realpath_cwd_  s<    



($$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 )(NrR   rG   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clearr4   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)rJ   )valuerg   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)r4   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)r4   r   temp_cwdru   r   rP   )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")rY   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   rZ   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")r_   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")r`   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"))r4   r   r   ru   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#   )r4   r)   )pathsrg   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>  r   zCTestNtpath.test_commonpath.<locals>.check_error.<locals>.<listcomp>)r   r   
commonpath)excr   rK   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   alotrI   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   rK   r   test_commonpath  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 )NrS   r   rT   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   rP   
executabler   rl   r   upper)r6   dr   r   r   r   r   test_ismountJ  s.    
.4zTestNtpath.test_ismountc                 C   s   |  | |  dS )z<Assert that two strings are equal ignoring case differences.N)r@   r   )r6   s1s2r   r   r   assertEqualCIm  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   rP   r   Z_getdiskusageexec_prefixZassertGreaterr-   r@   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_helpersq  s&    

zTestNtpath.test_nt_helpersN).rC   rD   rE   rL   rQ   rU   rW   rX   r]   rb   rh   ri   rj   rm   rn   ro   r   Zskip_unless_symlinkunittestZ
skipUnlessHAVE_GETFINALPATHNAMEr>   r   r~   r   r   r   r   r   r   r   r   HAVE_GETSHORTPATHNAMEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   l   st   A

	
	
7
-
*
4
 



#
$

	E#
rF   c                   @   s   e Zd ZeZdgZdS )NtCommonTestr   N)rC   rD   rE   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   ru   	file_namer   	file_pathrx   ry   rv   r   )r6   filer   r   r   setUp  s
    zPathLikeTests.setUpc                 C   s   |  || j|| j d S r   )rA   r   r   )r6   r9   r   r   r   _check_function  s    zPathLikeTests._check_functionc                 C   s   |  | jj d S r   )r   r   r   rK   r   r   r   test_path_normcase  s    z PathLikeTests.test_path_normcasec                 C   s   |  | jj d S r   )r   r   isabsrK   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 )NrY   br   )r@   r   r   r   rK   r   r   r   test_path_join  s    zPathLikeTests.test_path_joinc                 C   s   |  | jj d S r   )r   r   splitrK   r   r   r   test_path_split  s    zPathLikeTests.test_path_splitc                 C   s   |  | jj d S r   )r   r   splitextrK   r   r   r   test_path_splitext  s    z PathLikeTests.test_path_splitextc                 C   s   |  | jj d S r   )r   r   rP   rK   r   r   r   test_path_splitdrive  s    z"PathLikeTests.test_path_splitdrivec                 C   s   |  | jj d S r   )r   r   r   rK   r   r   r   test_path_basename  s    z PathLikeTests.test_path_basenamec                 C   s   |  | jj d S r   )r   r   rl   rK   r   r   r   test_path_dirname  s    zPathLikeTests.test_path_dirnamec                 C   s   |  | jj d S r   )r   r   islinkrK   r   r   r   test_path_islink  s    zPathLikeTests.test_path_islinkc                 C   s   |  | jj d S r   )r   r   lexistsrK   r   r   r   test_path_lexists  s    zPathLikeTests.test_path_lexistsc                 C   s   |  | jj d S r   )r   r   r   rK   r   r   r   test_path_ismount  s    zPathLikeTests.test_path_ismountc                 C   s   |  | jj d S r   )r   r   
expanduserrK   r   r   r   test_path_expanduser  s    z"PathLikeTests.test_path_expanduserc                 C   s   |  | jj d S r   )r   r   
expandvarsrK   r   r   r   test_path_expandvars  s    z"PathLikeTests.test_path_expandvarsc                 C   s   |  | jj d S r   )r   r   rd   rK   r   r   r   test_path_normpath  s    z PathLikeTests.test_path_normpathc                 C   s   |  | jj d S r   )r   r   rt   rK   r   r   r   test_path_abspath  s    zPathLikeTests.test_path_abspathc                 C   s   |  | jj d S r   )r   r   r{   rK   r   r   r   test_path_realpath  s    z PathLikeTests.test_path_realpathc                 C   s   |  | jj d S r   )r   r   r   rK   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   rA   )r6   Zcommon_pathr   r   r   test_path_commonpath  s    z"PathLikeTests.test_path_commonpathc                 C   s   |  | jj d S r   )r   r   isdirrK   r   r   r   test_path_isdir  s    zPathLikeTests.test_path_isdirN)rC   rD   rE   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   
subprocessr   r   r.   r   Ztest.supportr   r   r   r   r   tempfiler   r   ImportErrorr   AttributeErrorr   r   r   r   r"   r4   r>   ZTestCaser?   rF   Z
CommonTestr   r   rC   mainr   r   r   r   <module>   sN   




      )J
