3 SLj @ s d Z ddlZddlZyddlZW n ek r< ddlZY nX yddlZW n ek rf ddlZY nX G dd dejZ G dd dej ZeedreZ 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 testerrorr 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 )copyregdispatch_tablecopy_saved_pickle_registrysuperr runr rangeNB_RUNS _getRefcountsappendprintZassertEqual Exceptionr sysexc_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 clearupdater gcZcollectr# gettotalrefcount)r r r r r g s z*ReferenceLeakCheckerTestCase._getRefcounts)N)r r r r r r r __classcell__r r )r&