
W?                 @   s>   d  d l  Z  d  d l Z Gd d   d e  Z d d   Z d S)    Nc               @   s|  e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z e j j j d-  d. d/    Z d0 d1   Z d2 d3   Z d4 d5   Z  d6 d7   Z! d8 d9   Z" d: d;   Z# e j j j d-  d< d=    Z$ d> d?   Z% d@ dA   Z& dB dC   Z' dD dE   Z( dF dG   Z) dH dI   Z* dJ dK   Z+ dL dM   Z, dN dO   Z- dP dQ   Z. dR dS   Z/ dT dU   Z0 dV dW   Z1 dX dY   Z2 dZ d[   Z3 d\ d]   Z4 d^ d_   Z5 d` da   Z6 db dc   Z7 dd de   Z8 df dg   Z9 dh di   Z: dj dk   Z; dl dA   Z& dm dn   Z< do dp   Z= dq dr   Z> ds dt   Z? du dv   Z@ dw dx   ZA dy dz   ZB d{ d|   ZC d} d~   ZD d d   ZE e j j jF d  d d    ZG e j j jF d  d d    ZH d S)CommonFSTestsc             C   s%   | j  |  } | | k s! t  d  S)N)	__class__AssertionError)selfpath1p r   9/home/ronny/Projects/pytest-dev/py/testing/path/common.pytest_constructor_equality   s    z'CommonFSTests.test_constructor_equalityc             C   s4   | j  d  } | j  d  } | | k s0 t  d  S)N	sampledir)joinr   )r   r   p1p2r   r   r	   test_eq_nonstring	   s    zCommonFSTests.test_eq_nonstringc             C   s   | | j    k s t  d  S)N)newr   )r   r   r   r   r	   test_new_identical   s    z CommonFSTests.test_new_identicalc             C   sO   | j  d  } t |  } | j d  s0 t  | j t |   sK t  d  S)Nr   )r   strendswithr   
startswith)r   r   r   strpr   r   r	   	test_join   s    zCommonFSTests.test_joinc             C   s   | j  | j d  } t |  } | j d  s7 t  | j t |   sR t  | j  | j d d  } t |  } | j d  s t  | j t |   s t  d  S)Nr      )r   sepr   r   r   r   )r   r   newpathr   r   r   r	   test_join_normalized   s    z"CommonFSTests.test_join_normalizedc             C   s"   | j    } | | k s t  d  S)N)r   r   )r   r   r   r   r   r	   test_join_noargs!   s    zCommonFSTests.test_join_noargsc             C   sf   | j  d  } | d } | j   s+ t  | j   s= t  | j   sO t  | j   sb t  d  S)Nsampledir)r   checkr   existsisdirisfile)r   r   r   r   r   r	   test_add_something%   s    
z CommonFSTests.test_add_somethingc             C   s   | j  d d  } | j   d d   } | | | j  d  | g k sL t  | j d d  d  d  } | | | j  d  | g k s t  d  S)Nr   	otherfile   reverseT)r   partsr   )r   r   r   ZparZrevparr   r   r	   
test_parts-   s
    $zCommonFSTests.test_partsc             C   s4   | j  d  } | j |  } | | k s0 t  d  S)Nr   )r   commonr   )r   r   otherxr   r   r	   test_common5   s    zCommonFSTests.test_commonc             C   sX   | j  d  } | j d d  s' t  | j d d  s? t  | j d k sT t  d  S)Nr   basenameZnotbasenamexyz)r   r   r   r-   )r   r   r   r   r   r	   test_basename_checks?   s    z"CommonFSTests.test_basename_checksc             C   s@   | j  d  } | j d d  s' t  | j s< t d   d  S)Nr   r-   )r   r   r   r-   )r   r   r   r   r   r	   test_basenameE   s    zCommonFSTests.test_basenamec             C   s.   | j  d  } | j t |  k s* t  d  S)Nr   )r   dirnamer   r   )r   r   r   r   r   r	   test_dirnameJ   s    zCommonFSTests.test_dirnamec             C   s+   | j  d  } | j   | k s' t  d  S)Nr   )r   dirpathr   )r   r   r   r   r   r	   test_dirpathN   s    zCommonFSTests.test_dirpathc             C   s7   | j  d  } | j d  | j  d  k s3 t  d  S)Nr   r+   )r   r3   r   )r   r   r   r   r   r	   test_dirpath_with_argsR   s    z$CommonFSTests.test_dirpath_with_argsc             C   sX   | j  d  } | j d d  } | j d k s6 t  | j   | j   k sT t  d  S)N
samplefiler-   samplefile2)r   r   r-   r   r3   )r   r   r   Znewbaser   r   r	   test_newbasenameV   s    zCommonFSTests.test_newbasenamec             C   sA   | j  d  j   s t  | j  d  j d d  s= t  d  S)NZdoes_not_existr   r   )r   r   r   )r   r   r   r   r	   test_not_exists\   s    zCommonFSTests.test_not_existsc             C   s   | j  d  j   s t  | j  d  j d d  s< t  | j  d  j   sW t  | j  d  j   sr t  | j  d  j   s t  d  S)Nr6   r      )r   r   r   r   r!   r    )r   r   r   r   r	   test_exists`   s
    !zCommonFSTests.test_existsc             C   s   | j  d  j d d  s! t  | j  d  j d d  sB t  | j  d  j d d  sd t  | j  d  j   s t  | j  d  j   s t  | j  d  j   s t  d  S)Nr   r   r:   r6   notdir)r   r   r   r   r    r!   )r   r   r   r   r	   test_dirg   s    !!"zCommonFSTests.test_dirc             C   s   | j  d  j d d  s! t  | j  d  j d  s? t  | j  d  j d  s^ t  | j  d  j d d  s t  d  S)Nr6   fnmatchzs*ezs*x)r   r   r   r>   )r   r   r   r   r	   test_fnmatch_filep   s    !zCommonFSTests.test_fnmatch_filec             C   s   | j  d d  } | j |  | j j  d d g  k s? t  | j d |  sW t  | j d |  so t  | j d |  s t  d  S)Nr   r#   reltoZnotrelto)r   r@   r   r   r   )r   r   lr   r   r	   
test_relto|   s
    -zCommonFSTests.test_reltoc             C   s   | } | j  } | j |  } | d k s0 t  | j | j d d   } | d | d k se t  | j | j   j d   } | d | d k s t  | j | j    d k s t  | j d  d k s t  d  S)N.helloworldZsisterz..)r   bestrelpathr   r   r3   )r   r   curdirr   sr   r   r	   test_bestrelpath   s    	!zCommonFSTests.test_bestrelpathc             C   sN   | j  d  } | j  d  } | j |  s4 t  | j |  sJ t  d  S)NZbcdeb)r   r@   r   )r   r   l1l2r   r   r	   test_relto_not_relative   s    z%CommonFSTests.test_relto_not_relativezsys.platform.startswith('java')c             C   s_   | j    } | j d  | k s' t  | j d  | k sB t  t j j t j j d  d  S)Nr   r6   z"path1.join('samplefile').listdir())listdirr   r   pytestraiseserrorENOTDIR)r   r   rA   r   r   r	   test_listdir   s
    zCommonFSTests.test_listdirc             C   sD   | j  d  } t |  s! t  | d s@ t | j d    d  S)Nzs*dirr   r   )rN   lenr   r   )r   r   rA   r   r   r	   test_listdir_fnmatchstring   s    z(CommonFSTests.test_listdir_fnmatchstringc             C   sO   | j  d d    } | j d  | k s0 t  | j d  | k sK t  d  S)Nc             S   s   |  j  d d  S)Nr   r:   )r   )r+   r   r   r	   <lambda>   s    z3CommonFSTests.test_listdir_filter.<locals>.<lambda>r   r6   )rN   r   r   )r   r   rA   r   r   r	   test_listdir_filter   s    z!CommonFSTests.test_listdir_filterc             C   s|   | j  d d   d d } | j d  | d k s: t  | j d  | d k sY t  | j d	  | d
 k sx t  d  S)Nc             S   s   |  j  d d  S)N
basestartsr   )r   )r+   r   r   r	   rW      s    z3CommonFSTests.test_listdir_sorted.<locals>.<lambda>sortTr   r   r6   r:   samplepickler   )rN   r   r   )r   r   rA   r   r   r	   test_listdir_sorted   s    z!CommonFSTests.test_listdir_sortedc             C   sm   g  } x* | j    D] } | j | j |   q Wd | k sE t  | j j d d g  | k si t  d  S)Nr   r#   )visitappendr@   r   r   r   )r   r   rA   ir   r   r	   test_visit_nofilter   s
    z!CommonFSTests.test_visit_nofilterc             C   sy   g  } x6 | j  d  d d    D] } | j | j |   q Wd | k sQ t  | j j d d g  | k su t  d  S)Nc             S   s   |  j  d k S)Nr   )r-   )r+   r   r   r	   rW      s    z4CommonFSTests.test_visit_norecurse.<locals>.<lambda>r   r#   )r]   r^   r@   r   r   r   )r   r   rA   r_   r   r   r	   test_visit_norecurse   s
    z"CommonFSTests.test_visit_norecursec             C   sv   g  } x- | j  d  D] } | j | j |   q Wt |  sN t d   d | k s` t  d | k sr t  d  S)Nz*dirr   r   otherdir)r]   r^   r@   rU   r   )r   r   rA   r_   r   r   r	   test_visit_filterfunc_is_string   s    z-CommonFSTests.test_visit_filterfunc_is_stringc             C   s=   | j  d  } t | j d t j j   g  k s9 t  d  S)NZnonexistingignore)r   listr]   rO   rR   ENOENTr   )r   r   r   r   r   r	   test_visit_ignore   s    zCommonFSTests.test_visit_ignorec             C   sv   g  } x3 | j  d d    D] } | j | j |   q W| j j d d g  | k s` t  d | k sr t  d  S)Nc             S   s   |  j  d d  S)Nr   file)r   )r+   r   r   r	   rW      s    z3CommonFSTests.test_visit_endswith.<locals>.<lambda>r   r#   r6   )r]   r^   r@   r   r   r   )r   r   rA   r_   r   r   r	   test_visit_endswith   s
    $z!CommonFSTests.test_visit_endswithc             C   sC   | j  d d  s t  | j d  } | j  d d  s? t  d  S)NZnotendswithz.pyr6   r   rh   )r   r   r   )r   r   r+   r   r   r	   test_endswith   s    zCommonFSTests.test_endswithc             C   sS   | j  d  } | j  d  } | | k  d d k  k s< t  | | k  sO t  d  S)Nr6   r7   )r   r   )r   r   path2r   r   r	   test_cmp   s    zCommonFSTests.test_cmpc             C   s.   | j  d  j d  } | d k s* t  d  S)Nr6   rzsamplefile
)r   readr   )r   r   r+   r   r   r	   test_simple_read   s    zCommonFSTests.test_simple_readc             C   s6   | d d } | j  d d  } | | k s2 t  d  S)Nz
/sampledirz/test//r   rP   )r   r   )r   r   r   Znewpath2r   r   r	   test_join_div_operator   s    z$CommonFSTests.test_join_div_operatorc             C   sG   | j  d  } | j d k s$ t  | j  d  } | j sC t  d  S)Nzsampledir.extz.extr   )r   extr   )r   r   r   r   r   r	   test_ext   s    zCommonFSTests.test_extc             C   s(   | j  d  } | j d k s$ t  d  S)Nzsamplefile.pyr6   )r   purebasenamer   )r   r   r   r   r   r	   test_purebasename   s    zCommonFSTests.test_purebasenamec             C   s   | j  d  } | j d  \ } } } } t |  j |  sE t  | d k sW t  | d k si t  | d k s{ t  d  S)Nzsamplefile.pyz!dirname,purebasename,basename,extr6   z.py)r   
_getbyspecr   r   r   )r   r   r   r1   rs   r-   rq   r   r   r	   test_multiple_parts   s    z!CommonFSTests.test_multiple_partsc             C   sC   | j  d  } | j } | d k s* t  | j d k s? t  d  S)Nza.b.cz.c)r   rq   r   )r   r   r   rq   r   r   r	   test_dotted_name_ext   s    	z"CommonFSTests.test_dotted_name_extc             C   sO   | j  d  } | j d d  } | j d k s6 t  | j d k sK t  d  S)Nzsamplefile.pyrq   z.txtzsamplefile.txtr6   )r   r   r-   r   rs   )r   r   r   Znewextr   r   r	   test_newext   s    zCommonFSTests.test_newextc             C   s4   | j  d  } | j   } | d g k s0 t  d  S)Nr6   zsamplefile
)r   	readlinesr   )r   r   fncontentsr   r   r	   test_readlines  s    zCommonFSTests.test_readlinesc             C   s=   | j  d  } | j d d  } | d d g k s9 t  d  S)Nr6   crr    )r   ry   r   )r   r   rz   r{   r   r   r	   test_readlines_nocr	  s    z!CommonFSTests.test_readlines_nocrc             C   s%   | j  d  j d d  s! t  d  S)Nr6   rh   r:   )r   r   r   )r   r   r   r   r	   	test_file  s    zCommonFSTests.test_filec             C   sG   | j  d  j d d  s" t  | j  d  j d d  sC t  d  S)Nr   rh   r:   r   )r   r   r   )r   r   r   r   r	   test_not_file  s    "zCommonFSTests.test_not_filec             C   s   | j  d  j d d  s! t  | j  d  j d d  sB t  | j  d  j d d  sc t  | j  d  j d d  s t  | j  d  j d d  s t  | j  d  j d d  s t  d  S)	Nzsampledir.notherer   r   rh   Znotfiler:   r<   Z	notexists)r   r   r   )r   r   r   r   r	   test_non_existent  s    !!!!!zCommonFSTests.test_non_existentc             C   s1   | j  d  } | j   t d  k s- t  d  S)Nr6   )r   sizerU   r   )r   r   urlr   r   r	   	test_size!  s    zCommonFSTests.test_sizec             C   s+   | j  d  } | j   d k s' t  d  S)Nr6   r   )r   mtimer   )r   r   r   r   r   r	   
test_mtime%  s    zCommonFSTests.test_mtimec             C   s   t  j j t d  d  S)Nzpath1.relto(42))rO   rP   rQ   	TypeError)r   r   r   r   r	   test_relto_wrong_type)  s    z#CommonFSTests.test_relto_wrong_typec             C   sU   | j  d  } | j   } t |  t k s3 t  | j d d   d k sQ t  d  S)Nr[   answer*   )r   loadtypedictr   get)r   r   r   objr   r   r	   	test_load,  s    zCommonFSTests.test_loadc             C   sv   g  } x3 | j  d d    D] } | j | j |   q Wd | k sN t  | j j d d g  | k sr t  d  S)Nc             S   s   |  j  d d  S)Nrh   r:   )r   )r+   r   r   r	   rW   4  s    z4CommonFSTests.test_visit_filesonly.<locals>.<lambda>r   r#   )r]   r^   r@   r   r   r   )r   r   rA   r_   r   r   r	   test_visit_filesonly2  s
    z"CommonFSTests.test_visit_filesonlyc             C   s   g  } x3 | j  d d    D] } | j | j |   q Wd | k sN t  | j j d d g  | k sr t  d | k s t  d  S)Nc             S   s   |  j  d d  S)Ndotfiler   )r   )r+   r   r   r	   rW   ;  s    z5CommonFSTests.test_visit_nodotfiles.<locals>.<lambda>r   r#   z.dotfile)r]   r^   r@   r   r   r   )r   r   rA   r_   r   r   r	   test_visit_nodotfiles9  s    $z#CommonFSTests.test_visit_nodotfilesc             C   s   g  } x0 | j  d d  D] } | j | j |   q Wxs t |  D]U \ } } | j | k rF x6 t | t |   D] } | j | | k sw t  qw WPqF Wt j	 j
 d  d  S)NbfTZhuh)r]   r^   r@   	enumerater   rangerU   r   rO   rP   fail)r   r   rA   r_   r   jr   r   r	   test_visit_breadthfirstA  s    z%CommonFSTests.test_visit_breadthfirstc             C   s   g  } x6 | j  d d d d  D] } | j | j |   q Wx* t |  D] \ } } | j | k rL PqL W| d  |  t | d  |   k s t  | | d   t | | d    k s t  d  S)Nr   TrZ   )r]   r^   r@   r   r   sortedr   )r   r   rA   r_   r   r   r   r	   test_visit_sortM  s    ,zCommonFSTests.test_visit_sortc             C   sZ   d d   } | |  s t   | | j d   s; t   | | j d   sV t   d  S)Nc             S   s   |  j  d d  S)Nr   pickle)r   )r   r   r   r	   chkX  s    z(CommonFSTests.test_endswith.<locals>.chkr6   Z
somepickle)r   r   )r   r   r   r   r   r	   rj   W  s    c          
   C   s   | j  d  } | j  d  } | j  d  } | j |  z@ | j   sO t  | j   } | j   } | | k sy t  Wd  | j   r | j   Xd  S)Nrb   z__init__.pycopied)r   copyr   r   rn   remove)r   r   rb   Zinitpyr   s1s2r   r   r	   test_copy_file^  s    zCommonFSTests.test_copy_filec             C   s   | j  d  } | j  d  } z | j |  | j d d  sF t  | j  d  j d d  sg t  | j  d  j   } | j  d  j   } | | k s t  Wd  | j d d  r | j d d  Xd  S)Nrb   Znewdirr   r:   z__init__.pyrh   rec)r   r   r   r   rn   r   )r   r   rb   r   r   r   r   r   r	   test_copy_dirl  s    !zCommonFSTests.test_copy_dirc             C   sB   | j  d  } | j   s! t  | j   | j   s> t  d  S)NZ	todeleted)ensurer   r   r   )r   r   dr   r   r	   test_remove_filez  s    
zCommonFSTests.test_remove_filec             C   sW   | j  d d d  } | j   s' t  | j d  } | j   | j   sS t  d  S)NZtobedeleted)r   r   r   r   r   )r   r   r   r   r   r   r	   $test_remove_dir_recursive_by_default  s
    
z2CommonFSTests.test_remove_dir_recursive_by_defaultc             C   s=   | j  d d  } | j d k s' t  | j   s9 t  d  S)NZ001Z002)
ensure_dirr-   r   r    )r   r   rJ   r   r   r	   test_ensure_dir  s    zCommonFSTests.test_ensure_dirc             C   s   | } t  j j t  j j | j d  | j d  } | j   | j d d  sV t  | j	   | j d  } | j d d  s t  | j	   | j d  | k s t  d  S)Nr   Zmktest1r   r:   Zmktest)
rO   rP   rQ   rR   EEXISTmkdirr   r   r   r   )r   r   tmpdirr   r   r   r	   test_mkdir_and_remove  s    


z#CommonFSTests.test_mkdir_and_removec             C   s   | j  d  } | j d  } | j |  z/ | j d d  sF t  | j   sY t  Wd  | j   } t | d  r | j   n | j |  | j   s t  Xd  S)Nr6   Zmoved_samplefilerh   r:   revert)r   r3   mover   r   hasattrr   )r   r   r   Znewpdpr   r   r	   test_move_file  s    zCommonFSTests.test_move_filec             C   s   | j  d  } | j  d  } | j |  | j d d  sC t  | j  d  j d d  sd t  | j  d  j   s t  d  S)Nr   Zmoveddirr   r:   r#   rh   )r   r   r   r   )r   r   sourcedestr   r   r	   test_move_dir  s    !zCommonFSTests.test_move_dirc             C   s   | j    | j k s t  d  S)N)
__fspath__strpathr   )r   r   r   r   r	   "test_fspath_protocol_match_strpath  s    z0CommonFSTests.test_fspath_protocol_match_strpathc             C   sX   y d d l  m } Wn" t k
 r8 d d l m } Yn X| |  | j k sT t  d  S)Nr   )fspath)osr   ImportErrorZpy._path.commonr   r   )r   r   r   r   r   r	   test_fspath_func_match_strpath  s
    z,CommonFSTests.test_fspath_func_match_strpathzsys.version_info < (3,6)c             C   s   | j  d  } t |  d  S)NZopentestfile)r   open)r   r   fr   r   r	   test_fspath_open  s    zCommonFSTests.test_fspath_openc             C   s5   d d l  m } | |  | | j  k s1 t  d  S)Nr   )fsencode)r   r   r   r   )r   r   r   r   r   r	   test_fspath_fsencode  s    z"CommonFSTests.test_fspath_fsencodeN)I__name__
__module____qualname__r
   r   r   r   r   r   r"   r(   r,   r/   r0   r2   r4   r5   r8   r9   r;   r=   r?   rB   rI   rM   rO   rP   markxfailrT   rV   rX   r\   r`   ra   rc   rg   ri   rj   rl   ro   rp   rr   rt   rv   rw   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   skipr   r   r   r   r   r	   r      s   

	!!	
!r   c             C   sr  |  j  d  j   r d  S|  j d  } | j d  |  j d  } | j d  |  j d  } | j d  d d d d	 d
 d i } |  j d  j |  |  j d d d } | j d  |  j d d d } | j d  | j d  } t j d k r| j d  n | j d  | j d  } | j d  | j d  }	 |	 j d  | j d  }
 |
 j d  d  S)Nr6   zsamplefile
execfilezx=42zexecfile.pyr:   r   rD   rE   r   r   r[   r   r   r#   rb   z__init__.pyza.py   zfrom .b import stuff as result
zfrom b import stuff as result
zb.pyzstuff="got it"
zc.pyz7import py;
import otherdir.a
value = otherdir.a.result
zd.pyz4import py;
from otherdir import a
value2 = a.result
)r   r   )r   r   r   writedumpsysversion_info)pathr6   r   Z
execfilepyr   r   rb   Zmodule_aZmodule_bZmodule_cZmodule_dr   r   r	   setuptestfs  s4    r   )rO   r   objectr   r   r   r   r   r	   <module>   s    