o
    ‹¨Êh›  ã                   @   s²   d Z ddlZddlZzddlZW n ey   ddlZY nw zddlZW n ey1   ddlZY nw G dd„ dejƒZ	G dd„ dej
ƒZeedƒrPeZejZdS ej
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                   @   s0   e Zd Z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	   ú[/var/www/html/env/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   A   r   zLocalTestResult.addFailurec                 C   s   d S r   r	   )r   r   Úreasonr	   r	   r
   ÚaddSkipD   ó   zLocalTestResult.addSkipN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r	   r	   r
   r   7   s    r   c                       s.   e Zd ZdZdZd‡ fdd„	Zdd„ Z‡  ZS )	ÚReferenceLeakCheckerTestCasezHA TestCase which runs tests multiple times, collecting reference counts.é   Nc                    sÊ   t j ¡ | _tt| ƒj|d� tt| ƒj|d� d}t|ƒ}g }t| j	ƒD ]}|  
¡ }tt| ƒj|d� |  
¡ }| || ¡ q%t|| ƒ z|  |dg| j	 ¡ W d S  tyd   | | t ¡ ¡ Y d S w )N)Úresultr   )ÚcopyregÚdispatch_tableÚcopyÚ_saved_pickle_registryÚsuperr   Úrunr   ÚrangeÚNB_RUNSÚ_getRefcountsÚappendÚprintÚassertEqualÚ	Exceptionr   ÚsysÚexc_info)r   r   ÚoldrefcountÚlocal_resultÚrefcount_deltasÚ_Únewrefcount©Ú	__class__r	   r
   r!   M   s"   
ÿz ReferenceLeakCheckerTestCase.runc                 C   s8   t j ¡  t j | j¡ t ¡  t ¡  t ¡  t ¡ S r   )	r   r   ÚclearÚupdater   ÚgcÚcollectr)   Úgettotalrefcount)r   r	   r	   r
   r$   g   s   
z*ReferenceLeakCheckerTestCase._getRefcountsr   )r   r   r   r   r#   r!   r$   Ú__classcell__r	   r	   r0   r
   r   H   s
    r   r6   c                 C   s   ~ dd„ }|S )Nc                 S   s   | S r   r	   )Úfuncr	   r	   r
   ÚSame|   r   z&SkipReferenceLeakChecker.<locals>.Samer	   )r   r9   r	   r	   r
   ÚSkipReferenceLeakCheckerz   s   r:   )r   r4   r)   Úcopy_regr   ÚImportErrorÚ	unittest2r   r   r   ÚTestCaser   ÚhasattrÚBaseTestCaseÚskipr:   r	   r	   r	   r
   Ú<module>   s(   
ÿÿ
*
