B
    [T                 @   s  d Z ddlmZmZmZ 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Z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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Zdd	 Zejd
ejgddd Zej fddZ!G dd dZ"G dd dZ#G dd dZ$G dd dZ%G dd dZ&G dd dZ'G dd dZ(G dd dZ)G d d! d!Z*G d"d# d#Z+ej,j-ej.d$k d%d&G d'd( d(Z/G d)d* d*Z0G d+d, d,Z1ej,j2d-d.d&d/d0 Z3d1d2 Z4dS )3aC  
Tests for the path module.

This suite runs on Linux, OS X, and Windows right now.  To extend the
platform support, just add appropriate pathnames for your
platform (os.name) in each place where the p() function is called.
Then report the result.  If you can't get the test to run at all on
your platform, there's probably a bug in path.py -- please report the issue
in the issue tracker at https://github.com/jaraco/path.py.

TestScratchDir.test_touch() takes a while to run.  It sleeps a few
seconds to allow some time to pass between calls to check the modify
time on files.
    )unicode_literalsabsolute_importprint_functionN)TempDir)matchers)SpecialResolver)Multic              K   s
   | t j S )z? Choose a value from several possible values, based on os.name )osname)choices r   (lib/python3.7/site-packages/test_path.pyp0   s    r   T)autouseZparamsc             C   s   | t d| j dS )z5
    Invoke tests on any number of Path classes.
    PathN)setitemglobalsZparam)Zrequestmonkeypatchr   r   r   
path_class5   s    r   c             C   s6   t jt d }t j| }t dko4|||S )zF
    Return True if on a Mac whose version passes the comparator.
    r   Darwin)	packagingversionparseplatformZmac_versystem)targetZ
comparatorZcurrent_verZ
target_verr   r   r   mac_version=   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dd ZdS )
TestBasicsc       	      C   s  t tddd}|d }|d }|d }|d d }t tj}||t dd d d ks`t||t dd kszt|||d d d kst|||| | d kst|||| kst||dt d d d kst||tjkst||tjkst|| tjks4tt t }|	 ||ksXttj
d	krt d
}|||kstd S )NzC:\/)ntposixfooquuxbarZBazZBozr   zD:\)r   r   r	   pardir	relpathtoAssertionErrorcurdirnormcasegetcwdrelpathr
   )	selfrootr!   r"   r#   bozZupcwddr   r   r   test_relpathJ   s(    
""zTestBasics.test_relpathc             C   s.   yt d W n tk
r    Y n
X tddS )z


        NzDID NOT RAISE)r   	TypeError	Exception)r+   r   r   r   test_construction_from_nonek   s
    z&TestBasics.test_construction_from_nonec             C   s   t ddkstdS )zL
        Path class will construct a path as a string of the number
           1N)r   r&   )r+   r   r   r   test_construction_from_intv   s    z%TestBasics.test_construction_from_intc             C   s   t d}|dkst|tdks$tt dt ddt ddt ddg}|  |dddddddgkshtt d	}t d
}|| tdddkstdS )z+ Test compatibility with ordinary strings. ZxyzzyZfhjZfghEr/   ABcr!   r#   zfoo\barzfoo/bar)r   r    N)r   r&   strsortr   )r+   xitemsZp1Zp2r   r   r   test_string_compatibility|   s    z$TestBasics.test_string_compatibilityc             C   s   t ddd}t|}d}d}t ||d}|j|ks6t|jdksDt|jjt dddks\t|jd	ksjt|jjd
kszt|jt dd
dkstd S )Nz$C:\Program Files\Python\Lib\xyzzy.pyz/usr/local/python/lib/xyzzy.py)r   r    zC:\Program Files\Python\Libz/usr/local/python/libzxyzzy.pyZLiblibz.py zC:)r   r   parentr&   r
   ZextZdrive)r+   fZnt_libZ	posix_libexpectedr   r   r   test_properties   s    zTestBasics.test_propertiesc             C   sD   t tj t kstt  }t|t s0t|t ks@td S )N)r   r	   r'   abspathr)   r&   
isinstance)r+   r.   r   r   r   test_methods   s    zTestBasics.test_methodsc             C   sB   t tjdr>td}|jdks"t| tjt|ks>td S )Nsplituncz\\python1\share1\dir1\file1.txtz\\python1\share1)hasattrr	   pathr   Zuncsharer&   rI   r;   )r+   r   r   r   r   test_UNC   s    zTestBasics.test_UNCc             C   s~   t td}t td}t td}| dks:t| dksJt| dksZt|d dksjt|d dksztd	S )
zF
        The user may specify an explicit path module to use.
        zfoo\bar\bazzfoo/bar/bazzfoo\barzfoo/barrA   r"   zfoo\bar\baz\quuxzfoo/bar/baz/quuxN)r   using_modulentpath	posixpathdirnamer&   )r+   Znt_okZposix_okZposix_wrongr   r   r   test_explicit_module   s    zTestBasics.test_explicit_modulec             C   s.   t t}|t tkst|jdks*tdS )zT
        Multiple calls to path.using_module should produce the same class.
        ZPath_ntpathN)r   rM   rN   r&   __name__)r+   Znt_pathr   r   r   test_explicit_module_classes   s    
z'TestBasics.test_explicit_module_classesc             C   s*   t d}|d}|tdddks&td S )Nr!   r#   zfoo\barzfoo/bar)r   r    )r   joinpathr   r&   )r+   resfoo_barr   r   r   test_joinpath_on_instance   s    
z$TestBasics.test_joinpath_on_instancec             C   s   t d}| |kstd S )Nr!   )r   rT   r&   )r+   rU   r   r   r   test_joinpath_to_nothing   s    z#TestBasics.test_joinpath_to_nothingc             C   s$   t dd}|tdddks tdS )z)Construct a path from a series of stringsr!   r#   zfoo\barzfoo/bar)r   r    N)r   rT   r   r&   )r+   rV   r   r   r   test_joinpath_on_class   s    z!TestBasics.test_joinpath_on_classc             C   s.   yt   W n tk
r    Y n
X tddS )z,It doesn't make sense to join nothing at allzdid not raiseN)r   rT   r1   r2   )r+   r   r   r   test_joinpath_fails_on_empty   s
    z'TestBasics.test_joinpath_fails_on_emptyc             C   sJ   t t}|d}t||s"t|d}t||s:t|dksFtd S )Nr!   r#   zfoo/bar)r   rM   rO   rT   rG   r&   )r+   Z
path_posixrU   Zres2r   r   r   test_joinpath_returns_same_type   s    


z*TestBasics.test_joinpath_returns_same_typeN)rR   
__module____qualname__r0   r3   r6   r?   rE   rH   rL   rQ   rS   rW   rX   rY   rZ   r[   r   r   r   r   r   I   s   !		r   c               @   s&   e Zd Zejjejdddd ZdS )TestPerformancez+Tests fail frequently on Python 2; see #153)reasonc             C   sb   t jdddddddg}tj|dd}td	|d
}tjdd}tjt	|d}||k s^t
dS )z
        Import of path.py should take less than 100ms.

        Run tests in a subprocess to isolate from test suite overhead.
        z-mZtimeitz-nr5   z-rzimport pathT)Zuniversal_newlinesz(\d+) msec per loopr4   d   )ZmillisecondsN)sys
executable
subprocessZcheck_outputresearchgroupdatetimeZ	timedeltaintr&   )r+   r   cmdrU   ZdurlimitZdurationr   r   r   test_import_time   s    
z TestPerformance.test_import_timeN)	rR   r\   r]   pytestmarkskipifrK   ZPY2rk   r   r   r   r   r^      s   r^   c               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )TestSelfReturnz
    Some methods don't necessarily return any value (e.g. makedirs,
    makedirs_p, rename, mkdir, touch, chroot). These methods should return
    self anyhow to allow methods to be chained.
    c             C   s$   t |d }| }||ks tdS )z9
        Path('foo').makedirs_p() == Path('foo')
        newpathN)r   
makedirs_pr&   )r+   tmpdirr   retr   r   r   test_makedirs_p  s    zTestSelfReturn.test_makedirs_pc             C   s    t |}| }||kstd S )N)r   rq   r&   )r+   rr   r   rs   r   r   r   test_makedirs_p_extant  s    z%TestSelfReturn.test_makedirs_p_extantc             C   s:   t |d }|  t |d }||}||ks6td S )NZsomefileZ	otherfile)r   touchrenamer&   )r+   rr   r   r   rs   r   r   r   test_rename  s
    
zTestSelfReturn.test_renamec             C   s$   t |d }| }||ks td S )NZnewdir)r   mkdirr&   )r+   rr   r   rs   r   r   r   
test_mkdir!  s    zTestSelfReturn.test_mkdirc             C   s$   t |d }| }||ks td S )Nz
empty file)r   rv   r&   )r+   rr   r   rs   r   r   r   
test_touch&  s    zTestSelfReturn.test_touchN)	rR   r\   r]   __doc__rt   ru   rx   rz   r{   r   r   r   r   ro     s   ro   c               @   s   e Zd ZdZdd Zdd Zdd Zejj	e
dd	d
ejj	e dkoLejdd
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jeejd dd
dd  Zd!d" Zd#d$ Zd%d& Zd'S )(TestScratchDirzO
    Tests that run in a temporary directory (does not test TempDir class)
    c          	   C   s\   t |}|d }|  t }| t tj|ks>tW dQ R X t |ksXtdS )z)Can be used as context manager for chdir.subdirN)r   makedirsr	   r)   rK   realpathr&   )r+   rr   r/   r~   Zold_dirr   r   r   test_context_manager0  s    "z#TestScratchDir.test_context_managerc             C   s  d}t |}|d }t | }|  t | }| s@t| sLt|jdksZt||j  krp|ksvn ttt	j
dr|j}||  kr|ksn tt|d  t|d}|dd |  t|d  t | }	|  t | }
||  kr$|	  k r$|
ks*n t| s8t| sFt|jd	ksVt|	|j  krp|
ksvn ttt	j
dr|j}t	jd
kr||kst||	k stn"||ks|t|jdkstd S )Nr4   ztest.txtr   getctime   Zabz
some byteszutf-8
   r   gMbP?)r   timerv   existsr&   isfilesizemtimerJ   r	   rK   ZctimeZsleepopenwriteencodecloser
   rl   Zapprox)r+   rr   Z	thresholdr/   rC   Zt0Zt1ZctfobjZt2Zt3Zct2r   r   r   r{   :  sB    
* 
zTestScratchDir.test_touchc                s  t |   g kstd} | }|tj |ks:t|  z| sPt  |gksbt d|gksvt d|gkst d|gkst d|gkst d|gkst dg kst dg kstt	 
d dkstt 
dtjs tW d |  X  fdd	td
D }x*|D ]"}t|d}|d |  qJW z*  }|  |  ||kstW d x2|D ]*}y|  W n tk
r   Y nX qW X d S )Nztestfile.txtz	test*.txtz*.txtz*txt*z*.htmlZtestfilec                s   g | ]} d |  qS )z%d.txtr   ).0i)r/   r   r   
<listcomp>  s    z/TestScratchDir.test_listing.<locals>.<listcomp>   wz
some text
)r   listdirr&   r	   rK   joinrv   r   ZgloblistZiglobrG   typesGeneratorTyperemoveranger   r   r   r<   r2   )r+   rr   rC   Zaffilesr   Zfiles2r   )r/   r   test_listingp  sD    




zTestScratchDir.test_listingz10.13z!macOS disallows invalid encodings)r_   ZWindowsz&Can't write latin characters. See #133c          	   C   s   t | g kstt|d}dd}tj||}t|d W dQ R X t|s^tt | }t	|dkszt|\}t
|t stt dkr| dkstdS t	| t	|kstdS )	z
        Some filesystems allow non-character sequences in path names.
        ``.listdir`` should still function in this case.
        See issue #61 for details.
        asciiu   réñemizlatin-1wbNr4   r   z
r%E9%F1emi)r   r   r&   r;   r   r	   rK   r   r   lenrG   r   r   basename)r+   rr   Ztmpdir_bytesfilenamepathnameZresultsrU   r   r   r   test_listdir_other_encoding  s    

z*TestScratchDir.test_listdir_other_encodingc          	   C   s   t |}|d }|  z|d }|d d d }|  z| sHtW d |  X | rbt| snt|d |d z| stW d |  X | rt| stW d t	| X d S )Nztemp.txtr!   r#   Zbazr-   i  i  )
r   rv   r   isdirr&   
removedirsr   ry   r	   r   )r+   rr   r/   Ztempfr!   r-   r   r   r   test_makedirs  s(    



zTestScratchDir.test_makedirsc             C   sD   i }x|D ]}d ||< q
W i }x|D ]}d ||< q$W ||ks@t d S )N)r&   )r+   abZadr   Zbdr   r   r   assertSetsEqual  s    

zTestScratchDir.assertSetsEqualc             C   s  t |}|d }|d }|d }|d }|d }|d }|d }	|	|| }
|  |  |  t|d}|d	d
  |  || | st|	 |	 kst||j
 }|| | st|	 |	 kstttdr|| n
|| ||	 |	 st| |	 |	|j
 |	|j
 |
g |
 rLt|	  |	 rbt||	d |	 s|t| |	 |	|j
 |	|j
 |
g ttdr|
 st|
 |kst|  | rt| | g  d S )NZtestdirztestfile.txtr8   ztestcopy.txtztestlink.txtr9   Cr   r=   i'  symlinkT)r   r%   ry   r   r   r   copyfiler   r&   bytesr
   copyrJ   r	   r   copytreer   r   r   islinkrmtreer   readlink
assertList)r+   rr   r/   ZtestDirZtestFileZtestAZtestCopyZtestLinkZtestBZtestCZtestCopyOfLinkrC   Z	testCopy2r   r   r   test_shutil  s`    






zTestScratchDir.test_shutilc             C   s   t |t |kstd S )N)sortedr&   )r+   ZlistingrD   r   r   r   r   4  s    zTestScratchDir.assertListc                sF  t | dddddg  d  d  d d g}x6|D ].}| sL|  xD ]}||   qRW q8W |  d	 d  d g |  d	 d g |  d	 d g |    fd
d|D fdd|D   |  d	dd |D  d g  |  	d	dd |D  |  
d	 d g d S )Nzx.tmpzx.xtmpZx2gZx22zx.txtZxdirzxdir.tmpZxsubdirz*.tmpc                s   g | ]}| kr|qS r   r   )r   e)r/   r   r   r   E  s    z0TestScratchDir.test_patterns.<locals>.<listcomp>c                s   g | ]} D ]}|| qqS r   r   )r   r   n)namesr   r   r   F  s    c             S   s   g | ]}|d  qS )zx.tmpr   )r   r   r   r   r   r   I  s    c             S   s   g | ]}|d  qS )zx.tmpr   )r   r   r   r   r   r   J  s    )r   r   r   rv   r   r   r   dirswalk	walkfileswalkdirs)r+   rr   r   r   r
   r   )r/   r   r   test_patterns7  s"    

zTestScratchDir.test_patternsc                s@   t |}|d   fdd}|d |d |d |d d S )Nzunicode.txtc       
         s  d}d}ddddddgdd	d	d	d
dg}ddddddg}t d}|| |   |ksnt|kst|kstjdd|kstdkrdS |d
  	  j	 dd d 
d
tj }|dd }|d  d
7  <  |kstd  ks6td| ksNtjddd| ksjt| j|dd  |kst jdd  |kst fdd}|d
 |d |d |d jdd jddd d| } |ks:td| ksRt|dd }	|	d  |d 7  < |	|dd 7 }	|	kstdS )z Test that path works with the specified encoding,
            which must be capable of representing the entire range of
            Unicode codepoints.
            u?   Hello world
ഊ਍കਕ
ഊ਍കਕഊ਍കਕ hangingu;   Hello world
ഊ਍കਕ
ഊ਍കਕ
ഊ਍കਕ

hangingzHello world
u   ഊ਍കਕ
u   ഊ਍കਕu   ഊ਍കਕ Zhangingu   ഊ਍കਕ

zHello worldu   ഊ਍കਕrA   r   F)ZretainzUTF-16NT)appendr   c                sL   j | d j | dd d d|  } |ksHtd S )N)linesepT)r   r   r   r   )write_linesreplacer   r   r&   )ZeolrD   )cleanNoHangingenc
givenLinesr   r   r   testLinesep  s    z>TestScratchDir.test_unicode.<locals>.test.<locals>.testLinesepz
u   )r   )r   r   r   r4   )codecsr   r   r   r   r   r&   textlines
write_textr   r	   r   r   )
r   ZgivenZcleanZexpectedLinesZexpectedLines2rC   ZexpectedBytesZexpectedLinesNoHangingr   ZexpectedResultLines)r   )r   r   r   r   testQ  sx    
z)TestScratchDir.test_unicode.<locals>.testzUTF-8zUTF-16BEzUTF-16LEzUTF-16)r   )r+   rr   r/   r   r   )r   r   test_unicodeM  s    wzTestScratchDir.test_unicodec             C   sx   t  d  }d}d}|| x:t||D ](\}}|||| || |  ks0tq0W |t|| d ksttd S )Nztest.txt
0123456789   r4   )r   rv   r   	enumerateZchunksr&   r   )r+   rr   r   Ztxtr   r   chunkr   r   r   test_chunks  s    
$zTestScratchDir.test_chunkssamefilezsamefile not presentc             C   s   t  d  }|d t  d  }|d t  d  }|d t  d }|| tj||||ksxttj||||ksttj||||ksttj||||kstd S )Nz1.txtr!   z2.txtz3.txtr#   z4.txt)r   rv   r   r   r	   rK   r   r&   )r+   rr   f1f2Zf3Zf4r   r   r   test_samefile  s    




zTestScratchDir.test_samefilec             C   sj   t |}|d }|  |d d |  | r:ty|  W n tk
rd   | d Y nX d S )N	subfolderZafileZ	somethingzKCalling `rmtree_p` on non-existent directory should not raise an exception.)r   ry   r   Zrmtree_pr   r&   OSErrorZfail)r+   rr   r/   subr   r   r   test_rmtree_p  s    zTestScratchDir.test_rmtree_pc             C   s0   t |}|d }|  |  | r,tdS )ze
        Invocation of rmdir_p on an existant directory should
        remove the directory.
        r   N)r   ry   rmdir_pr   r&   )r+   rr   r/   r   r   r   r   test_rmdir_p_exists  s
    z"TestScratchDir.test_rmdir_p_existsc             C   s(   t |}|d }| rt|  dS )zD
        A non-existent file should not raise an exception.
        r   N)r   r   r&   r   )r+   rr   r/   r   r   r   r   test_rmdir_p_nonexistent  s    z'TestScratchDir.test_rmdir_p_nonexistentN)rR   r\   r]   r|   r   r{   r   rl   rm   xfailr   r   r   rK   ZPY3r   r   r   r   r   r   r   r   rn   rJ   r	   r   r   r   r   r   r   r   r   r}   ,  s0   
6/H 
r}   c               @   sP   e Zd Zejdddd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd ZdS )TestMergeTreeT)r   c          	   C   s   t || _| jd | _| jd | _| jd | _| jd | _| j  | j  t| jd}|dd  W d Q R X t	t
dr| j| j n| j| j d S )	Nr8   ztestfile.txtztestlink.txtr9   r   r=   i'  r   )r   Ztest_dirsubdir_a	test_file	test_linksubdir_bry   r   r   rJ   r	   r   r   )r+   rr   rC   r   r   r   testing_structure  s    



zTestMergeTree.testing_structurec             C   s6   t | j| jj }ttdr"|jn|j}| s2td S )Nr   )	r   r   r   r
   rJ   r	   r   r   r&   )r+   r   Zcheckr   r   r   
check_link   s    zTestMergeTree.check_linkc             C   sb   | j j| jdd | j s tt| j| jj | j| jj f}t| j	 |ksVt| 
  d S )NT)Zsymlinks)r   
merge_treer   r   r&   setr   r
   r   r   r   )r+   rD   r   r   r    test_with_nonexisting_dst_kwargs%  s    z.TestMergeTree.test_with_nonexisting_dst_kwargsc             C   s`   | j | jd | j stt| j| jj | j| jj f}t| j	 |ksTt| 
  d S )NT)r   r   r   r   r&   r   r   r
   r   r   r   )r+   rD   r   r   r   test_with_nonexisting_dst_args/  s    z,TestMergeTree.test_with_nonexisting_dst_argsc          	   C   s   | j   | j| j d | j  | jd }|  t| jd}|	dd  W d Q R X | j
| j d | j  sztt| j | jj | j | jj | j |j f}t| j  |kst|   tt| j | jj  dkstd S )NTznewfile.txtr   r=   i  )r   r   r   r   r   r   rv   r   r   r   r   r   r&   r   r
   r   r   r   r   r   )r+   Ztest_newrC   rD   r   r   r   test_with_existing_dst9  s     


z$TestMergeTree.test_with_existing_dstc             C   sL   t d}| jj| j|d | j s*t| j | j| jj	 gksHtdS )zS
        merge_tree should accept parameters to copytree, such as 'ignore'
        z	testlink*)ignoreN)
shutilZignore_patternsr   r   r   r   r&   r   r   r
   )r+   r   r   r   r   test_copytree_parametersO  s    
z&TestMergeTree.test_copytree_parametersc             C   sB   | j d }|d | jj| j ttjd | dks>t	dS )z
        merge_tree should accept a copy_function in which only
        newer files are copied and older files do not overwrite
        newer copies in the dest.
        ztestfile.txtzthis is newer)Zcopy_functionN)
r   r   r   r   rK   Z
only_newerr   Zcopy2r   r&   )r+   r   r   r   r   test_only_newerY  s    

zTestMergeTree.test_only_newerN)rR   r\   r]   rl   fixturer   r   r   r   r   r   r   r   r   r   r   r     s   


r   c               @   s   e Zd Zdd ZdS )	TestChdirc             C   s   t t|}| }t|t|ks(t|  t| t|ksHtt |}t| t|ksht|  t| t|kstt| t|kstdS )z tests the chdir or cd method N)r   r;   r)   r&   chdirZcd)r+   rr   r/   r.   r   r   r   test_chdir_or_cdi  s    zTestChdir.test_chdir_or_cdN)rR   r\   r]   r   r   r   r   r   r   h  s   r   c               @   s   e Zd Zdd ZdS )TestSubclassc             C   s2   G dd dt }|d}|d }t||s.tdS )z{
        When operations are invoked on a subclass, they should produce another
        instance of that subclass.
        c               @   s   e Zd ZdS )zDTestSubclass.test_subclass_produces_same_class.<locals>.PathSubclassN)rR   r\   r]   r   r   r   r   PathSubclass  s   r   z/foor#   N)r   rG   r&   )r+   r   r   r~   r   r   r   !test_subclass_produces_same_class  s    z.TestSubclass.test_subclass_produces_same_classN)rR   r\   r]   r   r   r   r   r   r     s   r   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestTempDirc             C   sF   t  }t|tjst| s"t| s.t|  | rBtdS )zO
        One should be able to readily construct a temporary directory
        N)r   rG   rK   r   r&   r   r   rmdir)r+   r/   r   r   r   test_constructor  s    zTestTempDir.test_constructorc             C   s*   t  }|d }t|tjst|  dS )zg
        It should be possible to invoke operations on a TempDir and get
        Path classes.
        r~   N)r   rG   rK   r   r&   r   )r+   r/   r   r   r   r   test_next_class  s    zTestTempDir.test_next_classc             C   s\   t  }| }|t|ks t|d   t|d t r>t|ddd | rXtdS )zz
        One should be able to use a TempDir object as a context, which will
        clean up the contents after.
        zsomefile.txtN)	r   	__enter__rK   r   r&   rv   rG   __exit__r   )r+   r/   rU   r   r   r   r     s    z TestTempDir.test_context_managerc             C   sN   t  }|  |d   t|d t r,t|ttdd | sJtdS )zO
        The context manager will not clean up if an exception occurs.
        zsomefile.txtr!   N)r   r   rv   rG   r&   r   r1   r   )r+   r/   r   r   r   test_context_manager_exception  s    z*TestTempDir.test_context_manager_exceptionc          	   C   s.   t  }| stW dQ R X | r*tdS )z
        The context manager will allow using the with keyword and
        provide a temporry directory that will be deleted after that.
        N)r   r   r&   )r+   r/   r   r   r   test_context_manager_using_with  s    z+TestTempDir.test_context_manager_using_withN)rR   r\   r]   r   r   r   r   r   r   r   r   r   r     s
   
r   c               @   s(   e Zd Zejdddd Zdd ZdS )TestUnicodeT)r   c             C   s   t |d  d S )Nu   ☃)r   rT   ry   )r+   rr   r   r   r   unicode_name_in_tmpdir  s    z"TestUnicode.unicode_name_in_tmpdirc             C   s   xt | D ]}qW d S )N)r   r   )r+   rr   rU   r   r   r   test_walkdirs_with_unicode_name  s    z+TestUnicode.test_walkdirs_with_unicode_nameN)rR   r\   r]   rl   r   r  r  r   r   r   r   r     s   r   c               @   sT   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S )TestPatternMatchingc             C   s(   t d}|dst|ds$td S )NFooBarzFoo*z
Foo[ABC]ar)r   fnmatchr&   )r+   r   r   r   r   test_fnmatch_simple  s    z'TestPatternMatching.test_fnmatch_simplec             C   s.   t d}t|_|dst|ds*td S )Nr  foobarz
FOO[ABC]AR)r   rN   moduler  r&   )r+   r   r   r   r   test_fnmatch_custom_mod  s    z+TestPatternMatching.test_fnmatch_custom_modc             C   s8   dd }t d}|jd|ds"t|jd|ds4td S )Nc             S   s   |   S )N)upper)rK   r   r   r   r(     s    zBTestPatternMatching.test_fnmatch_custom_normcase.<locals>.normcaser  r  )r(   z
FOO[ABC]AR)r   r  r&   )r+   r(   r   r   r   r   test_fnmatch_custom_normcase  s    z0TestPatternMatching.test_fnmatch_custom_normcasec             C   s*   t d}t| ttdks&td S )N.)r   r   r   r	   r&   )r+   r   r   r   r   test_listdir_simple  s    z'TestPatternMatching.test_listdir_simplec             C   s   t d}|dg kstd S )Nr  rA   )r   r   r&   )r+   r   r   r   r   test_listdir_empty_pattern  s    z.TestPatternMatching.test_listdir_empty_patternc             C   sR   t |}|d   |d   |d|d gks8tt|ddksNtd S )Nr   Filezs*r   r   )r   ry   rv   r   r&   r   )r+   rr   r   r   r   r   test_listdir_patterns  s
    z)TestPatternMatching.test_listdir_patternsc             C   s   t t}||}|d   |d   |dg ks<tt t}||}|d|d gksft|d|d gks~tdS )zx
        Listdir patterns should honor the case sensitivity of the path module
        used by that Path class.
        r   r  zS*zf*N)r   rM   rO   ry   rv   r   r&   rN   )r+   rr   Zalways_unixr   Z
always_winr   r   r   test_listdir_custom_module  s    

z.TestPatternMatching.test_listdir_custom_modulec             C   s   t |}|d   |d   |td|d gks>t|td|d gks\t|tdg kstt|tdg kstdS )zx
        Listdir patterns should honor the case sensitivity of the path module
        used by that Path class.
        r   r  zS*zf*N)	r   ry   rv   r   r   CaseInsensitiver&   r   r   )r+   rr   r   r   r   r   test_listdir_case_insensitive  s    z1TestPatternMatching.test_listdir_case_insensitivec             C   s   t |}|d d   |d d   |d d d   |d d d   |d d d   t|td}t|dkst|d d d |kst|d d d |kstd S )	NZsub1r!   Zsub2zbar.Txtzbar.TXTzbar.txt.bz2z*.txtr   )	r   rq   rv   r   r   r   r  r   r&   )r+   rr   r   r   r   r   r   test_walk_case_insensitive  s    z.TestPatternMatching.test_walk_case_insensitiveN)rR   r\   r]   r  r	  r  r  r  r  r  r  r  r   r   r   r   r    s   r  )r      z)in_place requires io module in Python 2.6)r_   c               @   sR   e Zd Zed Zed Zed Ze	dd Z
dd Zdd	 Zd
S )TestInPlacez?
        The quick brown fox jumped over the lazy dog.
        z?
        .god yzal eht revo depmuj xof nworb kciuq ehT
        a
  
          Lorem ipsum dolor sit amet, consectetur adipisicing elit,
        sed do eiusmod tempor incididunt ut labore et dolore magna
        aliqua. Ut enim ad minim veniam, quis nostrud exercitation
        ullamco laboris nisi ut aliquip ex ea commodo consequat.
        Duis aute irure dolor in reprehenderit in voluptate velit
        esse cillum dolore eu fugiat nulla pariatur. Excepteur
        sint occaecat cupidatat non proident, sunt in culpa qui
        officia deserunt mollit anim id est laborum.
        c          	   C   s2   t |d }|d}|| j W d Q R X |S )NZdocumentr   )r   r   r   reference_content)clsrr   r   streamr   r   r   create_reference7  s    zTestInPlace.create_referencec       	   	   C   s~   |  |}| 8\}}x,|D ]$}dt| d }|| qW W d Q R X | }| }W d Q R X || jkszt	d S )NrA   r   )
r  in_placer   reversedstripr   r   readreversed_contentr&   )	r+   rr   docreaderwriterlineZr_liner  datar   r   r   test_line_by_line_rewrite>  s    


z%TestInPlace.test_line_by_line_rewritec          
   C   s   |  |}tt2}| \}}|| j tdW d Q R X W d Q R X dt|ks\t|	 }|
 }W d Q R X d|kstd|kstd S )Nz
some errorZLoremzlazy dog)r  rl   ZraisesRuntimeErrorr  r   alternate_contentr;   r&   r   r  )r+   rr   r   excr!  r"  r  r$  r   r   r   test_exception_in_contextI  s    

z%TestInPlace.test_exception_in_contextN)rR   r\   r]   textwrapdedentlstripr  r  r'  classmethodr  r%  r)  r   r   r   r   r  !  s   

	
r  c               @   sh   e Zd Zejddddd Zej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 )TestSpecialPathsTclass)r   Zscopec             C   s   t d d S )Nappdirs)rl   Zimportorskip)r  r   r   r   appdirs_installedW  s    z"TestSpecialPaths.appdirs_installedc             C   s8   | ddd  | dd | dd tjd d S )	Nzplatform.systemc               S   s   dS )NZLinuxr   r   r   r   r   <lambda>]  s    z.TestSpecialPaths.feign_linux.<locals>.<lambda>zsys.platformZlinuxz
os.pathsep:r0  )setattrra   modulespop)r+   r   r   r   r   feign_linux[  s    zTestSpecialPaths.feign_linuxc             C   sj   t d}| }ttjj|ks&t| }ttj	j|ksBt|dd}ttddjj|ksftd S )Nr0  zMy AppZMe)
	importlibimport_moduleuser_config_dirr   r   userconfigr&   Zsite_config_dirsite)r+   r0  rD   r   r   r   test_basic_pathsd  s    
z!TestSpecialPaths.test_basic_pathsc             C   s@   |d }| tjdt| t|d }ttjj|ks<td S )NZ_configXDG_CONFIG_HOME)	r   r	   environr;   r   r   r;  r<  r&   )r+   rr   r   r7  Zfake_configrD   r   r   r   test_unix_pathsp  s    z TestSpecialPaths.test_unix_pathsc             C   sR   |d }|j tjddd |tjdt| td }ttjj	|ksNt
dS )z6Without XDG_CONFIG_HOME set, ~/.config should be used._homer?  F)ZraisingHOMEz	~/.configN)delitemr	   r@  r   r;   r   
expanduserr   r;  r<  r&   )r+   rr   r   r7  Z	fake_homerD   r   r   r   test_unix_paths_fallbackv  s
    z)TestSpecialPaths.test_unix_paths_fallbackc             C   sF   t t jjtstt t jjts,tt t jjtsBtd S )N)rG   r   specialr;  r<  r&   r$  cache)r+   r   r   r   test_property~  s    zTestSpecialPaths.test_propertyc             C   s$   t jdddjj}t|t s tdS )zP
        Other parameters should be passed through to appdirs function.
        z1.0T)r   	multipathN)r   rG  r=  r<  rG   r&   )r+   rU   r   r   r   test_other_parameters  s    z&TestSpecialPaths.test_other_parametersc             C   s   t |d }t |d }tj||g}|tjd| tjddjj	}t
|tsVt||ksbt||ksntdt |ks~tdS )zO
        If multipath is provided, on Linux return the XDG_CONFIG_DIRS
        Z_config1Z_config2ZXDG_CONFIG_DIRST)rJ  N)r;   r	   pathsepr   r   r@  r   rG  r=  r<  rG   r   r&   )r+   r7  r   rr   Zfake_config_1Zfake_config_2Zconfig_dirsrU   r   r   r   test_multipath  s    zTestSpecialPaths.test_multipathc             C   s:   t d}ttdd}|jj}|jdd}||ks6tdS )z
        Passing additional args and kwargs to SpecialResolver should be
        passed through to each invocation of the function in appdirs.
        r0  z1.0)r   N)r8  r9  r   r   r;  r<  r:  r&   )r+   r0  ZadprU   rD   r   r   r   test_reused_SpecialResolver  s
    
z,TestSpecialPaths.test_reused_SpecialResolverN)rR   r\   r]   rl   r   r1  r7  r>  rA  rF  rI  rK  rM  rN  r   r   r   r   r.  V  s   	r.  c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestMultiPathc             C   sB   t t}t|tstt|t s&tdtj }|j|ks>tdS )zV
        Multi.for_class should return a subclass of the Path class provided.
        r   N)r   	for_classr   
issubclassr&   rR   )r+   r  Zexpected_namer   r   r   test_for_class  s
    

zTestMultiPath.test_for_classc             C   s0   t td}t|tstt|t r,tdS )z
        If no pathsep is provided, multipath detect should return an instance
        of the parent class with no Multi mix-in.
        z/foo/barN)r   rP  r   detectrG   r&   )r+   rK   r   r   r   test_detect_no_pathsep  s    z$TestMultiPath.test_detect_no_pathsepc             C   s2   d}t j|}tt|}t|ts.tdS )z~
        If a pathsep appears in the input, detect should return an instance
        of a Path with the Multi mix-in.
        )z/foo/barz	/baz/bingN)	r	   rL  r   r   rP  r   rS  rG   r&   )r+   inputsinputrK   r   r   r   test_detect_with_pathsep  s    z&TestMultiPath.test_detect_with_pathsepc             C   sx   d}t j|}tt|}t|}t|}|dks<t	t
|tsJt	t
|trXt	t|dksht	||kstt	dS )z`
        Iterating over a MultiPath should yield instances of the
        parent class.
        )z/foo/barz	/baz/bingz/foo/barz	/baz/bingN)r	   rL  r   r   rP  r   rS  iternextr&   rG   )r+   rU  rV  rK   r>   firstr   r   r   test_iteration  s    zTestMultiPath.test_iterationN)rR   r\   r]   rR  rT  rW  r[  r   r   r   r   rO    s   
	rO  zpath.PY2zPython 2 has no __future__c              C   s   t jdddg} t|  dS )zw
    Path.py guarantees that the path module can be
    transplanted into an environment without any dependencies.
    z-Sz-czimport pathN)ra   rb   rc   Z
check_call)ri   r   r   r   test_no_dependencies  s    r\  c               C   s   t dtjstdS )zL
    Under normal circumstances, path should present a
    __version__.
    z
\d+\.\d+.*N)rd   matchrK   __version__r&   r   r   r   r   test_version  s    r_  )5r|   Z
__future__r   r   r   r   r	   ra   r   r   r   rN   rO   r*  r   r8  operatorrg   rc   rd   rl   Zpackaging.versionr   rK   r   r   r   r   r   r   r   r   ger   r   r^   ro   r}   r   r   r   r   r   r  rm   rn   version_infor  r.  rO  r   r\  r_  r   r   r   r   <module>   s`    '%   c\:L3P1