
    Ng$              	       X   d 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	 ddl
mZ ddl
m
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mZ ej        dd         dk    Zej        dd         dk    Zej                            d          Zej                            d          Zej                            d          peZej                            d          ZepeZ ej                            d          Z! G d de"          Z# G d d e#dej$        fi                     Z$dS )z
Tests for greenlet.

    N)collect)get_objects)active_count)sleep)time)greenlet)
getcurrent)get_pending_cleanup_count)get_total_main_greenlets   )	leakcheck   )      )r      winGITHUB_ACTIONSTRAVISAPPVEYORGREENLET_MANYLINUXc                       e Zd Zd ZdS )TestCaseMetaClassc                 6   d}t          |                                          D ]Y\  }}|                    d          r?t          |          r0|                    |           |rt          j        |          }|||<   Zt                              | |||          S )NTtest)	listitems
startswithcallablepopr   wrap_refcounttype__new__)cls	classnamebases	classDictcheck_totalrefcountkeyvalues          S/var/www/html/ai-engine/env/lib/python3.11/site-packages/greenlet/tests/__init__.pyr"   zTestCaseMetaClass.__new__'   s    
 #
 y0011 	' 	'JC~~f%% '(5// 'c"""& ;%3E::E!&	#||CE9===    N)__name__
__module____qualname__r"    r+   r*   r   r   $   s#        > > > > >r+   r   c                   z     e Zd ZdZdZ	 	 ddZedfdZdZdZ	dZ
dZd	 Z fd
Z fdZd Zd ZddZddZ xZS )TestCasegMbP?r   Nc                 \   |p| j         }|p| j        }| j        }t          |           t	                      | j        z   }t                      s+t                      |k    s| j        st                      |k    rt          |           t	                      |k    rLt          d           t          d|dt                                 t          d|dt                                 n9t                      {t                      |k    | j        st                      |k    t                       d S )NzTime limit exceeded.zThreads: Waiting for onlyz-->zMGlets : Waiting for only)threads_before_testmain_greenlets_before_testcleanup_attempt_sleep_durationr   r   cleanup_max_sleep_secondsr
   active_thread_countexpect_greenlet_leakr   printr   )selfinitial_active_threadsinitial_main_greenlets
sleep_time
quit_afters        r*   wait_for_pending_cleanupsz"TestCase.wait_for_pending_cleanupsB   sO    "8!S4;S!7!Z4;Z8
 	jVVd<<
 *++	&((+AAA1 B0225KKK*vv
"",---13I0224 4 413I5779 9 9 *++	&((+AAA1 B0225KKK 						r+   Tc                     t          d          D ]}t                       |r't          fdt                      D                       S t          fdt                      D                       S )Nr   c              3   >   K   | ]}t          |          u d V  dS r   N)r!   .0xkinds     r*   	<genexpr>z)TestCase.count_objects.<locals>.<genexpr>j   s;        77d?? "??? r+   c              3   <   K   | ]}t          |          d V  dS rB   )
isinstancerC   s     r*   rG   z)TestCase.count_objects.<locals>.<genexpr>p   sG       
 
!T""

 
 
 
 
 
r+   )ranger   sumr   )r:   rF   
exact_kind_s    `  r*   count_objectszTestCase.count_objectsd   s     q 	 	AIIII 	    $       
 
 
 
 ]]
 
 
 
 
 	
r+   r   Fc                 8    |                      t          d          S )zJ
        Find all the greenlets and subclasses tracked by the GC.
        F)rN   RawGreenlet)r:   s    r*   count_greenletszTestCase.count_greenlets{   s     !!+u555r+   c                 "   t                                                       t                       t                      | _        t                      | _        |                     | j        | j                   |                                 | _	        d S N)
supersetUpr	   r7   r3   r   r4   r?   rQ   greenlets_before_testr:   	__class__s    r*   rU   zTestCase.setUp   sq     	#6#8#8 *B*D*D'&&t'?A`aaa%)%9%9%;%;"""r+   c                     t          | dd          rd S |                     | j        | j                   t	                                                       d S )NskipTearDownF)getattrr?   r3   r4   rT   tearDownrW   s    r*   r\   zTestCase.tearDown   sT    4// 	F&&t'?A`aaar+   c                 @    dd l }t          s|j         |j         fnd}|S )Nr   )r   l   	   l       )signalWINSIGABRTSIGSEGV)r:   r^   expected_exits      r*   ,get_expected_returncodes_for_aborted_processz5TestCase.get_expected_returncodes_for_aborted_process   sB    J 
^O
 ^O
 

 	 r+   c                     	 t          j                                                    j        S # t          $ r}t          j        d          |d}~ww xY w)a  
        Return the current process's USS in bytes.

        uss is available on Linux, macOS, Windows. Also known as
        "Unique Set Size", this is the memory which is unique to a
        process and which would be freed if the process was terminated
        right now.

        If this is not supported by ``psutil``, this raises the
        :exc:`unittest.SkipTest` exception.
        zuss not supportedN)psutilProcessmemory_full_infoussAttributeErrorunittestSkipTest)r:   es     r*   get_process_usszTestCase.get_process_uss   s\    	@>##4466:: 	@ 	@ 	@#$788a?	@s   ), 
AAAc                    dd l }t          j                            t          j                            t
                    |          }	 |                    t          j        |gd|j	                  S # |j
        $ rY}|rQt          d           t          d|           t          d           t          |j                   t          d            d }~ww xY w)Nr   zutf-8)encodingstderrz-----zFailed to run scriptz~~~~~z------)
subprocessospathjoindirname__file__check_outputsys
executableSTDOUTCalledProcessErrorr9   output)r:   script_nameshow_outputrq   scriptexs         r*   
run_scriptzTestCase.run_script   s    GOOH%%
 

	**CNF+C4;2<2C + E E E , 	 	 	  g,f555gbi   h	s   (A1 1
C;ACCc                    dd l }|                     |j                  5 }|                     |d          }|}d d d            n# 1 swxY w Y   ||                                 }|                     |j        j        |           |j        S )Nr   F)r~   )rq   assertRaisesr{   r   rc   assertIn	exception
returncode)r:   r}   	exitcodesrq   excr|   __traceback_info__s          r*   assertScriptRaiseszTestCase.assertScriptRaises   s    z<== 	(__[e_DDF!'	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( IIKKIcm.	:::}s   AA	A	)NN)TrS   )r,   r-   r.   r5   r6   r?   r   rN   rV   r3   r4   r8   rQ   rU   r\   rc   rm   r   r   __classcell__)rX   s   @r*   r1   r1   :   s
       
 &+" ! :>9=       D "&$ 
 
 
 
$ !" 6 6 6< < < < <    + + +Z@ @ @"   *       r+   r1   NewBase)%__doc__rr   rx   rj   gcr   r   	threadingr   r7   r   r   re   r   rP   r	   greenlet._greenletr
   r    r   version_infoPY312PY313platformr   r_   environgetRUNNING_ON_GITHUB_ACTIONSRUNNING_ON_TRAVISRUNNING_ON_APPVEYORRUNNING_ON_CIRUNNING_ON_MANYLINUXr!   r   r1   r/   r+   r*   <module>r      s    
			 



              9 9 9 9 9 9              , , , , , ,       8 8 8 8 8 8 7 7 7 7 7 7      !'!'	le$$JNN+;<< JNN8,,I0I jnnZ00 !8%8z~~&:;; > > > > > > > >,v v v v v  		
  v v v v vr+   