
    %
i|*                     D   d dl Z d dlZd dlZd dlZd dlZd dlZ G d dej                  Z G d dej                  Zej	        ej
        gZdad ZddZ G d	 d
e          Z G d dej                  Z G d dej                  Z G d dej                  Zd ZdS )    Nc                   4    e Zd ZdZd Zd ZddZd ZddZdS )	LeakTestCasea  An 'adaptor' which takes another test.  In debug builds we execute the
    test once to remove one-off side-effects, then capture the total
    reference count, then execute the test a few times.  If the total
    refcount at the end is greater than we first captured, we have a leak!

    In release builds the test is executed just once, as normal.

    Generally used automatically by the test runner - you can safely
    ignore this.
    c                     t           j                            |            || _        d| _        d| _        t          t          d          r| xj        | j        z  c_        d S d S )N      gettotalrefcount)unittestTestCase__init__	real_testnum_test_casesnum_leak_itershasattrsys)selfr   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\win32/lib/pywin32_testutil.pyr   zLeakTestCase.__init__   sj    ""4((("3*++ 	74#66	7 	7    c                     | j         S N)r   r   s    r   countTestCaseszLeakTestCase.countTestCases$   s    ""r   Nc                    ddl m}m} t          j                      |            } |            }|                     |           |j        s|                                sd S |                     |           t          j                      |            |z
  } |            |z
  }|s|r;d||fz  }t          |          }	|
                    | j        |	j        |	d f           d S d S )Nr   )_GetGatewayCount_GetInterfaceCountz2%d interface objects and %d gateway objects leaked)	pythoncomr   r   gccollectr   
shouldStopwasSuccessful_do_leak_testsAssertionError
addFailure	__class__)
r   resultr   r   ninglost_ilost_gmsgexcs
             r   __call__zLeakTestCase.__call__'   s'    	CBBBBBBB

!!v 	F$8$8$:$: 	FF###

##%%*!!##b( 	JV 	JFJ C !%%Cdns}c4.HIIIII	J 	Jr   c                      t          d          )Nznot used)NotImplementedErrorr   s    r   runTestzLeakTestCase.runTest?   s    !*---r   c                 2   	 t           j        }n# t          $ r Y d S w xY wt          j                      |            }t          | j                  D ] }|                     |           |j        r n!~t          j                      |            |z
  | j        z  }|dk     r0d| j        | fz  }|	                    | j        t          |d f           |dk    r@d| j        |fz  }t          |          }|	                    | j        |j        |d f           d S d S )Nr   z-LeakTest: %s appeared to gain %d references!!zLeakTest: %s lost %d references)r   r   AttributeErrorr   r   ranger   r   r   r"   r!   r#   )r   r$   gtrctrcilostr)   r*   s           r   r    zLeakTestCase._do_leak_testsB   sL   	'DD 	 	 	FF	 	
dfft*++ 	 	ANN6"""   	
!44!88AE C dn~sD.IJJJ!883t~t6LLC %%Cdns}c4.HIIIII 8s    
r   )	__name__
__module____qualname____doc__r   r   r+   r.   r     r   r   r   r      s}        	 	7 7 7# # #J J J J0. . .J J J J J Jr   r   c                   .    e Zd Zd Zd Zd Zd ZddZdS )
TestLoaderc                     g }|                      |          D ]7} ||          }|                     |          }|                    |           8|                     |          S )z<Return a suite of all tests cases contained in testCaseClass)getTestCaseNames_getTestWrapperappend
suiteClass)r   testCaseClass
leak_testsnamer   	leak_tests         r   loadTestsFromTestCasez TestLoader.loadTestsFromTestCase`   so    
))-88 	) 	)D%d++I,,Y77Ii((((z***r   c                      t          |t          j                  r fd|j        D             |_        |S                      |          S )Nc                 :    g | ]}                     |          S r:   )fixupTestsForLeakTests).0tr   s     r   
<listcomp>z5TestLoader.fixupTestsForLeakTests.<locals>.<listcomp>k   s'    OOOa466q99OOOr   )
isinstancer	   	TestSuite_testsr?   )r   tests   ` r   rI   z!TestLoader.fixupTestsForLeakTestsi   sP    dH.// 	.OOOO4;OOODKK ''---r   c                 h    t          |dd          }|rt          d           |S t          |          S )Nno_leak_testsFz%Test says it doesn't want leak tests!)getattrprintr   )r   rP   rR   s      r   r?   zTestLoader._getTestWrapperq   s=    ou== 	9:::KD!!!r   c                     t          |d          r|                                }n t          j                            | |          }|                     |          S )Nsuite)r   rV   r	   r<   loadTestsFromModulerI   )r   modtestss      r   rW   zTestLoader.loadTestsFromModuley   sP    3   	GIIKKEE';;D#FFE**5111r   Nc                     t           j                            | ||          }t          |t           j                  rn@t          |t           j                  r|                     |          }nt          d|           |S )NzXXX - what is)r	   r<   loadTestsFromNamerM   rN   r
   r?   rT   )r   rD   modulerP   s       r   r[   zTestLoader.loadTestsFromName   ss    "44T4HHdH.// 	)h/00 	)''--DD/4(((r   r   )r6   r7   r8   rF   rI   r?   rW   r[   r:   r   r   r<   r<   _   sd        + + +. . ." " "2 2 2	 	 	 	 	 	r   r<   c                      t           Edd l} ddlm} 	  |            a n/# | j        $ r"}|j        t          j        k    r da Y d }~nd }~ww xY wt           S )Nr   )IsUserAnAdminT)	_is_adminr   win32com.shell.shellr^   	com_errorhresultwinerror	E_NOTIMPL)r   r^   r*   s      r   check_is_adminre      s    666666	%II" 	 	 	{h000IIIIII		
 s   
 
A
AA
.c                    t           j                            t          j        d                   |dg}|D ]E}t           j                            ||           }t           j                            |          r|c S Ft           j                            t           j                            t          j        d                             }t          j
                    d d          }t          j        r|                    t          j                   |D ]Y}t           j                            |          }t           j                            ||g          |k    rt          d| d          Zt          d| d          )Nr   rf   zCan't find test fixture '')ospathdirnamer   argvjoinisfilenormcaseabspathsitegetsitepackages	USER_SITEr@   commonprefixTestSkippedRuntimeError)basename	extra_dir
candidates	candidatefname	this_filedirs_to_checkds           r   find_test_fixturer      sV    	$$J
   A A	Y117>>%   	LLL	
 G$$RW__SXa[%A%ABB	,..qqq1> 	1  000 	H 	HA  ##Aw##YN33q88!"Fe"F"F"FGGG 9 ?u???@@@r   c                       e Zd ZdS )ru   N)r6   r7   r8   r:   r   r   ru   ru      s        Dr   ru   c                   2     e Zd Z fdZ fdZ fdZ xZS )
TestResultc                 H     t                      j        |i | i | _        d S r   )superr   skips)r   argskwr#   s      r   r   zTestResult.__init__   s*    $%"%%%


r   c                    ddl }|d         }t          ||j                  r,|j        t          v rt                      st          |          }nxt          ||j                  r:|j        t          j	        t          j
        t          j        fv rt          |          }n)t          |t                    rt          t                    }t          |t                    r|j        d         }	 t          |j                  }n# t          t           f$ r Y nw xY w| j                            |d           | j        |xx         dz  cc<   | j        r| j                            d| d           n:| j        r3| j                            d           | j                                         dS t3                                          ||           dS )zmCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().
        r   Nr   zSKIP ()S)
pywintypesrM   errorrc   non_admin_error_codesre   ru   ra   rb   CO_E_CLASSSTRINGREGDB_E_CLASSNOTREGTYPE_E_LIBNOTREGISTEREDr-   r   tupler0   	TypeErrorr   
setdefaultshowAllstreamwritelndotswriteflushr   addError)r   rP   errr   exc_valreasonr#   s         r   r   zTestResult.addError   s   
 	a& w
 011	7 $999"$$ : "'**GG !566 		77?%(,O
 <
 <

 "'**GG !455 	7!"566Gg{++ 	\!_Fv{++"I.   J!!&!,,,Jv!#| $##$6V$6$6$67777 $!!#&&&!!###Fs#####s   *C? ?DDc                     t                                                       | j                                        D ]$\  }}| j                            d||fz             %d S )NzSKIPPED: %d tests - %s)r   printErrorsr   itemsr   r   )r   r   num_skippedr#   s      r   r   zTestResult.printErrors  sm    #':#3#3#5#5 	R 	RFKK 8K;P PQQQQ	R 	Rr   )r6   r7   r8   r   r   r   __classcell__)r#   s   @r   r   r      st            -$ -$ -$ -$ -$^R R R R R R R R Rr   r   c                       e Zd Zd ZdS )
TestRunnerc                 B    t          | j        | j        | j                  S r   )r   r   descriptions	verbosityr   s    r   _makeResultzTestRunner._makeResult  s    $+t'8$.IIIr   N)r6   r7   r8   r   r:   r   r   r   r     s(        J J J J Jr   r   c                       e Zd Zd ZdS )TestProgramc                 x    t          | j                  | _        t          j                            |            d S )N)r   )r   r   
testRunnerr	   r   runTestsr   s    r   r   zTestProgram.runTests  s3    $t~>>>%%d+++++r   N)r6   r7   r8   r   r:   r   r   r   r     s#        , , , , ,r   r   c                      |                                 }d|vrt                      |d<   |                    dt                    } || i | d S )N
testLoadertestProgram)copyr<   getr   )r   r   new_kwprogram_classs       r   testmainr     sV    WWYYF6!!)|||JJ}k::MM4"6"""""r   )rf   )r   ri   rq   r   r	   rc   r
   r   r<   ERROR_ACCESS_DENIEDERROR_PRIVILEGE_NOT_HELDr   r_   re   r   	Exceptionru   TextTestResultr   TextTestRunnerr   r   r   r:   r   r   <module>r      s   				 				  



  LJ LJ LJ LJ LJ8$ LJ LJ LJ^* * * * *$ * * *l  % 
 	  *A A A A:	 	 	 	 	) 	 	 	7R 7R 7R 7R 7R( 7R 7R 7RvJ J J J J( J J J, , , , ,(& , , ,# # # # #r   