
    5\h),                        d 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 ej        Zedz   ZdZdZej                            e          Zd	                                Zej                            e          Zd
ZdZdZ G d d          Z G d de          Z G d de          Z G d deej                  Z G d deej                  Z  G d deej                  Z! G d deej                  Z" G d deej                  Z# G d d          Z$ G d d           Z% G d! d"ej                  Z& G d# d$ej                  Z'e(d%k    r ej)                     dS dS )&z  Tests for the linecache module     N)
ModuleSpec)support)	os_helperz.missingz
!@$)(!@#_1 zlinecache abcz3
" Docstring "

def function():
    return result

z%
def f():
    return 1 + 1

a = f()

z
def f():
    return 3c                        e Zd Z fdZ xZS )TempFilec                 8   t                                                       t          j        d          5 }|j        | _        |                    | j                   d d d            n# 1 swxY w Y   |                     t          j
        | j                   d S )NF)delete)supersetUptempfileNamedTemporaryFilename	file_namewritefile_byte_string
addCleanupr   unlink)selffp	__class__s     =/opt/python-3.11.14/usr/lib/python3.11/test/test_linecache.pyr   zTempFile.setUp,   s    (666 	,"WDNHHT*+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 		($.99999s   'A**A.1A.)__name__
__module____qualname__r   __classcell__r   s   @r   r   r   *   s8        : : : : : : : : :    r   c                   *     e Zd Z fdZd Zd Z xZS )GetLineTestsGoodDatac                     d                     | j                                      d          | _        t	                                                       d S )Nr   utf-8)join	file_listencoder   r   r   )r   r   s    r   r   zGetLineTestsGoodData.setUp7   s<     " 7 7 > >w G Gr   c                 0   t          j        | j                  5 }t          |          D ]R\  }}|                    d          s|dz  }t          j        | j        |dz             }|                     ||           S	 d d d            d S # 1 swxY w Y   d S )N
   )tokenizeopenr   	enumerateendswith	linecachegetlineassertEqual)r   r   indexlinecached_lines        r   test_getlinez!GetLineTestsGoodData.test_getline;   s    ]4>** 	4b(}} 4 4t}}T** !DLD'/	JJ  {33334	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   A#BBBc                 n    t          j        | j                  }|                     || j                   d S N)r-   getlinesr   r/   r$   r   liness     r   test_getlinesz"GetLineTestsGoodData.test_getlinesD   s2    "4>22/////r   )r   r   r   r   r3   r9   r   r   s   @r   r    r    4   sV            4 4 40 0 0 0 0 0 0r   r    c                       e Zd Zd Zd ZdS )GetLineTestsBadDatac                 b    |                      t          j        | j        d          d           d S )Nr(   r   )r/   r-   r.   r   r   s    r   r3   z GetLineTestsBadData.test_getlineL   s-    *4>1==rBBBBBr   c                 `    |                      t          j        | j                  g            d S r5   )r/   r-   r6   r   r=   s    r   r9   z!GetLineTestsBadData.test_getlinesO   s+    +DN;;R@@@@@r   N)r   r   r   r3   r9    r   r   r;   r;   I   s:        C C CA A A A Ar   r;   c                       e Zd Zg ZdS )	EmptyFileNr   r   r   r$   r?   r   r   rA   rA   S   s        IIIr   rA   c                       e Zd ZdgZdS )SingleEmptyLiner'   NrB   r?   r   r   rD   rD   W   s        IIIr   rD   c                       e Zd Zg dZdS )GoodUnicode)u   á
zb
zabcdef
u   ááááá
NrB   r?   r   r   rF   rF   [   s        ;;;IIIr   rF   c                       e Zd ZdZdS )BadUnicode_NoDeclarations   
abcNr   r   r   r   r?   r   r   rH   rH   ^   s        #r   rH   c                       e Zd ZdZdS )BadUnicode_WithDeclarations   # coding=utf-8
abcNrI   r?   r   r   rK   rK   a   s        1r   rK   c                       e Zd Zd ZdS )
FakeLoaderc                     d| S )Nzsource for r?   r   fullnames     r   
get_sourcezFakeLoader.get_sourcef   s    'X'''r   Nr   r   r   rQ   r?   r   r   rM   rM   e   s#        ( ( ( ( (r   rM   c                       e Zd Zd ZdS )NoSourceLoaderc                     d S r5   r?   rO   s     r   rQ   zNoSourceLoader.get_sourcek   s    tr   NrR   r?   r   r   rT   rT   j   s#            r   rT   c                   V    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )LineCacheTestsc                 .   t           j        }|                      |t          d          t                     |                      |t          d          t                     |                     t          |t          d           |                      |t          d          t                     |                      |t          d          t                     t          D ]}t          j
                            t          |          dz   }t          |d          5 }t          |          D ](\  }}|                     | |||dz                        )	 d d d            n# 1 swxY w Y   t          j        d          }|                     |g            d S )	Ni   g?r(   .pyr"   encodingza/b/c/__init__.py)r-   r.   r/   FILENAMEEMPTYassertRaises	TypeErrorINVALID_NAMEMODULESospathr#   MODULE_PATHr*   r+   r6   )r   r.   entryfilenamefiler0   r1   emptys           r   r3   zLineCacheTests.test_getlineq   s   # 	51159992..666 	)Wh<<< 	**E222q115999  	I 	IEw||K77%?Hh111 IT#,T?? I IKE4$$T778UQY+G+GHHHHII I I I I I I I I I I I I I I
 "#677#####s   9EE#	&E#	c                 b   |                      t          j        t          j                   t	          t          j        dd          5 }|                    t                     d d d            n# 1 swxY w Y   t          j        t          j                  }| 	                    |g d           d S )Nwr"   r[   )r'   z	def f():
z    return 3
)
r   r   r   TESTFNr*   r   SOURCE_3r-   r6   r/   )r   r   r8   s      r   test_no_ending_newlinez%LineCacheTests.test_no_ending_newline   s    	()*:;;;)"C'::: 	bHHX	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"9#344 F F FGGGGGs   A..A25A2c                    g }t           D ]T}t          j                            t          |          dz   }|                    |           t          j        |d           U|                     |g            d |D             }| 	                    |g            t          j
                     d |D             }| 	                    |g            d S )NrZ   r(   c                 .    g | ]}|t           j        v|S r?   r-   cache.0fns     r   
<listcomp>z2LineCacheTests.test_clearcache.<locals>.<listcomp>   s$    IIIrr/H/H/H/H/Hr   c                 .    g | ]}|t           j        v |S r?   rq   rs   s     r   rv   z2LineCacheTests.test_clearcache.<locals>.<listcomp>   s$    EEErrY_/D/D/D/D/Dr   )rb   rc   rd   r#   re   appendr-   r.   assertNotEqualr/   
clearcache)r   cachedrf   rg   cached_emptys        r   test_clearcachezLineCacheTests.test_clearcache   s     	+ 	+Ew||K77%?HMM(###h**** 	FB'''IIVIIIr*** 	EEVEEEr*****r   c           
      F   t           j        }t          j        dz   }|                     t          j        |           t          |dd          5 }|                    t                     d d d            n# 1 swxY w Y    ||d           g }t          |d          5 }t          |          D ]=\  }}| 
                    | |||dz                        |                    |           >	 d d d            n# 1 swxY w Y   t          |dd          5 }|                    t                     d d d            n# 1 swxY w Y   t          j        d           t          |          D ](\  }}| 
                    | |||dz                        )t          j        |           t          |d          5 }t          |          D ]=\  }}| 
                    | |||dz                        |                    |           >	 d d d            d S # 1 swxY w Y   d S )NrZ   rk   r"   r[   r(   dummy)r-   r.   r   rl   r   r   r*   r   SOURCE_1r+   r/   rx   SOURCE_2
checkcache)r   r.   source_namesourcesource_listr0   r1   s          r   test_checkcachezLineCacheTests.test_checkcache   s<   #&.	(+666+sW555 	#LL"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#Q +000 	)F(00 ) )t  ww{EAI'F'FGGG""4(((()	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)
 +sW555 	#LL"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	W%%% %[11 	D 	DKE4T77;	#B#BCCCC 	[)))+000 	)F(00 ) )t  ww{EAI'F'FGGG""4(((()	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)sJ   A55A9<A9AC::C>C>D>>EE:AHHHc                    t          j        t                    }t          j                     |                     dt          j        t          d                      |                     |t          j        t                               d S )NF)r-   r6   r]   rz   r/   	lazycacher7   s     r   test_lazycache_no_globalsz(LineCacheTests.test_lazycache_no_globals   sk    "8,,	 3Hd C CDDD	 28 < <=====r   c                    t          j        t          t                                }t          j                     |                     dt          j        t          t                                           |                     dt          t           j        t                                        |                     |t          j        t                               d S )NTr(   )	r-   r6   NONEXISTENT_FILENAMEglobalsrz   r/   r   lenrr   r7   s     r   test_lazycache_smokez#LineCacheTests.test_lazycache_smoke   s    "#7CC)%&:GIIFF	H 	H 	HC	0D EFFGGG 		 23G H HIIIIIr   c                 v   t          j                     t          j        t          t	                                }t          j                     t          j        t                     t          j        t          t	                                 |                     |t          j        t                               d S r5   )r-   rz   r6   r   r   r   r/   updatecacher7   s     r   *test_lazycache_provide_after_failed_lookupz9LineCacheTests.test_lazycache_provide_after_failed_lookup   s    "#7CC/0000'))<<<	 56J K KLLLLLr   c                     t          j                     t          j        t          t	                                 t          j                     d S r5   )r-   rz   r   r   r   r   r=   s    r   test_lazycache_checkz#LineCacheTests.test_lazycache_check   s>    0'))<<<r   c                     t          j                     |                     dt          j        dt	                                           |                     dt          j        dt	                                           d S )NFr   z<foo>)r-   rz   r/   r   r   r=   s    r   test_lazycache_bad_filenamez*LineCacheTests.test_lazycache_bad_filename   se    	 3B		 B BCCC	 3GWYY G GHHHHHr   c                 \   t          j                     t          j        t          t	                                }|                     dt          j        t          t	                                           |                     dt          t           j        t                                        d S )NF   )	r-   rz   r6   r   r   r/   r   r   rr   r7   s     r   test_lazycache_already_cachedz,LineCacheTests.test_lazycache_already_cached   s    "#7CC 4gii@@	B 	B 	B 	C	0D EFFGGGGGr   c                 p   t          j        t                    }|                     |           d }t	          j        t           d|          5  t          j        t                    }d d d            n# 1 swxY w Y   |                     ||           t          j                     t	          j        t           d|          5  t          j        t                    }d d d            n# 1 swxY w Y   |                     |g            |                     t          j        t                    |           d S )Nc                      t           r5   )MemoryError)argskwargss     r   raise_memoryerrorz:LineCacheTests.test_memoryerror.<locals>.raise_memoryerror   s    r   r   )r-   r6   r]   
assertTruer   	swap_attrr/   rz   )r   r8   r   lines2lines3s        r   test_memoryerrorzLineCacheTests.test_memoryerror   s   "8,,	 	 	y-9JKK 	2 	2'11F	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2'''y-9JKK 	2 	2'11F	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2$$$+H55u=====s$   A33A7:A7C((C,/C,c                 *   d}d t                      t                      fD ]C}t          j                     d|d}|                     t          j        ||          g            Dt          j                     dt                      d}|                     t          j        ||          dg           d t                      t          dt                                fD ]Q}t          j                     dt                      |d}|                     t          j        ||          dg           Rt          j                     t          dt                                }d|j        |d}|                     t          j        ||          dg           d S )	Nzscheme://pathza.b.c)r   
__loader__zsource for a.b.c
r   )r   r   __spec__zx.y.zzsource for x.y.z
)	objectrT   r-   rz   r/   r6   rM   r   loader)r   rg   r   module_globalsspecs        r   test_loaderzLineCacheTests.test_loader   s   "VXX~'7'78 	O 	OF """*1HHNY/.II2NNNN&-Z\\JJ+HnEE./	1 	1 	1 688ZJLL%A%AB 	5 	5D """*1*.0 0NY/.II235 5 5 5 	':<<00&-T[&*, ,+HnEE./	1 	1 	1 	1 	1r   N)r   r   r   r3   rn   r}   r   r   r   r   r   r   r   r   r   r?   r   r   rW   rW   o   s        $ $ $2H H H+ + +") ) )B> > >J J JM M M  
I I I
H H H> > >1 1 1 1 1r   rW   c                   0     e Zd Z fdZd Zd Zd Z xZS )LineCacheInvalidationTestsc                 >   t                                                       t          j                     t          j        dz   | _        t          j        dz   | _        t          j        dz   | _        | j        | j        | j        fD ]}| 	                    t          j
        |           t          |dd          5 }|                    d| d           d d d            n# 1 swxY w Y   |                     |t          j                   t          j        |           |                     |t          j                   t#          j        | j                   t          | j        dd          5 }|                    d	           d d d            d S # 1 swxY w Y   d S )
Nz.1z.2z.3rk   r"   r[   zprint("I am z")zprint("was modified"))r   r   r-   rz   r   rl   deleted_filemodified_fileunchanged_filer   r   r*   r   assertNotInrr   r6   assertInrc   remove)r   fnamer   r   s      r   r   z LineCacheInvalidationTests.setUp  s   %,t3&-4'.5'()+ 		2 		2E OOI,e444eS7333 7v5E5556667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 UIO444u%%%MM%1111
	$#$$$$$cG<<< 	2LL0111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s$   9CC#	&C#	/FFFc                    t          j        | j                   |                     | j        t           j                   |                     | j        t           j                   |                     | j        t           j                   d S r5   )r-   r   r   r   rr   r   r   r   r=   s    r    test_checkcache_for_deleted_filez;LineCacheInvalidationTests.test_checkcache_for_deleted_file/  si    T.///*IO<<<d()/:::d)9?;;;;;r   c                    t          j        | j                   |                     | j        t           j                   |                     | j        t           j                   |                     | j        t           j                   d S r5   )r-   r   r   r   r   rr   r   r   r=   s    r   !test_checkcache_for_modified_filez<LineCacheInvalidationTests.test_checkcache_for_modified_file5  si    T/000d'999+Y_===d)9?;;;;;r   c                 
   t          j                     |                     | j        t           j                   |                     | j        t           j                   |                     | j        t           j                   d S r5   )r-   r   r   r   rr   r   r   r   r=   s    r   !test_checkcache_with_no_parameterz<LineCacheInvalidationTests.test_checkcache_with_no_parameter;  sf    *IO<<<+Y_===d)9?;;;;;r   )r   r   r   r   r   r   r   r   r   s   @r   r   r     se        2 2 2 2 2,< < << < << < < < < < <r   r   __main__)*__doc__r-   unittestos.pathrc   r   r)   importlib.machineryr   testr   test.supportr   __file__r]   r   ra   r^   rd   dirname	TEST_PATHsplitrb   re   r   r   rm   r   r    r;   TestCaserA   rD   rF   rH   rK   rM   rT   rW   r   r   mainr?   r   r   <module>r      s*   & &         * * * * * *       " " " " " " *, 
GOOH%%	



!
!gooh''
: : : : : : : :0 0 0 0 08 0 0 0*A A A A A( A A A    $h&7       *H,=   < < < < <&(9 < < <$ $ $ $ $2H4E $ $ $2 2 2 2 2!4h6G 2 2 2( ( ( ( ( ( ( (
       
f1 f1 f1 f1 f1X& f1 f1 f1R'< '< '< '< '<!2 '< '< '<T zHMOOOOO r   