3 SÉLj›ã@s´dZddlZddlZy ddlZWnek r<ddlZYnXy ddlZWnek rfddlZYnXGdd„dejƒZ Gdd„dej ƒZ e edƒr¢e Z ejZnej Z dd „ZdS) a[A subclass of unittest.TestCase which checks for reference leaks. To use: - Use testing_refleak.BaseTestCase instead of unittest.TestCase - Configure and compile Python with --with-pydebug If sys.gettotalrefcount() is not available (because Python was built without the Py_DEBUG option), then this module is a no-op and tests will run normally. éNc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚLocalTestResultzHA TestResult which forwards events to a parent object, except for Skips.cCstjj|ƒ||_dS)N)ÚunittestÚ TestResultÚ__init__Ú parent_result)Úselfr©rú&/usr/lib/python3.6/testing_refleaks.pyr:s zLocalTestResult.__init__cCs|jj||ƒdS)N)rÚaddError)rÚtestÚerrorrrr r >szLocalTestResult.addErrorcCs|jj||ƒdS)N)rÚ addFailure)rr r rrr r AszLocalTestResult.addFailurecCsdS)Nr)rr Úreasonrrr ÚaddSkipDszLocalTestResult.addSkipN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr r rrrrr r7s rcs.eZdZdZdZd‡fdd„ Zdd„Z‡ZS) ÚReferenceLeakCheckerTestCasezHA TestCase which runs tests multiple times, collecting reference counts.éNc sÐtjjƒ|_tt|ƒj|d�tt|ƒj|d�d}t|ƒ}g}xBt|j ƒD]4}|j ƒ}tt|ƒj|d�|j ƒ}|j ||ƒqLWt ||ƒy|j |dg|j ƒWn$tk rÊ|j|tjƒƒYnXdS)N)Úresultr)ÚcopyregÚdispatch_tableÚcopyÚ_saved_pickle_registryÚsuperrÚrunrÚrangeÚNB_RUNSÚ _getRefcountsÚappendÚprintZ assertEqualÚ Exceptionr ÚsysÚexc_info)rrZ oldrefcountZ local_resultZrefcount_deltasÚ_Z newrefcount)Ú __class__rr rMs   z ReferenceLeakCheckerTestCase.runcCs8tjjƒtjj|jƒtjƒtjƒtjƒtjƒS)N) rrÚclearÚupdaterÚgcZcollectr#Úgettotalrefcount)rrrr rgs  z*ReferenceLeakCheckerTestCase._getRefcounts)N)rrrrrrrÚ __classcell__rr)r&r rHsrr*cCs~dd„}|S)NcSs|S)Nr)Úfuncrrr ÚSame|sz&SkipReferenceLeakChecker..Samer)rr-rrr ÚSkipReferenceLeakCheckerzsr.)rr)r#Zcopy_regrÚ ImportErrorZ unittest2rrrZTestCaserÚhasattrZ BaseTestCaseÚskipr.rrrr Ú's"  *