o
    HXh                     @   sj  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 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yM   dZY nw ze j W n ey^   dZY nw d	Zzd dlZW n eyr   dZY nw 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re"  dS dS )    N)ALLOW_MISSING)	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   :/opt/python-3.10.19/usr/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>3   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   tester7   s.   

r3   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 ](}|  |  | g||R i | W d    n1 s!w   Y  |   qd S r   )subTestZ
doCleanups)selfargskwargsZ	parameter)func
parametersr   r   _parameterized[   s   
zE_parameterize.<locals>._parametrize_decorator.<locals>._parameterizedr   )r8   r:   r9   )r8   r   _parametrize_decoratorZ   s   z-_parameterize.<locals>._parametrize_decoratorr   )r9   r<   r   r;   r   _parameterizeO   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)r5   Zpath1Zpath2r   r   r   assertPathEquale   s   zNtpathTestCase.assertPathEqualc                 C   s   |  t|t| d S r   )ZassertInr!   )r5   r   Zpathsetr   r   r   assertPathInj   s   zNtpathTestCase.assertPathInN)__name__
__module____qualname__r@   rA   r   r   r   r   r>   d   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/foorG   zntpath.splitext(".ext"))rG    zntpath.splitext("\foo.ext\foo"))z\foo.ext\foorH   zntpath.splitext("foo.ext\"))zfoo.ext\rH   zntpath.splitext(""))rH   rH   zntpath.splitext("foo.bar.ext"))zfoo.barrG   z!ntpath.splitext("xx/foo.bar.ext"))z
xx/foo.barrG   z!ntpath.splitext("xx\foo.bar.ext"))z
xx\foo.barrG   zntpath.splitext("c:a/b\c.d"))zc:a/b\cz.dr3   r5   r   r   r   test_splitexto   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"))rL   /foo/barz/ntpath.splitdrive("\\conky\mountpoint\foo\bar"))z\\conky\mountpointrM   z/ntpath.splitdrive("//conky/mountpoint/foo/bar"))z//conky/mountpointrN   z0ntpath.splitdrive("\\\conky\mountpoint\foo\bar"))rH   z\\\conky\mountpoint\foo\barz0ntpath.splitdrive("///conky/mountpoint/foo/bar"))rH   z///conky/mountpoint/foo/barz0ntpath.splitdrive("\\conky\\mountpoint\foo\bar"))rH   z\\conky\\mountpoint\foo\barz0ntpath.splitdrive("//conky//mountpoint/foo/bar"))rH   z//conky//mountpoint/foo/baru   //conky/MOUNTPOİNT/foo/bar)u   //conky/MOUNTPOİNTrN   )r3   r?   r   
splitdriverJ   r   r   r   test_splitdrive{   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\foorQ   zntpath.split("c:\"))c:\rH   z#ntpath.split("\\conky\mountpoint\"))z\\conky\mountpoint\rH   zntpath.split("c:/"))c:/rH   z#ntpath.split("//conky/mountpoint/"))z//conky/mountpoint/rH   rI   rJ   r   r   r   
test_split   s   


zTestNtpath.test_splitc                 C   ,   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")rI   rJ   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/spamrI   rJ   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("")rH   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)
rH   za/bz/a/brL   zc:a/brS   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/brI   )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:/')rR   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\ZrI   rJ   r   r   r   test_normpath   s,   




















zTestNtpath.test_normpathc                 C   D   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   r5   expectedr   r   r   test_realpath_curdir     



zTestNtpath.test_realpath_curdirc                 C   rc   )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)rd   rg   r   r   r   test_realpath_curdir_strict  rj   z&TestNtpath.test_realpath_curdir_strictc                 C   rc   )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)rd   rg   r   r   r   test_realpath_curdir_missing_ok  s    z*TestNtpath.test_realpath_curdir_missing_okc                 C   ~   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   re   r   rf   r3   dirnamerO   rg   r   r   r   test_realpath_pardir#     zTestNtpath.test_realpath_pardirc                 C   rm   )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)rn   rg   r   r   r   test_realpath_pardir_strict/  rq   z&TestNtpath.test_realpath_pardir_strictc                 C   rm   )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)rn   rg   r   r   r   test_realpath_pardir_missing_ok;  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   symlinkr@   realpathr*   r5   r7   ABSTFNr   r   r   test_realpath_basicH  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 )Nrw   Trt   2)r   rx   r   ry   r   r~   r|   r}   assertRaisesFileNotFoundErrorr   r5   r   r   r   r   test_realpath_strictV  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 ru   )r   rx   r   ry   rz   r{   r|   r}   r   r~   relpathr@   r   r   r   r   r   test_realpath_relativea  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subdirr_   	recursiver^   parentr5   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   rx   r   ry   r   mkdirr|   rmtree
change_cwdchdirr~   r@   r   r*   r   r   r   r   test_realpath_broken_symlinksm  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 )Nrw   r   r\   crY   1\xc                 s   s    | ]	}t |d V  qdS )r[   N)r   join)r   rr   r   r   r     s    z9TestNtpath.test_realpath_symlink_loops.<locals>.<genexpr>1\..1\..\x\xr[   1\..\a\b..\r"   )r   rx   r   ry   r|   r}   r   r~   r@   r   rA   ro   basename)r5   r   rh   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 )Nrw   r   r\   r   rY   Tr   r   r   r   r[   r   r   r   r"   )r   rx   r   ry   r|   r}   r   r~   r   r
   r   r@   ro   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 )Nrw   r   r\   r   rY   r[   r   r   r   r   r   r   r   r   r"   )r   rx   r   ry   r|   r}   r   r~   r   r
   r   r   r@   ro   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 sCw   Y  t	|d |d  td| d d}|d W d    n1 skw   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 sw   Y  tt |d d	}| | d W d    n1 sw   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.linkrv      0   1rb)r   rx   r   ry   r|   r}   rz   writer   r~   r@   r   r?   read)r5   r7   r   fr   r   r   test_realpath_symlink_prefix7  s>   


z'TestNtpath.test_realpath_symlink_prefixc                 C   rU   )Nzntpath.realpath('NUL')ra   z$ntpath.realpath('NUL', strict=False)z#ntpath.realpath('NUL', strict=True)z,ntpath.realpath('NUL', strict=ALLOW_MISSING)rI   rJ   r   r   r   test_realpath_nulZ  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 sLw   Y  | |t | i ddidtifD ]}| jdi |m t| | |t jdi | W d    n1 sw   Y  t|  | |t jdi | W d    n1 sw   Y  t| | |t jdi | W d    n1 sw   Y  W d    n1 sw   Y  qcd S )	NZMyVeryLongDirectoryNamefile.txtrv   s   contentrt   Tr   )r   )r   rx   r   ry   r}   r   r   r   r|   r   r   rz   r   r@   r   r   r4   r   lower)r5   r   Ztest_dir_longZtest_dir_shortZtest_file_longZtest_file_shortr   r7   r   r   r   test_realpath_cwda  sL   



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 )(NrQ   rF   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   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)rI   )valuerh   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)r3   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)r3   r   temp_cwdry   r   rO   )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")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"))r3   r   r   ry   r   r   )r5   r   Z
currentdirr   r   r   test_relpath  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"   )r3   r(   )pathsrh   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>)r   r   
commonpath)excr   rJ   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   alotrH   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)r5   r   r   r   rJ   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platformr   r
   )r5   Ztf1Ztf2r   r   r   test_sameopenfileL  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 )NrR   r   rS   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   rO   
executabler   ro   r   upper)r5   dr   r   r   r   r   test_ismountY  s4   

zTestNtpath.test_ismountc                 C   s   |  | |  dS )z<Assert that two strings are equal ignoring case differences.N)r?   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   rO   r   Z_getdiskusageexec_prefixZassertGreaterr,   r?   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).rB   rC   rD   rK   rP   rT   rW   rX   r]   rb   ri   rk   rl   rp   rr   rs   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   rE   n   sv    A

	
	
7
-
*
4

 


#

1
	E#
rE   c                   @   s   e Zd ZeZdgZdS )NtCommonTestr   N)rB   rC   rD   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   ry   	file_namer   	file_pathr|   r}   rz   r   )r5   filer   r   r   setUp  s   "zPathLikeTests.setUpc                 C   s   |  || j|| j d S r   )r@   r   r   )r5   r8   r   r   r   _check_function  s   zPathLikeTests._check_functionc                 C   s2   |  | jj tjdkr| tdd d S d S )Nr   u   ΩΩu   ωΩ)r   r   r   r   r   r?   r   rJ   r   r   r   test_path_normcase  s   
z PathLikeTests.test_path_normcasec                 C      |  | jj d S r   )r   r   isabsrJ   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 )NrY   br   )r?   r   r   r   rJ   r   r   r   test_path_join  s   zPathLikeTests.test_path_joinc                 C   r   r   )r   r   splitrJ   r   r   r   test_path_split  r   zPathLikeTests.test_path_splitc                 C   r   r   )r   r   splitextrJ   r   r   r   test_path_splitext  r   z PathLikeTests.test_path_splitextc                 C   r   r   )r   r   rO   rJ   r   r   r   test_path_splitdrive  r   z"PathLikeTests.test_path_splitdrivec                 C   r   r   )r   r   r   rJ   r   r   r   test_path_basename  r   z PathLikeTests.test_path_basenamec                 C   r   r   )r   r   ro   rJ   r   r   r   test_path_dirname  r   zPathLikeTests.test_path_dirnamec                 C   r   r   )r   r   islinkrJ   r   r   r   test_path_islink  r   zPathLikeTests.test_path_islinkc                 C   r   r   )r   r   lexistsrJ   r   r   r   test_path_lexists  r   zPathLikeTests.test_path_lexistsc                 C   r   r   )r   r   r   rJ   r   r   r   test_path_ismount  r   zPathLikeTests.test_path_ismountc                 C   r   r   )r   r   
expanduserrJ   r   r   r   test_path_expanduser  r   z"PathLikeTests.test_path_expanduserc                 C   r   r   )r   r   
expandvarsrJ   r   r   r   test_path_expandvars  r   z"PathLikeTests.test_path_expandvarsc                 C   r   r   )r   r   re   rJ   r   r   r   test_path_normpath  r   z PathLikeTests.test_path_normpathc                 C   r   r   )r   r   rx   rJ   r   r   r   test_path_abspath  r   zPathLikeTests.test_path_abspathc                 C   r   r   )r   r   r   rJ   r   r   r   test_path_realpath  r   z PathLikeTests.test_path_realpathc                 C   r   r   )r   r   r   rJ   r   r   r   test_path_relpath  r   zPathLikeTests.test_path_relpathc                 C   s&   | j | j| jg}| || j d S r   )r   r   r   r   r@   )r5   Zcommon_pathr   r   r   test_path_commonpath  s   z"PathLikeTests.test_path_commonpathc                 C   r   r   )r   r   isdirrJ   r   r   r   test_path_isdir  r   zPathLikeTests.test_path_isdirN)rB   rC   rD   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   Ztest.support.os_helperr   r   r   tempfiler   r   ImportErrorr   AttributeErrorr   r   r   r   r!   r3   r=   ZTestCaser>   rE   Z
CommonTestr   r   rB   mainr   r   r   r   <module>   s\    

      6L