U Wg.@s ddlmZddlZddlZddlZddlmZddlZddlZej dZ ej dpZe Z ej dZ e pne Zej dZepej dZej d Zej d Zd d Zd dZGdddeZeedrGdddeZee_eZnddZGdddeZGdddeZddZdS))print_functionN)wrapsZGITHUB_ACTIONSZTRAVISZAPPVEYORZGREENLET_MANYLINUXZGREENLET_SKIP_LEAKCHECKSZ GREENLET_SKIP_FAILING_LEAKCHECKSZ GREENLET_ONLY_FAILING_LEAKCHECKScCs d|_|S)a Ignore the given object during leakchecks. Can be applied to a method, in which case the method will run, but will not be subject to leak checks. If applied to a class, the entire class will be skipped during leakchecks. This is intended to be used for classes that are very slow and cause problems such as test timeouts; typically it will be used for classes that are subclasses of a base class and specify variants of behaviour (such as pool sizes). T)ignore_leakcheckfuncrH/opt/hc_python/lib64/python3.8/site-packages/greenlet/tests/leakcheck.pyignores_leakcheckLs r cCsd|_trtd|}|S)z2 Mark that the function is known to leak. TzSkipping known failures)fails_leakcheckSKIP_FAILING_LEAKCHECKSunittestskiprrrrr [sr c@s eZdZdS)LeakCheckErrorN)__name__ __module__ __qualname__rrrrrdsr getobjectsc@seZdZddZddZdS)_MockGCcCs tdS)Nr)sysrselfrrr get_objectslsz_MockGC.get_objectscCs tt|SN)getattrgc)rnamerrr __getattr__nsz_MockGC.__getattr__N)rrrrrrrrrrksrcCs|S)a Decorator for a function that is known to fail when running strict (``sys.getobjects()``) leakchecks. This type of leakcheck finds all objects, even those, such as strings, which are not tracked by the garbage collector. rrrrrfails_strict_leakcheckssrc@seZdZddZddZdS)!ignores_types_in_strict_leakcheckcCs ||_dSr)types)rrrrr__init__~sz*ignores_types_in_strict_leakcheck.__init__cCs |j|_|Sr)rleakcheck_ignore_types)rrrrr__call__sz*ignores_types_in_strict_leakcheck.__call__N)rrrr r"rrrrr}src@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)_RefCountCheckerrcCs(||_||_g|_i|_d|_d|_dS)NrF)testcasefunctiondeltas peak_stats ignored_types needs_setUp)rr$r%rrrr s z_RefCountChecker.__init__cCs||kr dSt|}|t|jkrhz|j|}Wn$tk rV|j|dk}YnX|tk rh|rhdS|jD]}||krrdSqr||jks||j krdSdS)NFrT) type_include_object_p__eq__AttributeErrorZ__cmp__NotImplemented__dict__valuesr( IGNORED_TYPES)robjkindZexact_method_equalsxrrrr+s  z"_RefCountChecker._include_object_pcCstjd|j|jdS)N)limitr'filter)objgraphgrowthr'r+rrrr_growths z_RefCountChecker._growthcCsR|sdSg}tdd|D}|D] \}}}|d||||fq"d|}|S)Nzcss|]\}}}t|VqdSr)len).0r_rrr sz0_RefCountChecker._report_diff..z %-*s%9d %+9d )maxappendjoin)rr8lineswidthrcountdeltadiffrrr _report_diffs z_RefCountChecker._report_diffcCsvt}t|jr(|jd|j_z|j |jf||W5|j|jd|j_d|_|rpt XdS)NFT) r isenableddisabler)r$ZsetUpZ skipTearDownZtearDownZ doCleanupsenabler%)rargskwargsZ gc_enabledrrr _run_tests   z_RefCountChecker._run_testcCs8dtjkrtjddtjkr0tjd|S)Nurlparsez urllib.parse)rmodules clear_cacher9rrrr _growth_afters   z_RefCountChecker._growth_aftercCsN|j}|sdStjr$tdtjf|ddddgkrHt|dkrHdS|dddddgkrbdSt|dkrt|d ddkrdSt|d kr|d dkr|d |dkr|d|dkr||}td ||ft|dddkst|d ddks|d ddd kr"d}nd}t||krJtd |||fdS)NTz"Generated uncollectable garbage %rr)FrTzrefcount increased by %r %srS )r&rgarbagerr:sumrGrD)rr8r&rFr5rrr _check_deltass0  8 Dz_RefCountChecker._check_deltascCstdD] }tqt|jdd}|r0d|j_t|jdd|_|}z>| |r| ||| }|j tdd|DqJWntk r|sYnX|rtd |jfdS) NrTr FTr!rcss|]}|dVqdS)rSNr)r;statrrrr=+sz,_RefCountChecker.__call__..z#Expected %s to leak but it did not.)rangerZcollectrr%r$Zexpect_greenlet_leakr(r9r]rMrQr&r@r\r)rrKrLr<Zexpect_failurer8rrrr"s"     z_RefCountChecker.__call__N) rrrr1r r+r9rGrMrQr]r"rrrrr#s %  1r#cs,tddstrStfdd}|S)NrFcs@t|ddrtdtr0tdds0tdt|||S)NrFz$This class ignored during leakchecksr z(Only running tests that fail leakchecks.)rr ZSkipTestONLY_FAILING_LEAKCHECKSr#)rrKrLmethodrrwrapper7s    zwrap_refcount..wrapper)rSKIP_LEAKCHECKSr)rbrcrrar wrap_refcount3s re) __future__rosrr functoolsrr r7environgetZRUNNING_ON_GITHUB_ACTIONSZRUNNING_ON_TRAVISZRUNNING_ON_APPVEYORZ RUNNING_ON_CIZRUNNING_ON_MANYLINUXrdr r`r r AssertionErrorrhasattrobjectrrrr#rerrrrs4  !        0