
                             S r SSKrSSKrSSKrSSKr " S S\R
                  5      r " S S\5      r\	" \S5      (       a  S r
\R                  rgS	 r
S
 rg)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                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
LocalTestResult   zHA TestResult which forwards events to a parent object, except for Skips.c                 N    [         R                  R                  U 5        Xl        g N)unittest
TestResult__init__parent_result)selfr   s     Elib/third_party/cloudsdk/google/protobuf/internal/testing_refleaks.pyr
   LocalTestResult.__init__   s      &&    c                 :    U R                   R                  X5        g r   )r   addErrorr   testerrors      r   r   LocalTestResult.addError   s    ,r   c                 :    U R                   R                  X5        g r   )r   
addFailurer   s      r   r   LocalTestResult.addFailure"   s    !!$.r   c                     g r    )r   r   reasons      r   addSkipLocalTestResult.addSkip%       r   c                     g r   r   )r   r   durations      r   addDurationLocalTestResult.addDuration(   r   r   )r   N)__name__
__module____qualname____firstlineno____doc__r
   r   r   r   r!   __static_attributes__r   r   r   r   r      s    P'-/		r   r   c                   :   ^  \ rS rSrSrSrSU 4S jjrS rSrU =r	$ )ReferenceLeakCheckerMixin,   z:A mixin class for TestCase, which checks reference counts.   c                 $  > [        X R                  5      n[        USS5      n[        U SS5      nU(       d  U(       a  g [        R                  R	                  5       U l        [        [        U ]#  US9  [        [        U ]#  US9  [        U5      nSn/ nU R                  5       n[        U5      U R                  :  as  U R                  5       n[        [        U ]#  US9  U R                  5       n	X:  a  US:  a  US-  nM\  SnUR                  X-
  5        [        U5      U R                  :  a  Ms  [        Xp5         U R                  US/U R                  -  5        g ! [          a(    UR#                  U [$        R&                  " 5       5         g f = f)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__s             r   r9   ReferenceLeakCheckerMixin.run1   st   334J&z3SUZ[%d,LeT":
 #*"8"8"="="?D 

#T.f.=	
#T.f.="6*LJO $$&K
o

-&&(k%t00E&&(k 
	"zA~
 	a
j[67 o

- 
/ ,
dll(:; ,oodCLLN+,s   < E /FFc                    [        [        S5      (       a  [        R                  " 5         O[        R                  " 5         [        R
                  R                  5         [        R
                  R                  U R                  5        [        R                  " 5         [        R                  " 5         [        R                  " 5         [        R                  " 5       $ )N_clear_internal_caches)hasattrrA   rN   _clear_type_cacher4   r5   clearupdater7   gccollectgettotalrefcount)r   s    r   r:   'ReferenceLeakCheckerMixin._getRefcounts^   s    s,--	  "	  "!!$"="=> JJLJJLJJL!!r   )r7   r   )
r#   r$   r%   r&   r'   r<   r9   r:   r(   __classcell__)rK   s   @r   r*   r*   ,   s    B'+,Z" "r   r*   rU   c                     [         4U R                  -   n[        U 5      " U R                  U[	        U R
                  5      5      nU$ r   )r*   	__bases__typer#   dict__dict__)
test_class	new_bases	new_classs      r   TestCaser`   o   sC    *,z/C/CCIZ YZ-@-@(ACIr   c                     U $ r   r   )r]   s    r   r`   r`   y   s    r   c                     A S nU$ )Nc                     U $ r   r   )funcs    r   Same&SkipReferenceLeakChecker.<locals>.Same~   s    kr   r   )r   re   s     r   SkipReferenceLeakCheckerrg   |   s    Kr   )r'   r4   rS   rA   r   r	   r   objectr*   rO   r`   skiprg   r   r   r   <module>rj      sb     	 
 	h)) 	(>" >"B 3"##
 &]]
r   