U
     T‚g?  ã                   @  sz   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddd	d
œdd„ZG dd„ deƒZdS )z0
Test cases covering L{twisted.python.zippath}.
é    )ÚannotationsN)ÚUnion)Ú_coerceToFilesystemEncoding)Ú
ZipArchiveÚZipPath)ÚAbstractFilePathTestszstr | bytesÚNone)ÚdirnameÚzfnameÚreturnc              	   C  sˆ   t d| ƒ}t d|ƒ}t |d¡�^}t |¡D ]L\}}}|D ]<}tj ||¡}	tj ||¡t| ƒd d… }
| |	|
¡ q:q,W 5 Q R X dS )zI
    Create a zipfile on zfname, containing the contents of dirname'
    Ú Úwé   N)	r   ÚzipfileÚZipFileÚosÚwalkÚpathÚjoinÚlenÚwrite)r	   r
   ZcoercedDirnameZcoercedZfnameÚzfÚrootZignoredÚfilesÚfnameÚfspathZarcpath© r   úD/tmp/pip-unpacked-wheel-1_7di8ic/twisted/python/test/test_zippath.pyÚzipit   s    

ür   c                   @  sh   e Zd ZU dZded< ded< ddœdd„Zddœd	d
„Zddœdd„Zddœdd„Zddœdd„Z	dS )ÚZipFilePathTestszk
    Test various L{ZipPath} path manipulations as well as reprs for L{ZipPath}
    and L{ZipArchive}.
    zZipArchive[bytes]r   r   r   )r   c                   s\   t  ˆ ¡ tˆ jˆ jd ƒ tdˆ jƒˆ _tˆ jd ƒˆ _ˆ jˆ _‡ fdd„ˆ j	D ƒˆ _	d S )Nó   .zipr   c                   s    g | ]}|  ˆ jˆ jd  ¡‘qS )r    )ÚreplaceÚcmn)Ú.0Úx©Úselfr   r   Ú
<listcomp>4   s     z*ZipFilePathTests.setUp.<locals>.<listcomp>)
r   ÚsetUpr   r"   r   Ú	nativecmnr   r   r   Úallr%   r   r%   r   r(   .   s    
zZipFilePathTests.setUpc                 C  s&   |   | j d¡ d¡| j d¡¡ dS )zF
        L{ZipPath.sibling} returns a path at the same level.
        ZoneZtwoN)ÚassertEqualr   ÚchildZsiblingr%   r   r   r   Útest_sibling6   s    zZipFilePathTests.test_siblingc                 C  s‚   | j  d¡}d tj  | jd tj d ¡¡}|  t|ƒ|¡ | j 	t 
¡ tj dd¡d }t|ƒ}| d¡}|  t|ƒ|¡ dS )z„
        Make sure that invoking ZipPath's repr prints the correct class name
        and an absolute path to the zip file.
        ÚfoozZipPath({!r})ú.zipr   r   N)r   r,   Úformatr   Úabspathr)   Úsepr+   Úreprr!   Úgetcwdr   )r&   r,   ÚpathReprÚrelativeCommonÚrelpathr   r   r   Útest_zipPathRepr<   s    ÿ
z!ZipFilePathTests.test_zipPathReprc                 C  sN   | j  d¡ d¡ d¡}d| jd tj ddddg¡  }|  t|ƒ|¡ dS )z³
        The repr of a ZipPath with C{".."} in the internal part of its path
        includes the C{".."} rather than applying the usual parent directory
        meaning.
        r.   z..ÚbarzZipPath(%r)r/   r   N)r   r,   r)   r   r2   r   r+   r3   )r&   r,   r5   r   r   r   Ú test_zipPathReprParentDirSegmentQ   s
    ÿz1ZipFilePathTests.test_zipPathReprParentDirSegmentc                 C  sp   t | jd ƒ}d tj | jd ¡¡}|  t|ƒ|¡ | j t 	¡ tj
 dd¡d }t |ƒ}|  t|ƒ|¡ dS )z‡
        Make sure that invoking ZipArchive's repr prints the correct class
        name and an absolute path to the zip file.
        r/   zZipArchive({!r})r   r   N)r   r)   r0   r   r   r1   r+   r3   r!   r4   r2   )r&   r   r5   r6   r7   r   r   r   Útest_zipArchiveRepr]   s    z$ZipFilePathTests.test_zipArchiveReprN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r(   r-   r8   r:   r;   r   r   r   r   r   %   s   
r   )r?   Ú
__future__r   r   r   Útypingr   Ztwisted.python.filepathr   Ztwisted.python.zippathr   r   Ztwisted.test.test_pathsr   r   r   r   r   r   r   Ú<module>   s   