
­­­­­­­­­­­­­­­­­­
<!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                s    fdd| D }dS )z"Utility for testing patterns.
    c                s   g | ]} j |r|qS  )match).0f)patternr    /usr/lib64/python3.6/patterns.py
<listcomp>   s    z"check_patterns.<locals>.<listcomp>Nr   )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   s2   ddddddddd	d
dg}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   r   )r   r   r   objr   r   r   test_patterns_regex   s    r*   c               C   s   d S )Nr   r   r   r   r   test_regex_pattern   s    r+   c               C   s
   t jdkS )Ndarwin)r,   )sysplatformr   r   r   r   use_normalized_unicode   s    r/   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    r1   r   u   bác             C   s   d S )Nr   )r   r   r   r   test_composed_unicode_pattern   s    r2   u   bác             C   s   d S )Nr   )r   r   r   r   test_decomposed_unicode_pattern   s    r3   s   balatin1c             C   s   d S )Nr   )r   r   r   r   test_invalid_unicode_pattern   s    r5   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 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   path)matcherr   r   r     s    zEtest_exclude_patterns_from_file.<locals>.evaluate.<locals>.<listcomp>)r   openr   add_inclexcl)filenamepatterns)r   )r9   r   evaluate  s
    

z1test_exclude_patterns_from_file.<locals>.evaluatezexclude.txtwt
)joinr:   write)tmpdirlinesr   r>   Zexclfilefhr   )r   r   test_exclude_patterns_from_file   s    '
rF   z+lines, expected_roots, expected_numpatternsz- *   z+fm:*/something00.txtz-/datazR /z	# commentz- /datazR /homec       	   
   C   sL   dd }| j d}|jd}|jdj | W d Q R X |t|\}}d S )Nc             S   s&   g }g }t t| d|| |t|fS )Nr6   )r	   r:   len)r<   rootsinclexclpatternsr   r   r   r>   %  s    z.test_load_patterns_from_file.<locals>.evaluatezpatterns.txtr?   r@   )rA   r:   rB   str)	rC   rD   Zexpected_rootsZexpected_numpatternsr>   patternfilerE   rI   Znumpatternsr   r   r   test_load_patterns_from_file  s    
rM   c              C   s(   d} t j| }g g  }} t|||  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
    )ioStringIOr	   )r=   Zpattern_filerI   r   r   r   test_switch_patterns_style4  s
    

rP   rD   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.txtr?   r@   r6   )	rA   r:   rB   rK   pytestraisesargparseZArgumentTypeErrorr	   )rC   rD   rL   rE   r<   rI   rJ   r   r   r   $test_load_invalid_patterns_from_fileN  s    
rT   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 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)r7   r6   c                s   g | ]} j |r|qS r   )r   )r   r8   )r9   r   r   r     s    zFtest_inclexcl_patterns_from_file.<locals>.evaluate.<locals>.<listcomp>)r   r	   r:   r;   )r<   rI   rJ   )r   )r9   r   r>     s    

z2test_inclexcl_patterns_from_file.<locals>.evaluatezpatterns.txtr?   r@   )rA   r:   rB   )rC   rD   r   r>   rL   rE   r   )r   r    test_inclexcl_patterns_from_file]  s    !
rU   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   d S )Nr   )r   clsr   r   r   test_parse_pattern  s     rW   zaa:zfo:*z00:zx1:abcc          	   C   s"   t jt t|  W d Q R X d S )N)rQ   rR   
ValueErrorr
   )r   r   r   r   test_parse_pattern_error  s    rY   c              C   sr   t  } xdD ]}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| _d S )Nr   r   barABEmptyFileNotFoundz^az^bz^zz^$)r   r   rZ   )r[   r\   r]   r^   )r   Zis_include_cmdaddr   r7   )Zpmitargetr   r   r   test_pattern_matcher  s    

	rb   )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))rS   rN   Zos.pathosr-   rQ   r=   r   r   r   r   r   r   r	   r
   r   r   ZmarkZparametrizer   r   r   r   r#   r&   r*   r+   r/   r1   r2   r3   rK   r5   rF   rM   rP   rT   rU   rW   rY   rb   r   r   r   r   <module>   s|  





















 



