U Wg$@s8dZddlZddlZddlZddlmZddlmZddlmZ ddl m Z ddl m Z ddl Z ddl m Zdd l mZdd lmZdd lmZd d lmZejdddkZejdddkZejdZejdZejdpeZejdZepeZ ejdZ!Gddde"Z#Gddde#dej$fiZ$dS)z Tests for greenlet. N)collect) get_objects) active_count)sleep)time)greenlet) getcurrent)get_pending_cleanup_count)get_total_main_greenlets) leakcheck) )r winZGITHUB_ACTIONSZTRAVISZAPPVEYORZGREENLET_MANYLINUXc@seZdZddZdS)TestCaseMetaClasscCs\d}t|D]:\}}|drt|r|||rBt|}|||<qt||||S)NTtest) listitems startswithcallablepopr Z wrap_refcounttype__new__)cls classnamebasesZ classDictZcheck_totalrefcountkeyvaluer G/opt/hc_python/lib64/python3.8/site-packages/greenlet/tests/__init__.pyr's   zTestCaseMetaClass.__new__N)__name__ __module__ __qualname__rr r r r!r$srcseZdZdZdZdddZedfddZd Zd Z d Z d Z d d Z fd dZ fddZddZddZdddZdddZZS)TestCasegMbP?r NcCs|p|j}|p|j}|j}t|t|j}tsNt|ksN|jst |krt|t|kr.t dt d|dtt d|dt qq.t dS)NzTime limit exceeded.zThreads: Waiting for onlyz-->zMGlets : Waiting for only) threads_before_testmain_greenlets_before_testcleanup_attempt_sleep_durationrrcleanup_max_sleep_secondsr active_thread_countexpect_greenlet_leakr printr)selfZinitial_active_threadsZinitial_main_greenletsZ sleep_timeZ quit_afterr r r!wait_for_pending_cleanupsBs4     z"TestCase.wait_for_pending_cleanupsTcsHtdD] }tq|r0tfddtDStfddtDS)Nrc3s|]}t|krdVqdSr N)r.0xkindr r! js z)TestCase.count_objects..c3s|]}t|rdVqdSr/) isinstancer0r3r r!r5ps )rangersumr)r-r4Z exact_kind_r r3r! count_objectsds   zTestCase.count_objectsrFcCs |tdS)zJ Find all the greenlets and subclasses tracked by the GC. F)r: RawGreenletr-r r r!count_greenlets{szTestCase.count_greenletscs>ttt|_t|_||j|j||_ dS)N) supersetUprr*r&r r'r.r=greenlets_before_testr< __class__r r!r?s  zTestCase.setUpcs.t|ddrdS||j|jtdS)NZ skipTearDownF)getattrr.r&r'r>tearDownr<rAr r!rDs zTestCase.tearDowncCs$ddl}ts|j |j fnd}|S)Nr)rl l)signalWINSIGABRTSIGSEGV)r-rEZ expected_exitr r r!,get_expected_returncodes_for_aborted_processs% z5TestCase.get_expected_returncodes_for_aborted_processc CsDztjWStk r>}ztd|W5d}~XYnXdS)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. zuss not supportedN)psutilProcessZmemory_full_infoZussAttributeErrorunittestZSkipTest)r-er r r!get_process_usss zTestCase.get_process_ussc Csddl}tjtjt|}z|jtj|gd|j dWS|j k r}z6|r|t dt d|t dt |j t dW5d}~XYnXdS)Nrzutf-8)encodingstderrz-----zFailed to run scriptz~~~~~z------) subprocessospathjoindirname__file__ check_outputsys executableSTDOUTCalledProcessErrorr,output)r- script_name show_outputrRscriptexr r r! run_scripts$    zTestCase.run_scriptc CsXddl}||j}|j|dd}|}W5QRX|dkrB|}||jj||jS)NrF)r_)rRZ assertRaisesr\rbrIZassertIn exception returncode)r-r^Z exitcodesrRexcr]Z__traceback_info__r r r!assertScriptRaisesszTestCase.assertScriptRaises)NN)T)N)r"r#r$r(r)r.rr:r@r&r'r+r=r?rDrIrOrbrf __classcell__r r rAr!r%:s" " - r%ZNewBase)%__doc__rSrYrMgcrr threadingrr*rrrJrr;rZgreenlet._greenletr r r version_infoZPY312ZPY313platformrrFenvirongetZRUNNING_ON_GITHUB_ACTIONSZRUNNING_ON_TRAVISZRUNNING_ON_APPVEYORZ RUNNING_ON_CIZRUNNING_ON_MANYLINUXrrr%r r r r!s8