3 SÉLj› ã @ s´ d Z ddlZddlZyddlZW n ek r< ddlZY nX yddlZW n ek rf ddlZY nX G dd„ dejƒZ G dd„ dej ƒZeedƒr¢eZ 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 @ s0 e Zd ZdZdd„ Zdd„ Zdd„ Zdd „ Zd S )ÚLocalTestResultzHA TestResult which forwards events to a parent object, except for Skips.c C s t jj| ƒ || _d S )N)ÚunittestÚ TestResultÚ__init__Ú parent_result)Úselfr © r ú&/usr/lib/python3.6/testing_refleaks.pyr : s zLocalTestResult.__init__c C s | j j||ƒ d S )N)r ÚaddError)r ÚtestÚerrorr r r r > s zLocalTestResult.addErrorc C s | j j||ƒ d S )N)r Ú addFailure)r r r r r r r A s zLocalTestResult.addFailurec C s d S )Nr )r r Úreasonr r r ÚaddSkipD s zLocalTestResult.addSkipN)Ú__name__Ú __module__Ú__qualname__Ú__doc__r r r r r r r r r 7 s r c s. e Zd ZdZdZd‡ fdd„ Zdd„ Z‡ ZS ) ÚReferenceLeakCheckerTestCasezHA TestCase which runs tests multiple times, collecting reference counts.é Nc sÐ t jjƒ | _tt| ƒj|d� tt| ƒj|d� d}t|ƒ}g }xBt| j ƒD ]4}| j ƒ }tt| ƒj|d� | j ƒ }|j|| ƒ qLW t|| ƒ y| j |dg| j ƒ W n$ tk rÊ |j| tjƒ ƒ Y nX d S )N)Úresultr )ÚcopyregÚdispatch_tableÚcopyÚ_saved_pickle_registryÚsuperr Úrunr ÚrangeÚNB_RUNSÚ _getRefcountsÚappendÚprintZassertEqualÚ Exceptionr ÚsysÚexc_info)r r ZoldrefcountZlocal_resultZrefcount_deltasÚ_Znewrefcount)Ú __class__r r r M s z ReferenceLeakCheckerTestCase.runc C s8 t jjƒ t jj| jƒ tjƒ tjƒ tjƒ tjƒ S )N) r r ÚclearÚupdater ÚgcZcollectr# Úgettotalrefcount)r r r r r g s z*ReferenceLeakCheckerTestCase._getRefcounts)N)r r r r r r r Ú __classcell__r r )r&