o
    üÞh�  ã                   @   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	   úi/var/www/html/premium_crap/venv/lib/python3.10/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 )NÚ__unittest_expecting_failure__F)Úresultr   é   é   )ÚgetattrÚ_testMethodNameÚcopyregÚdispatch_tableÚcopyÚ_saved_pickle_registryÚsuperr   Úrunr   Ú_getRefcountsÚlenÚNB_RUNSÚappendÚprintÚassertEqualÚ	Exceptionr   ÚsysÚexc_info)
r   r   Ú
testMethodÚexpecting_failure_methodÚexpecting_failure_classÚlocal_resultÚ
num_flakesÚrefcount_deltasÚoldrefcountÚ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)Úhasattrr1   r=   Ú_clear_type_cacher$   r%   ÚclearÚupdater'   ÚgcÚcollectÚgettotalrefcount)r   r	   r	   r
   r*   ^   s   


z'ReferenceLeakCheckerMixin._getRefcountsr   )r   r   r   r   r,   r)   r*   Ú__classcell__r	   r	   r;   r
   r   ,   s
    -r   rD   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
   ÿrM   c                 C   ó   | S r   r	   )rJ   r	   r	   r
   rM   y   r   c                 C   s   ~ dd„ }|S )Nc                 S   rN   r   r	   )Úfuncr	   r	   r
   ÚSame~   r   z&SkipReferenceLeakChecker.<locals>.Samer	   )r   rP   r	   r	   r
   ÚSkipReferenceLeakChecker|   s   rQ   )r   r$   rB   r1   r   r   r   Úobjectr   r>   rM   ÚskiprQ   r	   r	   r	   r
   Ú<module>   s   

A
