U
    
W[                     @   sd   d Z ddlmZ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 dd ZG d	d
 d
eZdS )z0
Test cases covering L{twisted.python.zippath}.
    )absolute_importdivisionN)AbstractFilePathTests)
ZipArchive)_coerceToFilesystemEncodingc           	   	   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   zipfileZZipFileoswalkpathjoinlenwrite)	dirnameZzfnameZzfrootZignoredfilesfnamefspathZarcpath r   B/usr/lib/python3/dist-packages/twisted/python/test/test_zippath.pyzipit   s    

r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ZipFilePathTestszk
    Test various L{ZipPath} path manipulations as well as reprs for L{ZipPath}
    and L{ZipArchive}.
    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>-   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tj | jd tj d f }| 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.
        fooZipPath(%r).zipr   r	   N)r   childr   abspathr#   sepassertEqualreprr   getcwdr   )r    r(   pathReprrelativeCommonrelpathr   r   r   test_zipPathRepr1   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..Zbarr&   r'   r   N)r   r(   r#   r   r*   r   r+   r,   )r    r(   r.   r   r   r    test_zipPathReprParentDirSegmentG   s
    z1ZipFilePathTests.test_zipPathReprParentDirSegmentc                 C   sp   t | jd }dtj| jd f }| 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#   r   r   r)   r+   r,   r   r-   r*   )r    r   r.   r/   r0   r   r   r   test_zipArchiveReprS   s     z$ZipFilePathTests.test_zipArchiveReprN)__name__
__module____qualname____doc__r"   r1   r2   r3   r   r   r   r   r   "   s
   
r   )r7   Z
__future__r   r   r   r
   Ztwisted.test.test_pathsr   Ztwisted.python.zippathr   Ztwisted.python.filepathr   r   r   r   r   r   r   <module>   s   