
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
yb@                 @   s|  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 ddlmZmZ ddlmZmZ dd Zejjdd	g fd
d
gfdd
gfdd
gfddgfddgfddgfgdd Zejjddg fdg fddgfddgfgdd Zejjddddg fdg fdddgfdddgfdddgfdd d!gfd"d#d$gfg	d%d& Zejjddg fd'g fdd(d)gfd*d+gfgd,d- Zejjdddddddg fd3ddd d!d4d5gfd6ddgfd7ddgfd8dd gfd9ddgfd:d d!gfd;d#d$gfd<d4d5gfgd=d> Zejjddddddddg fd3ddd d!d4d5gfd6ddgfdAddgfdBddgfdCddgfd8g fdDdd gfd9ddgfdEd d!gfdFd d!gfdGd#d$dHgfd;d"d#d$dIdHgfdJd#d$gfdKdIdHgfdLdHgfd<d4gfdMd5gfgdNdO ZejjdddddRg fdSg fdTd
ddd d!d4d5gfgdUdV ZdWdX ZdYdZ Zd[d\ Zejjd]ed^d_d` Zejjd]edadbdc Zejjd]eedddedfdg Z ejjdhg dfdigdfd0gg fdjdkdldmddngdod
dpgfdqgg fdrgdsdod
gfdtgdod
dudvgfddddwdxddydzgdogfd{gdsdod
dvgfd|gdsdod
dpdugfd}gdfd~gdpdugfdgdfddddgdod
gfddgdsd
dpdudvgfddgdsd
dpdudvgfgdd Z!ejjdg g d fdigg d fdgg dfddgg dfdgd	gd fddgd	gd fdddgd
gdfgdd Z"dd Z#ejjddgdggdd Z$ejjdhg dfdigdfdgg fdgddsdd
dddgfdgddd
dddgfdgdd
dddgfddgdsd
dddgfddgdsd
dddgfddgddsdd
ddgfddgddsdd
gfddgddsdd
ddgfgdd Z%ejjdde	fd0e	fde	fde	fde	fde	fde	fdefdqefdefdefdefd~efdefdefde
fde
fde
fde
fgdd Z&ejjd]ddddgdd Z'dd Z(dS )    N   )PathFullPatternPathPrefixPatternFnmatchPatternShellPatternRegexPattern)load_exclude_fileload_pattern_file)parse_patternPatternMatcherc                sH   t dd | D std fdd| D }||dkr:| n|ksDtdS )z"Utility for testing patterns.
    c             S   s   g | ]}|t jj|kqS  )ospathnormpath).0fr   r    /usr/lib64/python3.6/patterns.py
<listcomp>   s    z"check_patterns.<locals>.<listcomp>z.Pattern matchers expect normalized input pathsc                s   g | ]} j |r|qS r   )match)r   r   )patternr   r   r      s    N)allAssertionError)filesr   expectedZmatchedr   )r   r   check_patterns   s    r   zpattern, expected/z/homez/home///z/./homez
/home/userz/home/user2z/home/user/.bashrcc             C   s    ddddg}t |t| | d S )Nz/homez
/home/userz/home/user2z/home/user/.bashrc)r   r   )r   r   r   r   r   r   test_patterns_full   s    r    Zrelativezrelative/path/zrelative/pathc             C   s   ddg}t |t| | d S )Nzrelative/pathzrelative/path2)r   r   )r   r   r   r   r   r   test_patterns_full_relative'   s    r   /./z/home/uz/home/user/.profilez/etcz/etc/server/configz/etc/server/hostsz///etc//////z/./home//..//home/user2z/home/user2/.profilez"/home/user2/public_html/index.htmlz/srvz/srv/messagesz
/srv/dmesgc          	   C   s*   ddddddddd	g	}t |t| | d S )
Nz/etc/server/configz/etc/server/hostsz/homez/home/user/.profilez/home/user/.bashrcz/home/user2/.profilez"/home/user2/public_html/index.htmlz/srv/messagesz
/srv/dmesg)r   r   )r   r   r   r   r   r   test_patterns_prefix4   s    
r    foozrelative/path1zrelative/twoZmorezmore/relativec             C   s   dddg}t |t| | d S )Nzrelative/path1zrelative/twozmore/relative)r   r   )r   r   r   r   r   r   test_patterns_prefix_relativeI   s    
r"   /*/./***/**///*z/home/*z/home/foo/.thumbnailsz/home/foo/bar/.thumbnailsz/home/user/*z/etc/*z
*/.pr????ez///etc//////*z/./home//..//home/user2/*z/srv*z/home/*/.thumbnailsc             C   s.   ddddddddd	d
dg}t |t| | d S )Nz/etc/server/configz/etc/server/hostsz/homez/home/user/.profilez/home/user/.bashrcz/home/user2/.profilez"/home/user2/public_html/index.htmlz/srv/messagesz
/srv/dmesgz/home/foo/.thumbnailsz/home/foo/bar/.thumbnails)r   r   )r   r   r   r   r   r   test_patterns_fnmatchV   s    
r(   **/*/**/*z/etc/*/*z	/etc/**/*z/etc/**/*/*z**/.pr????ez/./home//..//home/user2/z/./home//..//home/user2/**/*z/srv*/z/srv2/blafaselz/srv2z/srv/*z/srv2/**z	/srv2/**/z/home/*/*/.thumbnailsc             C   s4   ddddddddd	d
ddddg}t |t| | d S )Nz/etc/server/configz/etc/server/hostsz/homez/home/user/.profilez/home/user/.bashrcz/home/user2/.profilez"/home/user2/public_html/index.htmlz/srvz/srv/messagesz
/srv/dmesgz/srv2z/srv2/blafaselz/home/foo/.thumbnailsz/home/foo/bar/.thumbnails)r   r   )r   r   r   r   r   r   test_patterns_shells   s    

r+   .*^/z^abc$z^[^/]z^(?!/srv|/foo|/opt)c             C   sP   ddddddddd	d
dg}t | }t|| ks2t|j| ks@tt||| d S )Nz	/srv/dataz/foo/barz/homez/home/user/.profilez/home/user/.bashrcz/home/user2/.profilez"/home/user2/public_html/index.htmlz/opt/log/messages.txtz/opt/log/dmesg.txtz/home/foo/.thumbnailsz/home/foo/bar/.thumbnails)r   strr   r   r   )r   r   r   objr   r   r   test_patterns_regex   s    r0   c               C   s@   t djdstt djtjjs(tt djd s<td S )Nz^/$r   z^\\$)r   r   r   r   r   sepr   r   r   r   test_regex_pattern   s    r2   c               C   s
   t jdkS )Ndarwin)r3   )sysplatformr   r   r   r   use_normalized_unicode   s    r6   c             C   s"   t | t| tdj| t| gS )Nz^{}/foo$)r   r   r   formatr   )r   r   r   r   _make_test_patterns   s    r8   r   u   bác             C   s&   | j dst| j dt ks"td S )Nu   bá/foou   bá/foo)r   r   r6   )r   r   r   r   test_composed_unicode_pattern   s    r9   u   bác             C   s&   | j dt kst| j ds"td S )Nu   bá/foou   bá/foo)r   r6   r   )r   r   r   r   test_decomposed_unicode_pattern   s    r:   s   balatin1c             C   s(   | j d st| j tdds$td S )Nzba/foos   ba/foor;   )r   r   r.   )r   r   r   r   test_invalid_unicode_pattern   s    r<   zlines, expectedz# Comment onlyz	# Commentz*/something00.txtz  *whitespace*  z #/ws*z# EOFz
/more/dataz #/wsfoobarzre:.*zre:\sz/data/something00.txtz
re:(.)(\1)z	start/whitespacez/whitespace/end	z*# This is a test with mixed pattern styleszre:(?i)BAR|ME$z*whitespace*zfm:*/something00*z
  re:^\s  z
  re:\s$  zpp:./zpp:/z	pp:aaabbbzpp:/datazpp: #/z	pp:	startzpp:/whitespacez/nomatchz/more/*c          
      sp   ddddddg  fdd}| j d	}|jd
}|jdj | W d Q R X |t||d krb n|ksltd S )Nz/data/something00.txtz
/more/dataz/homez #/wsfoobarz	start/whitespacez/whitespace/end	c                s:   g }t t| d| tdd  j|  fddD S )NrtT)fallbackc                s   g | ]} j |r|qS r   )r   )r   r   )matcherr   r   r     s    zEtest_exclude_patterns_from_file.<locals>.evaluate.<locals>.<listcomp>)r   openr   add_inclexcl)filenamepatterns)r   )r?   r   evaluate  s
    

z1test_exclude_patterns_from_file.<locals>.evaluatezexclude.txtwt
)joinr@   writer.   r   )tmpdirlinesr   rD   Zexclfilefhr   )r   r   test_exclude_patterns_from_file   s    '
rL   z+lines, expected_roots, expected_numpatternsz- *   z+fm:*/something00.txtz-/datazR /z	# commentz- /datazR /homec       	   
   C   sd   dd }| j d}|jd}|jdj | W d Q R X |t|\}}||ksTt||ks`td S )Nc             S   s&   g }g }t t| d|| |t|fS )Nr=   )r	   r@   len)rB   rootsinclexclpatternsr   r   r   rD   %  s    z.test_load_patterns_from_file.<locals>.evaluatezpatterns.txtrE   rF   )rG   r@   rH   r.   r   )	rI   rJ   Zexpected_rootsZexpected_numpatternsrD   patternfilerK   rO   Znumpatternsr   r   r   test_load_patterns_from_file  s    
rR   c              C   s   d} t j| }g g  }} t|||  t| dks4tt| d jtsHtt| d jts\tt| d jt	sptt| d jt	stt| d jt
stt| d jtstd S )	Nz        +0_initial_default_is_shell
        p fm
        +1_fnmatch
        P re
        +2_regex
        +3_more_regex
        P pp
        +4_pathprefix
        p fm
        p sh
        +5_shell
       r   rM   r            )ioStringIOr	   rN   r   
isinstancevalr   r   r   r   )rC   Zpattern_filerO   r   r   r   test_switch_patterns_style4  s    

r[   rJ   zX /dataz/datac             C   sn   | j d}|jd}|jdj | W d Q R X t|}tjtj  g }g }tt|d|| W d Q R X d S )Nzpatterns.txtrE   rF   r=   )	rG   r@   rH   r.   pytestraisesargparseZArgumentTypeErrorr	   )rI   rJ   rQ   rK   rB   rO   rP   r   r   r   $test_load_invalid_patterns_from_fileN  s    
r_   z-*/something0?.txtz/data/subdir/something01.txtz	/home/leoz/home/leo/tz/home/otherz-fm:*/something00.txtz-fm:*/something0?.txtz+/*/something0?.txtz
+/home/leoz-/home/*z+fm:/home/leoz-/home/c          
      sr   dddddddg  fdd	}| j d
}|jd}|jdj | W d Q R X |t||d krd n|ksntd S )Nz/dataz/data/something00.txtz/data/subdir/something01.txtz/homez	/home/leoz/home/leo/tz/home/otherc                s@   t dd g }g }tt| d||  j|  fddD S )NT)r>   r=   c                s   g | ]} j |r|qS r   )r   )r   r   )r?   r   r   r     s    zFtest_inclexcl_patterns_from_file.<locals>.evaluate.<locals>.<listcomp>)r   r	   r@   rA   )rB   rO   rP   )r   )r?   r   rD     s    

z2test_inclexcl_patterns_from_file.<locals>.evaluatezpatterns.txtrE   rF   )rG   r@   rH   r.   r   )rI   rJ   r   rD   rQ   rK   r   )r   r    test_inclexcl_patterns_from_file]  s    !
r`   zpattern, clsz/data/*zfm:zfm:*z
fm:/data/*zfm:fm:/data/*zre:zre:^/something/zre:re:^/something/zpp:z	pp:/data/zpp:pp:/data/zsh:zsh:*z
sh:/data/*zsh:sh:/data/*c             C   s   t t| |std S )N)rY   r
   r   )r   clsr   r   r   test_parse_pattern  s     rb   zaa:zfo:*z00:zx1:abcc          	   C   s"   t jt t|  W d Q R X d S )N)r\   r]   
ValueErrorr
   )r   r   r   r   test_parse_pattern_error  s    rd   c              C   s  t  } | jd kstxdD ]}| j|d kstqW xdD ]}|| j|< q:W | jtdgd | jtd	td
gd | jtdgd d| _| jddkst| jddkst| jddkst| jddkst| jddkst| jddk stt ddjdkstd S )Nr   r!   barABEmptyFileNotFoundz^az^bz^zz^$ZaaaZbbbZcccZxyzzzhey!)r>   )r   r!   re   )rf   rg   rh   ri   )r   r>   r   r   Zis_include_cmdaddr   )Zpmitargetr   r   r   test_pattern_matcher  s"    

rn   )r   N)r   N)r#   N)r$   N)r%   N)r&   N)r'   N)r%   N)r)   N)r*   N)r$   N)r&   N)r'   N)r   N)r,   N)r-   N))r^   rW   Zos.pathr   r4   r\   rC   r   r   r   r   r   r   r	   r
   r   r   ZmarkZparametrizer   r   r    r"   r(   r+   r0   r2   r6   r8   r9   r:   r.   r<   rL   rR   r[   r_   r`   rb   rd   rn   r   r   r   r   <module>   s|  





















 



