B
    u9a,  ć               @   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 e jZ	e	d Z
dZdZej e”Zd ” Zej e	”ZdZdZd	ZG d
d dZG dd deZG dd deZG dd deejZG dd deejZG dd deejZG dd deejZG dd dejZedkre  ”  dS )é    N)Śsupportz.missingz
!@$)(!@#_1Ś zlinecache abcz3
" Docstring "

def function():
    return result

z%
def f():
    return 1 + 1

a = f()

z
def f():
    return 3c                   s   e Zd Z fddZ  ZS )ŚTempFilec          	      sJ   t   ”  tjdd}|j| _| | j” W d Q R X |  t	j
| j” d S )NF)Śdelete)ŚsuperŚsetUpŚtempfileZNamedTemporaryFileŚnameŚ	file_nameŚwriteŚfile_byte_stringŚ
addCleanupr   Śunlink)ŚselfŚfp)Ś	__class__© ś$/usr/lib/python3.7/test_linecache.pyr   *   s
    
zTempFile.setUp)Ś__name__Ś
__module__Ś__qualname__r   Ś__classcell__r   r   )r   r   r   (   s   r   c                   s,   e Zd Z fddZdd Zdd Z  ZS )ŚGetLineTestsGoodDatac                s"   d  | j” d”| _t  ”  d S )Nr   zutf-8)ŚjoinŚ	file_listŚencoder   r   r   )r   )r   r   r   r   5   s    zGetLineTestsGoodData.setUpc          	   C   sb   t  | j”L}xDt|D ]8\}}| d”s2|d7 }t | j|d ”}|  ||” qW W d Q R X d S )NŚ
é   )ŚtokenizeŚopenr
   Ś	enumerateŚendswithŚ	linecacheŚgetlineŚassertEqual)r   r   ŚindexŚlineZcached_liner   r   r   Śtest_getline9   s    
z!GetLineTestsGoodData.test_getlinec             C   s   t  | j”}|  || j” d S )N)r"   Śgetlinesr
   r$   r   )r   Ślinesr   r   r   Śtest_getlinesB   s    z"GetLineTestsGoodData.test_getlines)r   r   r   r   r'   r*   r   r   r   )r   r   r   2   s   	r   c               @   s   e Zd Zdd Zdd ZdS )ŚGetLineTestsBadDatac             C   s   |   ttftj| jd” d S )Nr   )ŚassertRaisesŚSyntaxErrorŚUnicodeDecodeErrorr"   r#   r
   )r   r   r   r   r'   J   s    
z GetLineTestsBadData.test_getlinec             C   s   |   ttftj| j” d S )N)r,   r-   r.   r"   r(   r
   )r   r   r   r   r*   N   s    
z!GetLineTestsBadData.test_getlinesN)r   r   r   r'   r*   r   r   r   r   r+   G   s   r+   c               @   s   e Zd Zg ZdS )Ś	EmptyFileN)r   r   r   r   r   r   r   r   r/   S   s   r/   c               @   s   e Zd ZdgZdS )ŚSingleEmptyLiner   N)r   r   r   r   r   r   r   r   r0   W   s   r0   c               @   s   e Zd ZddddgZdS )ŚGoodUnicodeu   Ć”
zb
zabcdef
u   Ć”Ć”Ć”Ć”Ć”
N)r   r   r   r   r   r   r   r   r1   [   s   r1   c               @   s   e Zd ZdZdS )Ś
BadUnicodes   abcN)r   r   r   r   r   r   r   r   r2   _   s   r2   c               @   sd   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S )ŚLineCacheTestsc          
   C   sŲ   t j}|  |tdt” |  |tdt” |  t|td” |  |tdt” |  |tdt” x^tD ]V}t	j
 t|”d }t|2}x*t|D ]\}}|  ||||d ” qW W d Q R X qdW t  d”}|  |g ” d S )Ni   é’’’’gń?r   z.pyza/b/c/__init__.py)r"   r#   r$   ŚFILENAMEŚEMPTYr,   Ś	TypeErrorŚINVALID_NAMEŚMODULESŚosŚpathr   ŚMODULE_PATHr   r    r(   )r   r#   ŚentryŚfilenameŚfiler%   r&   Śemptyr   r   r   r'   e   s    

(
zLineCacheTests.test_getlinec          	   C   sT   |   tjtj” ttjd}| t” W d Q R X t tj”}|  	|dddg” d S )NŚwr   z	def f():
z    return 3
)
r   r   r   ŚTESTFNr   r   ŚSOURCE_3r"   r(   r$   )r   r   r)   r   r   r   Śtest_no_ending_newline~   s
    z%LineCacheTests.test_no_ending_newlinec             C   s   g }x4t D ],}tj t|”d }| |” t |d” q
W |  |g ” dd |D }|  	|g ” t 
”  dd |D }|  	|g ” d S )Nz.pyr   c             S   s   g | ]}|t jkr|qS r   )r"   Ścache)Ś.0Śfnr   r   r   ś
<listcomp>   s    z2LineCacheTests.test_clearcache.<locals>.<listcomp>c             S   s   g | ]}|t jkr|qS r   )r"   rE   )rF   rG   r   r   r   rH      s    )r9   r:   r;   r   r<   Śappendr"   r#   ZassertNotEqualr$   Ś
clearcache)r   Ścachedr=   r>   Zcached_emptyr   r   r   Śtest_clearcache   s    

zLineCacheTests.test_clearcachec          	   C   sF  t j}tjd }|  tj|” t|d}| t” W d Q R X ||d g }t|<}x4t	|D ](\}}|  
||||d ” | |” q`W W d Q R X t|d}| t” W d Q R X t  d” x*t	|D ]\}}|  
||||d ” qŹW t  |” t|>}x6t	|D ]*\}}|  
||||d ” | |” q
W W d Q R X d S )Nz.pyrA   r   Zdummy)r"   r#   r   rB   r   r   r   r   ŚSOURCE_1r    r$   rI   ŚSOURCE_2Ś
checkcache)r   r#   Zsource_nameŚsourceZsource_listr%   r&   r   r   r   Śtest_checkcache   s*    





zLineCacheTests.test_checkcachec             C   s<   t  t”}t  ”  |  dt  td ”” |  |t  t”” d S )NF)r"   r(   r5   rJ   r$   Ś	lazycache)r   r)   r   r   r   Śtest_lazycache_no_globals·   s    
z(LineCacheTests.test_lazycache_no_globalsc             C   sX   t  tt ”}t  ”  |  dt  tt ”” |  dtt jt ” |  |t  t”” d S )NTr   )	r"   r(   ŚNONEXISTENT_FILENAMEŚglobalsrJ   r$   rR   ŚlenrE   )r   r)   r   r   r   Śtest_lazycache_smoke½   s    z#LineCacheTests.test_lazycache_smokec             C   sL   t  ”  t  tt ”}t  ”  t  t” t  tt ” |  |t  t”” d S )N)r"   rJ   r(   rT   rU   rR   r$   Śupdatecache)r   r)   r   r   r   Ś*test_lazycache_provide_after_failed_lookupĒ   s    
z9LineCacheTests.test_lazycache_provide_after_failed_lookupc             C   s"   t  ”  t  tt ” t  ”  d S )N)r"   rJ   rR   rT   rU   rO   )r   r   r   r   Śtest_lazycache_checkĻ   s    z#LineCacheTests.test_lazycache_checkc             C   s8   t  ”  |  dt  dt ”” |  dt  dt ”” d S )NFr   z<foo>)r"   rJ   r$   rR   rU   )r   r   r   r   Śtest_lazycache_bad_filenameŌ   s    z*LineCacheTests.test_lazycache_bad_filenamec             C   sF   t  ”  t  tt ”}|  dt  tt ”” |  dtt jt ” d S )NFé   )	r"   rJ   r(   rT   rU   r$   rR   rV   rE   )r   r)   r   r   r   Śtest_lazycache_already_cachedŁ   s    z,LineCacheTests.test_lazycache_already_cachedc          	   C   s   t  t”}|  |” dd }t t d|” t  t”}W d Q R X |  ||” t  ”  t t d|” t  t”}W d Q R X |  |g ” |  t  t”|” d S )Nc              _   s   t d S )N)ŚMemoryError)ŚargsŚkwargsr   r   r   Śraise_memoryerrorä   s    z:LineCacheTests.test_memoryerror.<locals>.raise_memoryerrorrX   )r"   r(   r5   Z
assertTruer   Z	swap_attrr$   rJ   )r   r)   ra   Zlines2Zlines3r   r   r   Śtest_memoryerrorį   s    

zLineCacheTests.test_memoryerrorN)r   r   r   r'   rD   rL   rQ   rS   rW   rY   rZ   r[   r]   rb   r   r   r   r   r3   c   s   !
r3   Ś__main__)!r"   ZunittestZos.pathr:   r   r   Ztestr   Ś__file__r5   rT   r8   r6   r;   ŚdirnameZ	TEST_PATHŚsplitr9   r<   rM   rN   rC   r   r   r+   ZTestCaser/   r0   r1   r2   r3   r   Śmainr   r   r   r   Ś<module>   s4   
 
