a
    äzeÁ  ã                	   @   s¶   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mZm	Z	m
Z
mZmZ e jjsˆze
 e	¡ W n  eefy†   e d¡‚Y n0 dd„ ZG dd„ dejƒZedkr²e ¡  dS )	é    N)ÚrmtreeÚ
change_cwdÚTESTFN_ENCODINGÚTESTFN_UNICODEÚTESTFN_UNENCODABLEÚcreate_empty_filez1No Unicode filesystem semantics on this platform.c                 C   s   t j | ¡rt  | ¡ d S ©N)ÚosÚpathÚexistsÚunlink)Úfilename© r   ú,/usr/lib/python3.9/test/test_unicode_file.pyÚremove_if_exists   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S )ÚTestUnicodeFilesc              
   C   s>  |   tj |¡¡ |   tj |¡¡ |   t |tj¡¡ |   tj tj |¡¡¡ |   tj tj |¡¡¡ |   t tj |¡tj¡¡ t |d¡ t 	|d ¡ t 	|t
 
¡ t
 
¡ f¡ |  ||¡ |   tj |¡tj t t |¡¡d ¡k¡ tj tj |¡¡\}}t |¡}t d|¡}dd„ |D ƒ}|  ||¡ d S )Niÿ  r   ÚNFDc                 S   s   g | ]}t  d |¡‘qS )r   )ÚunicodedataÚ	normalize)Ú.0Úfr   r   r   Ú
<listcomp>2   ó    z/TestUnicodeFiles._do_single.<locals>.<listcomp>)Ú
assertTruer	   r
   r   ÚisfileÚaccessÚR_OKÚabspathÚchmodÚutimeÚtimeÚ_do_copyishÚglobÚescapeÚsplitÚlistdirr   r   ZassertIn)Úselfr   r
   ÚbaseZ	file_listr   r   r   Ú
_do_single   s$    &ÿ
zTestUnicodeFiles._do_singlec                 C   s^  |   tj |¡¡ t ||d ¡ |  tj |¡¡ |   tj |d ¡¡ t |d |¡ |  tj |d ¡¡ |   tj |¡¡ t ||d ¡ t |d ¡ t 	||d ¡ |  tj 
|¡¡ |   tj 
|d ¡¡ t 	|d |¡ |  tj 
|d ¡¡ |   tj 
|¡¡ t ||d ¡ |   tj |d ¡¡ t |d ¡ |  tj 
|d ¡¡ d S )Nz.new)r   r	   r
   r   ÚrenameZassertFalseÚshutilÚcopyr   Úmover   Úcopy2)r&   Z	filename1Ú	filename2r   r   r   r!   7   s&    zTestUnicodeFiles._do_copyishc              	   C   sž   t j |¡rt|ƒ t  |¡ znt|ƒH t  ¡ }|}t d|¡}t d|¡}|  	t j 
|¡|¡ W d   ƒ n1 sv0    Y  W t  |¡ nt  |¡ 0 d S )Nr   )r	   r
   Úisdirr   Úmkdirr   Úgetcwdr   r   ZassertEqualÚbasenameÚrmdir)r&   Z	make_nameZ
chdir_nameZ
cwd_resultZname_resultr   r   r   Ú_do_directoryT   s    

4zTestUnicodeFiles._do_directoryc              	   C   sŒ   t |ƒ t|ƒ z|  |¡ W t |¡ nt |¡ 0 |  tj |¡ ¡ t |tj	¡}t 
|¡ z|  |¡ W t |¡ nt |¡ 0 d S r   )r   r   r(   r	   r   r   r
   r   ÚopenÚO_CREATÚclose)r&   r   r   r   r   r   Ú_test_singlef   s    
zTestUnicodeFiles._test_singlec                 C   s    |   t¡ td ur|   t¡ d S r   )r8   r   r   )r&   r   r   r   Útest_single_filesx   s    
z"TestUnicodeFiles.test_single_filesc                 C   s8   d}|   t| t| ¡ td ur4|   t| t| ¡ d S )Nz.dir)r4   r   r   )r&   Úextr   r   r   Útest_directories}   s    
ÿz!TestUnicodeFiles.test_directoriesN)	Ú__name__Ú
__module__Ú__qualname__r(   r!   r4   r8   r9   r;   r   r   r   r   r      s   r   Ú__main__)r	   r"   r    r*   r   ZunittestZtest.supportr   r   r   r   r   r   r
   Úsupports_unicode_filenamesÚencodeÚUnicodeErrorÚ	TypeErrorZSkipTestr   ZTestCaser   r<   Úmainr   r   r   r   Ú<module>   s     r