o
    =j�  ã                   @   sv   d Z ddlZddlZddlZddlZG dd„ dejƒZG dd„ deƒZe	edƒr1dd	„ Z
ejZdS d
d	„ Z
dd„ ZdS )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                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚLocalTestResultzHA TestResult which forwards events to a parent object, except for Skips.c                 C   s   t j | ¡ || _d S ©N)ÚunittestÚ
TestResultÚ__init__Úparent_result)Úselfr   © r	   úsC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\google/protobuf/internal/testing_refleaks.pyr      s   
zLocalTestResult.__init__c                 C   ó   | j  ||¡ d S r   )r   ÚaddError©r   ÚtestÚerrorr	   r	   r
   r      ó   zLocalTestResult.addErrorc                 C   r   r   )r   Ú
addFailurer   r	   r	   r
   r   "   r   zLocalTestResult.addFailurec                 C   ó   d S r   r	   )r   r   Úreasonr	   r	   r
   ÚaddSkip%   ó   zLocalTestResult.addSkipc                 C   r   r   r	   )r   r   Údurationr	   r	   r
   ÚaddDuration(   r   zLocalTestResult.addDurationN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r	   r	   r	   r
   r      s    r   c                       s.   e Zd ZdZdZd‡ fdd„	Zdd„ Z‡  ZS )	ÚReferenceLeakCheckerMixinz:A mixin class for TestCase, which checks reference counts.é   Nc           
         s,  t | | jƒ}t |ddƒ}t | ddƒ}|s|rd S tj ¡ | _tt| ƒj|d� tt| ƒj|d� t	|ƒ}d}g }|  
¡ }t|ƒ| jk rq|  
¡ }tt| ƒj|d� |  
¡ }	|	|k ra|dk ra|d7 }q<d}| |	| ¡ t|ƒ| jk sCt|| ƒ z|  |dg| j ¡ W d S  ty•   | | t ¡ ¡ Y d S w )NZ__unittest_expecting_failure__F)Úresultr   é   é   )ÚgetattrZ_testMethodNameÚcopyregÚdispatch_tableÚcopyÚ_saved_pickle_registryÚsuperr   Úrunr   Ú_getRefcountsÚlenÚNB_RUNSÚappendÚprintÚassertEqualÚ	Exceptionr   ÚsysÚexc_info)
r   r   Z
testMethodZexpecting_failure_methodZexpecting_failure_classZlocal_resultZ
num_flakesZrefcount_deltasZoldrefcountZnewrefcount©Ú	__class__r	   r
   r'   1   s8   ò
ÿzReferenceLeakCheckerMixin.runc                 C   sT   t tdƒr
t ¡  nt ¡  tj ¡  tj | j¡ t	 
¡  t	 
¡  t	 
¡  t ¡ S )NÚ_clear_internal_caches)Úhasattrr/   r3   Ú_clear_type_cacher"   r#   ÚclearÚupdater%   ÚgcZcollectÚgettotalrefcount)r   r	   r	   r
   r(   ^   s   


z'ReferenceLeakCheckerMixin._getRefcountsr   )r   r   r   r   r*   r'   r(   Ú__classcell__r	   r	   r1   r
   r   ,   s
    -r   r9   c                 C   s(   t f| j }t| ƒ| j|t| jƒƒ}|S r   )r   Ú	__bases__Útyper   ÚdictÚ__dict__)Ú
test_classÚ	new_basesÚ	new_classr	   r	   r
   ÚTestCaseo   s
   ÿrB   c                 C   ó   | S r   r	   )r?   r	   r	   r
   rB   y   r   c                 C   s   ~ dd„ }|S )Nc                 S   rC   r   r	   )Úfuncr	   r	   r
   ÚSame~   r   z&SkipReferenceLeakChecker.<locals>.Samer	   )r   rE   r	   r	   r
   ÚSkipReferenceLeakChecker|   s   rF   )r   r"   r8   r/   r   r   r   Úobjectr   r4   rB   ÚskiprF   r	   r	   r	   r
   Ú<module>   s   

A
