B
    u9aK^                 @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
 d dlmZ yd dlZW n ek
rx   dZY nX dd ZG dd dejZG d	d
 d
e
jejZG dd dejZedkre  dS )    N)
TestFailedFakePath)supporttest_genericpath)TemporaryFilec          	   C   s2  |  dd} 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 Q R X t|trt|}nt|trtdd |D }t| }||kr.tdt| t|t|f d S )N\z\\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ignorec             s   s   | ]}t |V  qd S )N)osfsencode).0r r   !/usr/lib/python3.7/test_ntpath.py	<genexpr>'   s    ztester.<locals>.<genexpr>)replaceevalr   strr   r   decodeencodewarningscatch_warningssimplefilterDeprecationWarning
isinstancetuplerepr)fnZ
wantResultZ	gotResultr   r   r   tester   s0    



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
eejddd Zdd Zeeddd Zdd Zdd Zdd Zdd  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"))fooz.extzntpath.splitext("/foo/foo.ext"))z/foo/fooz.extzntpath.splitext(".ext"))z.ext 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.barz.extz!ntpath.splitext("xx/foo.bar.ext"))z
xx/foo.barz.extz!ntpath.splitext("xx\foo.bar.ext"))z
xx\foo.barz.extzntpath.splitext("c:a/b\c.d"))zc:a/b\cz.d)r    )selfr   r   r   test_splitext0   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"))zc:z\foo\barzntpath.splitdrive("c:/foo/bar"))zc:z/foo/barz/ntpath.splitdrive("\\conky\mountpoint\foo\bar"))z\\conky\mountpointz\foo\barz/ntpath.splitdrive("//conky/mountpoint/foo/bar"))z//conky/mountpointz/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\barz0ntpath.splitdrive("//conky//mountpoint/foo/bar"))r#   z//conky//mountpoint/foo/baru   //conky/MOUNTPOİNT/foo/bar)u   //conky/MOUNTPOİNTz/foo/bar)r    assertEqualntpath
splitdrive)r$   r   r   r   test_splitdrive<   s$    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\foor*   zntpath.split("c:\"))zc:\r#   z#ntpath.split("\\conky\mountpoint\"))z\\conky\mountpoint\r#   zntpath.split("c:/"))zc:/r#   z#ntpath.split("//conky/mountpoint/"))z//conky/mountpoint/r#   )r    )r$   r   r   r   
test_splitQ   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/spam)r    )r$   r   r   r   test_commonprefixc   s    zTestNtpath.test_commonprefixc             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$ 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 x0dMD ](}x dND ]}t dO||f | qW qW t 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")z\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/bzc:zc:a/bzc:/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/b)r    )r$   xyr   r   r   	test_joink   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..zntpath.normpath('.').zntpath.normpath('')zntpath.normpath('/')r   zntpath.normpath('c:/')zc:\zntpath.normpath('/../.././..')zntpath.normpath('c:/../../..')zntpath.normpath('../.././..')z..\..\..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')z\\.\NULzntpath.normpath('\\?\D:/XY\Z')z\\?\D:/XY\Z)r    )r$   r   r   r   test_normpath   s,    




















zTestNtpath.test_normpathc          	   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 Q R X d S )(Nr*   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clearr    )r$   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 Q R X d S )Nc             S   s   t d|  | d S )Nzntpath.expandvars(%r))r    )valueexpectedr   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   r5   r6   FS_NONASCIIformat)r$   r;   r7   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 |  d|d< t dd t d
d t dd t dd t dd t dd W d Q R X d S )Nzntpath.expanduser("test")testzntpath.expanduser("~test")z~testz	eric\idleZHOMEPATHzC:\Z	HOMEDRIVEzC:\eric\testzntpath.expanduser("~")zC:\eric\idlez	eric\testZUSERPROFILEzC:\idle\ericHOMEzC:\idle\testz"ntpath.expanduser("~test\foo\bar")zC:\idle\test\foo\barz"ntpath.expanduser("~test/foo/bar")zC:\idle\test/foo/barzntpath.expanduser("~\foo\bar")zC:\idle\eric\foo\barzntpath.expanduser("~/foo/bar")zC:\idle\eric/foo/bar)r    r   r5   r6   )r$   r7   r   r   r   test_expanduser   s6    










zTestNtpath.test_expanduserzabspath requires 'nt' modulec          	   C   sh   t dd ttjH}t d| t d|d  t d|d  t|\}}t d|d	  W d Q R X d S )
Nzntpath.abspath("C:\")zC:\zntpath.abspath("")zntpath.abspath(" ")z\ zntpath.abspath("?")z\?zntpath.abspath("/abc/")z\abc)r    r   temp_cwdTESTFNr'   r(   )r$   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6}tj|}t dd	| d
  t dd	| d  W d Q R X 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")r/   z$ntpath.relpath(os.path.abspath("a"))zntpath.relpath("a/b")za\bzntpath.relpath("../a/b")z..\a\bzntpath.relpath("a", "../b")z..\z\az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")r3   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")z..\..\..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"))r    r   rC   rD   r   pathbasename)r$   rE   Z
currentdirr   r   r   test_relpath"  s,    
















zTestNtpath.test_relpathc                s^  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 |dddgd |dddg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)z\\r   )r    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   pr   r   r   
<listcomp>A  s    zCTestNtpath.test_commonpath.<locals>.check_error.<locals>.<listcomp>)assertRaisesr'   
commonpath)excrL   )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\.zC:\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<   Zalotr#   zand\jamzand\spamandzand\\jamz
and\spam\\z	and\.\jamz
.\and\spamz	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)rO   
ValueErrorr'   rP   	TypeError)r$   r;   rR   r   )r$   r   test_commonpath:  sp    










zTestNtpath.test_commonpathc             C   s   t  x}t  f}| t| |  | t| |  tjdkrp| t	 tdd W d Q R X W d Q R X W d Q R X d S )Nwin32)
r   
assertTruer'   sameopenfilefilenoassertFalsesysplatformrO   OSError)r$   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 Q R X tjdkrttj	\}}t
tjtj	. | t|  | t|  W d Q R X |  td |  td |  td |  td d S )Nzc:\zC:\zc:/zC:/z\\.\c:\z\\.\C:\s   c:\s   C:\s   c:/s   C:/s   \\.\c:\s   \\.\C:\rW   z\\localhost\c$z\\localhost\c$\s   \\localhost\c$s   \\localhost\c$\)rY   r'   ismountr   Ztemp_dirr\   r]   r^   r(   
executableZ
change_cwdr   rI   dirnamelowerupper)r$   drF   rI   r   r   r   test_ismount  s.    
zTestNtpath.test_ismountzOS helpers require 'nt' modulec       	      C   s  t tj\}}|t jt j }| |ttj | |	 ttj	  t
tj\}}| |d | |d t
tj	 \}}| || | |d xdtjtjgD ]T}t|}| |t | t|d t|	 }| |t | t|d qW d S )Nr   )r'   r(   r]   rb   rstripsepr&   ntZ_getvolumepathnamer   Z_getdiskusageexec_prefixZassertGreaterprefixZ_getfinalpathnameZassertIsInstancer   lenbytes)	r$   rF   rI   ZcapZfreeZb_capZb_freeZ
final_pathZb_final_pathr   r   r   test_nt_helpers  s$    

zTestNtpath.test_nt_helpersN)__name__
__module____qualname__r%   r)   r+   r-   r.   r2   r4   r8   unittestZ
skipUnlessr   r=   r?   rB   rj   rH   rK   rV   r`   rg   ro   r   r   r   r   r!   /   s    A#
E#r!   c               @   s   e Zd ZeZdgZdS )NtCommonTestrelpathN)rp   rq   rr   r'   Z
pathmoduleZ
attributesr   r   r   r   rt     s   rt   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   sP   t j | _tt j| _| t j| j t| jdd}|	d W d Q R X d S )NZxbr   s   test_ntpath.PathLikeTests)
r   rD   rd   	file_namer   	file_pathZ
addCleanupunlinkopenwrite)r$   filer   r   r   setUp  s
    zPathLikeTests.setUpc             C   s   |  || j|| j d S )N)r&   rx   rw   )r$   funcr   r   r   assertPathEqual  s    zPathLikeTests.assertPathEqualc             C   s   |  | jj d S )N)r   rI   normcase)r$   r   r   r   test_path_normcase  s    z PathLikeTests.test_path_normcasec             C   s   |  | jj d S )N)r   rI   isabs)r$   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 )Nr/   bc)r&   rI   joinr   )r$   r   r   r   test_path_join  s    zPathLikeTests.test_path_joinc             C   s   |  | jj d S )N)r   rI   split)r$   r   r   r   test_path_split  s    zPathLikeTests.test_path_splitc             C   s   |  | jj d S )N)r   rI   splitext)r$   r   r   r   test_path_splitext  s    z PathLikeTests.test_path_splitextc             C   s   |  | jj d S )N)r   rI   r(   )r$   r   r   r   test_path_splitdrive  s    z"PathLikeTests.test_path_splitdrivec             C   s   |  | jj d S )N)r   rI   rJ   )r$   r   r   r   test_path_basename  s    z PathLikeTests.test_path_basenamec             C   s   |  | jj d S )N)r   rI   rc   )r$   r   r   r   test_path_dirname  s    zPathLikeTests.test_path_dirnamec             C   s   |  | jj d S )N)r   rI   islink)r$   r   r   r   test_path_islink  s    zPathLikeTests.test_path_islinkc             C   s   |  | jj d S )N)r   rI   lexists)r$   r   r   r   test_path_lexists  s    zPathLikeTests.test_path_lexistsc             C   s   |  | jj d S )N)r   rI   ra   )r$   r   r   r   test_path_ismount  s    zPathLikeTests.test_path_ismountc             C   s   |  | jj d S )N)r   rI   
expanduser)r$   r   r   r   test_path_expanduser   s    z"PathLikeTests.test_path_expanduserc             C   s   |  | jj d S )N)r   rI   
expandvars)r$   r   r   r   test_path_expandvars  s    z"PathLikeTests.test_path_expandvarsc             C   s   |  | jj d S )N)r   rI   normpath)r$   r   r   r   test_path_normpath  s    z PathLikeTests.test_path_normpathc             C   s   |  | jj d S )N)r   rI   abspath)r$   r   r   r   test_path_abspath	  s    zPathLikeTests.test_path_abspathc             C   s   |  | jj d S )N)r   rI   realpath)r$   r   r   r   test_path_realpath  s    z PathLikeTests.test_path_realpathc             C   s   |  | jj d S )N)r   rI   ru   )r$   r   r   r   test_path_relpath  s    zPathLikeTests.test_path_relpathc             C   s&   | j | j| jg}| || j d S )N)rI   rP   rx   rw   r&   )r$   Zcommon_pathr   r   r   test_path_commonpath  s    z"PathLikeTests.test_path_commonpathc             C   s   |  | jj d S )N)r   rI   isdir)r$   r   r   r   test_path_isdir  s    zPathLikeTests.test_path_isdirN)rp   rq   rr   r'   rI   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   rv     s,   rv   __main__)r'   r   r]   rs   r   Ztest.supportr   r   r@   r   r   Ztempfiler   rj   ImportErrorr    ZTestCaser!   Z
CommonTestrt   rv   rp   mainr   r   r   r   <module>   s(   
   J