
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
yb$1              (   @   sp  d dl 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mZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ yd dlZeejd	ZW n ek
r   d
ZY nX yd dlmZ W n   dZY nX eedpejjdZy(e	j  Z!ej"e!j#ej$ W dQ R X W n e%k
rV   d
ZY nX yd dlZdpjeZ&W n ek
r   d
Z&Y nX de'edg krd Z(ndej) krd,Z(nd-Z(ejjdrd.Z(edd Z*ej+ dd Z,ej+ dd Z-ej+ dd Z.ej+ dd Z/ej+ d d! Z0d"d# Z1G d$d% d%ej2Z3G d&d' d'Z4G d(d) d)Z5G d*d+ d+Z6dS )/    )contextmanagerN   )get_all)	get_flags)umount)EXIT_SUCCESSEXIT_WARNING
EXIT_ERROR)platformst_mtime_nsF)raisesZlchflagslinuxTHAVE_FUTIMENS_have_functionsHAVE_UTIMES   	   netbsd   c           
   c   s(   t j } tjj| dV  W d Q R X d S )Nfile)tempfileZTemporaryDirectoryospathjoin)Ztempdir r    /usr/lib64/python3.6/__init__.pyunopened_tempfile;   s    
r   c              C   s\   t  L} y0tjd|  tj| ddr6tj| dkr6dS W n tk
rL   Y nX W d Q R X dS )NZ	somewhereF)follow_symlinksT)r   r   symlinkstatreadlinkOSError)filepathr   r   r   are_symlinks_supportedA   s    r#   c              C   s   t tdsdS t } t z}t| dj  yPtj| | tj| }tj|}|j|j  koddkn  rz|j|jkrzdS W n t	k
r   Y nX W d Q R X W d Q R X dS )NlinkFwr   T)
hasattrr   r   opencloser$   r   st_nlinkst_inor!   )Z	file1pathZ	file2pathZstat1Zstat2r   r   r   are_hardlinks_supportedM   s    


(r+   c              C   s:   t  *} ytj|  dS  tk
r*   dS X W d Q R X d S )NTF)r   r   mkfifor!   )r"   r   r   r   are_fifos_supported`   s    
r-   c              C   s   t  x} t rtjd|  nt| dj  y:tj| ddd tj| dd}|jdkrb|j	dkrbdS W n t
k
rx   Y nX dS Q R X d S )	N	somethingr%       F)r   T)r/   r0   )r   r#   r   r   r'   r(   utimer   st_atimest_mtimer!   )r"   	new_statsr   r   r   is_utime_fully_supportedj   s    r5   c              C   s   t tjdsdS t } t r,tjd|  nt| dj  yfd
\}}}tj| ||fdd tj| ||fdd tj	| dd}|j
|kr|j|kr|j|krd	S W n tk
r   Y nX dS Q R X d S )Nst_birthtimeFr.   r%    k8Cm8 n8)r   T)r7   r8   r9   )r&   r   stat_resultr   r#   r   r'   r(   r1   r   r6   r3   r2   r!   )r"   Z	birthtimemtimeZatimer4   r   r   r   is_birthtime_fully_supported|   s     
r<   c                sD   d t | tr$ fdd| j D S t | tr@ fdd| D S d S )Nzsecurity.selinuxc                s   i | ]\}}| kr||qS r   r   ).0kv)SELINUX_KEYr   r   
<dictcomp>   s    zno_selinux.<locals>.<dictcomp>c                s   g | ]}| kr|qS r   r   )r=   r>   )r@   r   r   
<listcomp>   s    zno_selinux.<locals>.<listcomp>)
isinstancedictitemslist)xr   )r@   r   
no_selinux   s
    

rH   c               @   s   e Zd ZdZejjZejjZ	ejj
ZejjZer:eeZnejjZedd Zdd ZdddZedd
dZddddZedd Zd	S )BaseTestCasez
    c             c   s@   t jj| stdj|d V  t jj|s<tdj|d S )Nz{} should not existz{} should exist)r   r   existsAssertionErrorformat)selfr   r   r   r   assert_creates_file   s    z BaseTestCase.assert_creates_filec             K   s   t j||}| j|f| d S )N)filecmpZdircmp_assert_dirs_equal_cmp)rM   Zdir1Zdir2kwargsdiffr   r   r   assert_dirs_equal   s    zBaseTestCase.assert_dirs_equalFc                s  | j |jg  | j |jg  | j |jg  | j |jg  x|jD ]}tjj|j	|}tjj|j
|}tj|dd tj|dd jjk}dddg}	| stjj| r|	jd |g fdd|	D  }
|gfd	d|	D  }|
jd
t j |jd
tj |s2|
jt|  |jt| tj j rZtj j rZd |
d< tjj rtjj rd |d< t r|r|
jt jd  |jtjd  nX|rt r|
jt jd |jtjd n$|
jt jt |jtjt |sD|
jtt|dd |jtt|dd | j |
| qBW x&|jj D ]}| j||||d q`W d S )NF)r   st_uidst_gidst_rdevr)   c                s   g | ]}t  |qS r   )getattr)r=   a)s1r   r   rB      s    z7BaseTestCase._assert_dirs_equal_cmp.<locals>.<listcomp>c                s   g | ]}t  |qS r   )rW   )r=   rX   )s2r   r   rB      s       r   g    eA)ignore_bsdflagsignore_xattrs	ignore_nsr_   ) assert_equalZ	left_onlyZ
right_onlyZ
diff_filesZfunny_filescommonr   r   r   leftrightr   st_devisdirappendinsertoctst_moder   S_ISCHRS_ISBLKr5   intr   have_fuse_mtime_nsroundst_mtime_ns_roundrH   r   ZsubdirsvaluesrP   )rM   rR   r\   r]   r^   filenameZpath1Zpath2ZfuseZattrsZd1Zd2Zsub_diffr   )rY   rZ   r   rP      sN    

  z#BaseTestCase._assert_dirs_equal_cmpNc             o   s   |d krt j }n
tj| d|kr,d|d< | jd||f|| |jdttkr\d V  d S | j|dd d V  t	| | j|dd tj
| tjd d S )NforkTmountZ	exit_code)mountedFg?)r   Zmkdtempr   mkdircmdgetr   r	   wait_for_mountstater   rmdirtimesleep)rM   location
mountpointZoptionsrQ   r   r   r   
fuse_mount   s    

	
zBaseTestCase.fuse_mount   )timeoutc            C   s\   |t j  7 }x.|t j  kr:tjj||kr.dS t jd qW d|rFdnd|f }t|dS )z4Wait until a path meets specified mount point statusNg?zWaiting for %s of %srs   r   )rz   r   r   ismountr{   TimeoutError)rM   r}   rt   r   messager   r   r   rx     s    z BaseTestCase.wait_for_mountstatec             c   s   t jjdrd| }d| }nPt jjdr<d| }d	| }n2t jjd
rZd| }d| }ndt j }| j| z"tjd|  tj| dV  W dtj| tjd|  X dS )a  Some paths need to be made read-only for testing

        If the tests are executed inside a fakeroot environment, the
        changes from chmod won't affect the real permissions of that
        folder. This issue is circumvented by temporarily disabling
        fakeroot with `LD_PRELOAD=`.

        Using chmod to remove write permissions is not enough if the
        tests are running with root privileges. Instead, the folder is
        rendered immutable with chattr or chflags, respectively.
        r   zchattr +i "%s"zchattr -i "%s"darwinfreebsdr   openbsdzchflags uchg "%s"zchflags nouchg "%s"sunoszchmod S+vimmutable "%s"zchmod S-vimmutable "%s"z7Testing read-only repos is not supported on platform %szLD_PRELOAD= chmod -R ugo-w "%s"NzLD_PRELOAD= chmod -R ugo+w "%s")r   r   r   r   )sysr
   
startswithZskipTestr   system)rM   r   Zcmd_immutableZcmd_mutabler   r   r   r   	read_only  s"    







zBaseTestCase.read_only)FFF)N)__name__
__module____qualname____doc__unittestTestCaseZassertInZ	assert_inZassertNotInZassert_not_inZassertEqualr`   ZassertNotEqualZassert_not_equalr   staticmethodZassert_raisesZassertRaisesr   rN   rS   rP   r~   rx   r   r   r   r   r   rI      s   

0 
rI   c               @   s$   e Zd Zdd Zdd Zdd ZdS )	changedirc             C   s
   || _ d S )N)dir)rM   r   r   r   r   __init__1  s    zchangedir.__init__c             C   s   t j | _t j| j d S )N)r   getcwdoldchdirr   )rM   r   r   r   	__enter__4  s    
zchangedir.__enter__c             O   s   t j| j d S )N)r   r   r   )rM   argskwr   r   r   __exit__8  s    zchangedir.__exit__N)r   r   r   r   r   r   r   r   r   r   r   0  s   r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )environment_variablec             K   s   || _ i | _d S )N)rp   
old_values)rM   rp   r   r   r   r   =  s    zenvironment_variable.__init__c             C   sP   xJ| j j D ]<\}}tjj|| j|< |d kr>tjj|d  q|tj|< qW d S )N)rp   rE   r   environrw   r   pop)rM   r>   r?   r   r   r   r   A  s
    zenvironment_variable.__enter__c             O   s>   x8| j j D ]*\}}|d kr,tjj|d  q|tj|< qW d S )N)r   rE   r   r   r   )rM   r   r   r>   r?   r   r   r   r   I  s    zenvironment_variable.__exit__N)r   r   r   r   r   r   r   r   r   r   r   <  s   r   c               @   s"   e Zd ZdZdd ZdddZdS )
FakeInputszASimulate multiple user inputs, can be used as input() replacementc             C   s
   || _ d S )N)inputs)rM   r   r   r   r   r   S  s    zFakeInputs.__init__Nc             C   s@   |d k	rt |dd y| jjdS  tk
r:   td Y nX d S )N )endr   )printr   r   
IndexErrorEOFError)rM   promptr   r   r   __call__V  s    zFakeInputs.__call__)N)r   r   r   r   r   r   r   r   r   r   r   Q  s   r   iir_   )7
contextlibr   rO   	functoolsr   posixr   r   	sysconfigr   rz   Zuuidr   Zxattrr   r
   r   Zhelpersr   r   r   r	   r   Zllfuser&   ZEntryAttributesrm   ImportErrorZpytestr   r   Zhas_lchflagsZNamedTemporaryFiler   Z	set_flagsname	UF_NODUMPr!   Z
has_llfuserW   ro   get_config_varsr   	lru_cacher#   r+   r-   r5   r<   rH   r   rI   r   r   r   r   r   r   r   <module>   sn   





	 