
    <eX                     P   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
Z
d dlZd dlZd dlZd dlZ ej        d            G d d	e          Zd
 Z G d d          Z G d dej        e          Z G d dej        e          Zd Zedk    r ej                     dS dS )    N)DocTestSuite)support)threading_helper)import_moduleT)modulec                       e Zd ZdS )WeakN__name__
__module____qualname__     0/usr/lib/python3.11/test/test_threading_local.pyr	   r	      s        Dr   r	   c                 ~    t                      }|| _        |                    t          j        |                     d S N)r	   weakappendweakrefref)localweaklistr   s      r   targetr      s4    66DEJOOGK%%&&&&&r   c                   \    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 ZdS )BaseLocalTestc                     |                      d           |                      d           |                      d           d S )N   2   d   )_local_refsselfs    r   test_local_refszBaseLocalTest.test_local_refs   sD    r   c                 r   |                                  }g }t          |          D ]G}t          j        t          ||f          }|                                 |                                 H~t          j                     | 	                    t          |          |           d |D             }|                     t          |          |dz
  |f           d |_        t          j                     d |D             }|                     t          |          |dz
  |f|t          |          f           d S )Nr   argsc                 &    g | ]} |            |S r   r   .0r   s     r   
<listcomp>z-BaseLocalTest._local_refs.<locals>.<listcomp>0       @@@TDr      c                 &    g | ]} |            |S r   r   r(   s     r   r*   z-BaseLocalTest._local_refs.<locals>.<listcomp>6   r+   r   )_localrange	threadingThreadr   startjoinr   
gc_collectassertEquallenassertInsomeothervar)r"   nr   r   itdeadlists          r   r    zBaseLocalTest._local_refs#   s&   q 	 	A eX5FGGGAGGIIIFFHHHHX*** A@X@@@c(mmac1X... "@@X@@@c(mmac1X3x==/ABBBBBr   c                      dd l  G fdd j                  } |             fdt          j        fdt	          d          D                       5  	 d d d            d S # 1 swxY w Y   d S )Nr   c                       e Zd Z fdZdS ))BaseLocalTest.test_derived.<locals>.Localc                 2                         d           d S )Ng{Gz?)sleep)r"   times    r   __init__z2BaseLocalTest.test_derived.<locals>.Local.__init__@   s    

4     r   Nr   r   r   rC   )rB   s   r   Localr?   ?   s.        ! ! ! ! ! ! !r   rE   c                 L    | _                             j         |            d S r   )xr5   )r:   r   r"   s    r   fz%BaseLocalTest.test_derived.<locals>.fD   s(    EGUWa(((((r   c              3   F   K   | ]}t          j        |f           V  dS )r%   N)r0   r1   )r)   r:   rH   s     r   	<genexpr>z-BaseLocalTest.test_derived.<locals>.<genexpr>I   sQ       ,@ ,@01 -6,<AQD,Q,Q,Q ,@ ,@ ,@ ,@ ,@ ,@r   
   )rB   r.   r   start_threadsr/   )r"   rE   rH   r   rB   s   ` @@@r   test_derivedzBaseLocalTest.test_derived9   s#   
 		! 	! 	! 	! 	! 	! 	!DK 	! 	! 	! 	) 	) 	) 	) 	) 	)
 + ,@ ,@ ,@ ,@5:2YY,@ ,@ ,@ @ @ 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A**A.1A.c                     G d d| j                   d dt          j                    t          j                    fd}t          j        |          }|                                                                  fdt          d          D                                              |                                 | 	                               d S )Nc                       e Zd ZdS )7BaseLocalTest.test_derived_cycle_dealloc.<locals>.LocalNr
   r   r   r   rE   rP   O           Dr   rE   Fc                                  g} |                      |            d| d         _        ~ t          j                                                                                       t          d D                       d S )Nbarr   c              3   8   K   | ]}t          |d            V  dS )fooN)hasattr)r)   r   s     r   rJ   zFBaseLocalTest.test_derived_cycle_dealloc.<locals>.f.<locals>.<genexpr>e   s/      GGuWUE222GGGGGGr   )r   rU   r   r4   setwaitall)cyclerE   e1e2localspasseds    r   rH   z3BaseLocalTest.test_derived_cycle_dealloc.<locals>.fV   s     UWWIELL E!HL    FFHHHGGIII GGGGGGGFFFr   r   c                 $    g | ]}             S r   r   )r)   r:   rE   s     r   r*   z<BaseLocalTest.test_derived_cycle_dealloc.<locals>.<listcomp>n   s    ---a%%''---r   rK   )
r.   r0   Eventr1   r2   rX   r/   rW   r3   
assertTrue)r"   rH   r;   rE   r[   r\   r]   r^   s      @@@@@r   test_derived_cycle_deallocz(BaseLocalTest.test_derived_cycle_deallocM   s   	 	 	 	 	DK 	 	 	__	H 	H 	H 	H 	H 	H 	H 	H 	H" A&&&				
			
 .---599---
	r   c                      G d d| j                   } |d            |d           |                     t          | j         d           |                     t          | j         d           d S )Nc                       e Zd Zd ZdS )-BaseLocalTest.test_arguments.<locals>.MyLocalc                     d S r   r   )r"   r&   kwargss      r   rC   z6BaseLocalTest.test_arguments.<locals>.MyLocal.__init__w   s    r   NrD   r   r   r   MyLocalrf   v   s#            r   ri   r,   )a)r.   assertRaises	TypeError)r"   ri   s     r   test_argumentszBaseLocalTest.test_argumentst   s    	 	 	 	 	dk 	 	 	 	!


)T[A666)T[!44444r   c                     d _                      t          j                    t          j                    fd} fd}t          j        |          }|                                                                  t          j        |          }|                                 |                                                                  |                                                       j          j                    d S )Nz No error message set or cleared.c                  x    d_         d_        `                                                                   d S )NrU   rS   )rG   yrW   rX   )r[   r\   objs   r   f1z)BaseLocalTest._test_one_class.<locals>.f1   s4    CECEFFHHHGGIIIIIr   c                      	 j         } d| dd_        t          j                            j                   d S # t
          $ r d_        Y d S w xY w)NzIncorrectly got value z from class 
 )rG   _failedsysstderrwriteAttributeError)rU   crq   r"   s    r   f2z)BaseLocalTest._test_one_class.<locals>.f2   sq    /e "%aaa!)
  ..... " " " "!"s   > AAr_   )	rv   r0   ra   r1   r2   rX   r3   rW   assertFalse)	r"   r{   rr   r|   t1t2r[   r\   rq   s	   ``    @@@r   _test_one_classzBaseLocalTest._test_one_class   s   9acc__	 	 	 	 	 	 			/ 		/ 		/ 		/ 		/ 		/ 		/ R(((




			R(((




			

			t|44444r   c                 :    |                      | j                   d S r   )r   r.   r!   s    r   test_threading_localz"BaseLocalTest.test_threading_local   s    T[)))))r   c                 V     G d d| j                   }|                     |           d S )Nc                       e Zd ZdS )BBaseLocalTest.test_threading_local_subclass.<locals>.LocalSubclassNr
   r   r   r   LocalSubclassr              ::r   r   )r.   r   r"   r   s     r   test_threading_local_subclassz+BaseLocalTest.test_threading_local_subclass   sH    	; 	; 	; 	; 	;DK 	; 	; 	;]+++++r   c                 >    |            }d|_         |                     |j        ddi           |                     t                    5  i |_        d d d            n# 1 swxY w Y   |                     t                    5  |`d d d            d S # 1 swxY w Y   d S )N   rG   )rG   r5   __dict__rk   rz   )r"   clsrq   s      r   _test_dict_attributez"BaseLocalTest._test_dict_attribute   s   ceeQx000~.. 	 	CL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   	AA!$A!BBBc                 :    |                      | j                   d S r   )r   r.   r!   s    r   test_dict_attributez!BaseLocalTest.test_dict_attribute   s    !!$+.....r   c                 V     G d d| j                   }|                     |           d S )Nc                       e Zd ZdS )ABaseLocalTest.test_dict_attribute_subclass.<locals>.LocalSubclassNr
   r   r   r   r   r      r   r   r   )r.   r   r   s     r   test_dict_attribute_subclassz*BaseLocalTest.test_dict_attribute_subclass   sH    	; 	; 	; 	; 	;DK 	; 	; 	;!!-00000r   c                     G d d          } |            }|                                  |_        ||j        _        t          j        |          }~t          j                     |                      |                       d S )Nc                       e Zd ZdS ).BaseLocalTest.test_cycle_collection.<locals>.XNr
   r   r   r   Xr      rQ   r   r   )r.   r   rG   r   r   r   r4   assertIsNone)r"   r   rG   wrs       r   test_cycle_collectionz#BaseLocalTest.test_cycle_collection   s    	 	 	 	 	 	 	 	 ACC++--	[^^""$$r   c                     t          d          }|                    d d           t          d          D ]}t          j                    }|                                 d S )N	_testcapic                      d S r   r   r   r   r   <lambda>z?BaseLocalTest.test_threading_local_clear_race.<locals>.<lambda>   s    T r   Fi  )r   call_in_temporary_c_threadr/   r0   r   join_temporary_c_thread)r"   r   _s      r   test_threading_local_clear_racez-BaseLocalTest.test_threading_local_clear_race   se     "+..	,,\\5AAAt 	" 	"A!!AA))+++++r   N)r   r   r   r#   r    rM   rc   rm   r   r   r   r   r   r   r   r   r   r   r   r   r      s          
C C C,  (%  %  % N	5 	5 	5"5 "5 "5H* * *, , ,
  / / /1 1 1

  
  
 	, 	, 	, 	, 	,r   r   c                       e Zd Zej        ZdS )ThreadLocalTestN)r   r   r   _threadr.   r   r   r   r   r      s        ^FFFr   r   c                       e Zd Zej        ZdS )PyThreadingLocalTestN)r   r   r   _threading_localr   r.   r   r   r   r   r      s        #FFFr   r   c                     |                     t          d                     t          j        d }fd}|                    t          d||                     |S )Nr   c                 2    t           j        t          _        d S r   )r   r.   r   r   )tests    r   setUpzload_tests.<locals>.setUp   s    !(r   c                      t           _        d S r   )r   r   )r   
local_origs    r   tearDownzload_tests.<locals>.tearDown   s    !+r   )r   r   )addTestr   r   r   addTests)loadertestspatternr   r   r   s        @r   
load_testsr      s    	MM,122333!'J0 0 0, , , , ,	NN< 2&+h@ @ @    Lr   __main__)rw   unittestdoctestr   r   r   test.supportr   test.support.import_helperr   r   gcr   r0   r   requires_working_threadingobjectr	   r   r   TestCaser   r   r   r   mainr   r   r   <module>r      s   



                    ) ) ) ) ) ) 4 4 4 4 4 4  				          ,  +4 8 8 8 8	 	 	 	 	6 	 	 	' ' 'v, v, v, v, v, v, v, v,r    h'   $ $ $ $ $8,m $ $ $   zHMOOOOO r   