B
    u9a\                 @   s0  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dddd	d
dddg
Zej	dkrve
dddddddddg	 e jjse ZyxeD ]Zee qW W n ek
r   edY nX G dd dejZG dd deZG dd deZG dd  d eZG d!d" d"eZd#d$ Zed%kr,e  dS )&    N)	normalize)supportZ1_abcZ2_asciiu   3_Grüß-Gottu   4_Γειά-σαςu   5_Здравствуйтеu   6_にぽんu   7_השקצץסu   8_曨曩曫u   9_曨שんдΓßu	   10_΅´darwinu	   11_΅ϓϔu   12_΅ϓϔu   13_ ̈́ΎΫu   14_ẛ῁῍῎῏῝῞῟῭u   15_΅´𣏕u   16_   Au   17_   Au   18_   Az19_   Az>only NT+ and systems with Unicode-friendly filesystem encodingc               @   s   e Zd ZeeZdZdd Zdd Ze	dfddZ
d	d
 ZejdkrNee	fZneZdd Zeejdkddd Zeejdkddd Zdd Zdd ZdS )UnicodeFileTestsNc          
   C   s   yt tj W n tk
r$   Y nX | tjtj t }xb| jD ]X}t j	
tj| |}t|d}||d d W d Q R X t | || qDW || _d S )Nwb
zutf-8)osmkdirr   TESTFNFileExistsErrorZ
addCleanupZrmtreesetfilespathjoinnormopenwriteencodestatadd)selfr   namef r   1/usr/lib/python3.7/test_unicode_file_functions.pysetUp?   s    
zUnicodeFileTests.setUpc             C   s   | j rt| j |S |S )N)normal_formr   )r   sr   r   r   r   O   s    zUnicodeFileTests.normTc          	   C   sH   |  |}|| W d Q R X |jj}|rD| ||d|j||f  d S )Nz>Function '%s(%a) failed with bad filename in the exception: %a)ZassertRaisesZ	exceptionfilenameassertEqual__name__)r   fnr   Zexpected_exceptionZcheck_filenamecZexc_filenamer   r   r   _apply_failureT   s    
zUnicodeFileTests._apply_failurec             C   sn   xh| j D ]^}d| }| t| | tj| | tj| | tj| | tj| | tj| qW d S )Nnot_)	r   r#   r   r   r   chdirrmdirremovelistdir)r   r   r   r   r   test_failures_   s    zUnicodeFileTests.test_failureswin32c             C   sV   xP| j D ]F}t|d}||d d |  t| | tj|| j	 qW d S )Nr   r   zutf-8)
r   r   r   r   closer   r   r#   r(   _listdir_failure)r   r   r   r   r   r   	test_openp   s    

zUnicodeFileTests.test_openr   zirrelevant test on Mac OS Xc                s   t | j}t  }x2t ddddgD ] |t  fdd|D O }q"W ||8 }x^|D ]V}| t| | tj| | tj| | tj| | tj| | tj	| qRW d S )NNFCNFDNFKCNFKDc             3   s   | ]}t  |V  qd S )N)r   ).0file)nfr   r   	<genexpr>   s    z2UnicodeFileTests.test_normalize.<locals>.<genexpr>)
r   r   r#   r   r   r   r%   r&   r'   r(   )r   r   Zothersr   r   )r4   r   test_normalize|   s    

zUnicodeFileTests.test_normalizec          	   C   s   t | j}t ( tdt ttj	
t }W d Q R X ttj	}t dd |D }| ||d||f  | t|t| d S )Nignorec             s   s   | ]}t jtj|V  qd S )N)r   r   r   r   r
   )r2   r   r   r   r   r5      s    z0UnicodeFileTests.test_listdir.<locals>.<genexpr>z%a != %a)r   r   warningscatch_warningssimplefilterDeprecationWarningr   r(   r   r
   r   sysgetfilesystemencodingr   len)r   Zsf0f1f2Zsf2r   r   r   test_listdir   s    

 zUnicodeFileTests.test_listdirc             C   s,   x&| j D ]}t|d td| qW d S )NZtmp)r   r   rename)r   r   r   r   r   test_rename   s    zUnicodeFileTests.test_renamec          
   C   sp   t jtjd}d}t|H t|d}||d d W d Q R X t 	|t j
 t | W d Q R X d S )Nu   Grüß-曨曩曫u   ß-曨曩曫r   r   zutf-8)r   r   r   r   r
   Ztemp_cwdr   r   r   accessR_OKr'   )r   dirnamer   r   r   r   r   test_directory   s    zUnicodeFileTests.test_directory)r    
__module____qualname__r   	filenamesr   r   r   r   FileNotFoundErrorr#   r)   r<   platformNotADirectoryErrorr,   r-   unittestZskipIfr6   rA   rC   rG   r   r   r   r   r   ;   s   	

r   c               @   s   e Zd ZdZdS )UnicodeNFCFileTestsr.   N)r    rH   rI   r   r   r   r   r   rO      s   rO   c               @   s   e Zd ZdZdS )UnicodeNFDFileTestsr/   N)r    rH   rI   r   r   r   r   r   rP      s   rP   c               @   s   e Zd ZdZdS )UnicodeNFKCFileTestsr0   N)r    rH   rI   r   r   r   r   r   rQ      s   rQ   c               @   s   e Zd ZdZdS )UnicodeNFKDFileTestsr1   N)r    rH   rI   r   r   r   r   r   rR      s   rR   c               C   s   t ttttt d S )N)r   Zrun_unittestr   rO   rP   rQ   rR   r   r   r   r   	test_main   s    rS   __main__)r   r<   rN   r8   Zunicodedatar   Ztestr   rJ   rL   extendr   supports_unicode_filenamesr=   Z
fsencodingr   r   UnicodeEncodeErrorZSkipTestZTestCaser   rO   rP   rQ   rR   rS   r    r   r   r   r   <module>   sR   	

m

