a oe -@sddlZddlZddlZddlZddlZddlZddZddZddZGdd d ej Z Gd d d ej Z ej ej gZdad d ZdddZGdddeZz ejZWneyejZYn0GdddeZGdddejZGdddejZddZdS)NcCs(tjdkrt|tr|d}|dSNrlatin1)sys version_info isinstancestrdecodeencodeZsvalr ;C:\Program Files\Certbot\pkgs\win32\lib\pywin32_testutil.py str2bytess rcCs tjdkrt|St|dSr)rrbuffer memoryviewr r r r r str2memorys rcCstjdkrt|St|S)Nr)rrrr)obr r r ob2memory!s rc@s<eZdZdZddZddZd ddZd d Zdd d ZdS) LeakTestCaseaAn '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. cCs:tj|||_d|_d|_ttdr6|j|j|_dS)Ngettotalrefcount)unittestTestCase__init__ real_testnum_test_casesnum_leak_itershasattrr)selfrr r rr:s   zLeakTestCase.__init__cCs|jSN)rr r r rcountTestCasesBszLeakTestCase.countTestCasesNc Csddlm}m}t|}|}|||js<|s@dS||t||}||}|sn|rd||f}t |} | |j| j | dfdS)Nr)_GetGatewayCount_GetInterfaceCountz2%d interface objects and %d gateway objects leaked) pythoncomr$r%gccollectr shouldStopZ wasSuccessful_do_leak_testsAssertionError addFailure __class__) r resultr$r%ZniZngZlost_iZlost_gmsgexcr r r__call__Es$    zLeakTestCase.__call__cCsds JddS)Nrznot usedr r"r r rrunTest]szLeakTestCase.runTestcCsz tj}WntyYdS0t|}t|jD]}|||jr8qRq8~t|||j}|dkrd|j| f}| |jt |df|dkrd|j|f}t |}| |j|j |dfdS)Nrz-LeakTest: %s appeared to gain %d references!!zLeakTest: %s lost %d references) rrAttributeErrorr'r(rangerrr)r,r+r-)r r.ZgtrcZtrciZlostr/r0r r rr*`s.   zLeakTestCase._do_leak_tests)N)N) __name__ __module__ __qualname____doc__rr#r1r2r*r r r rr.s   rc@s6eZdZddZddZddZddZd d d Zd S) TestLoadercCs:g}||D] }||}||}||q||S)zz5TestLoader.fixupTestsForLeakTests..)rr TestSuiteZ_testsr;)r testr r"rr?s z!TestLoader.fixupTestsForLeakTestscCs$t|dd}|rtd|St|S)N no_leak_testsFz%Test says it doesn't want leak tests!)getattrprintr)r rErFr r rr;s  zTestLoader._getTestWrappercCs,t|dr|}ntj||}||S)Nsuite)rrIrr:loadTestsFromModuler?)r modZtestsr r rrJs  zTestLoader.loadTestsFromModuleNcCsDtj|||}t|tjrn"t|tjr6||}n td||S)Nz XXX - what is)rr:loadTestsFromNamerrDrr;rH)r r=modulerEr r rrLs    zTestLoader.loadTestsFromName)N)r6r7r8r>r?r;rJrLr r r rr:}s  r:c Csdtdur`ddl}ddlm}z |aWn8|jy^}z|jtjkrFdaWYd}~n d}~00tS)Nr) IsUserAnAdminT) _is_adminr&Zwin32com.shell.shellrN com_errorhresultwinerrorZ E_NOTIMPL)r&rNr0r r rcheck_is_admins   rS.cCstjtjd|dg}|D]&}tj||}tj|r|Sqtjtjtjd}t dd}t j r| t j |D]4}tj|}tj ||g|krtd|dqtd|ddS)NrrTzCan't find test fixture '')ospathdirnamerargvjoinisfilenormcaseabspathsitegetsitepackages USER_SITEr< commonprefix TestSkipped RuntimeError)basenameZ extra_dirZ candidates candidatefnameZ this_fileZ dirs_to_checkdr r rfind_test_fixtures"    rhc@s eZdZdS)rbN)r6r7r8r r r rrbsrbcs4eZdZfddZfddZfddZZS) TestResultcs tt|j|i|i|_dSr!)superrirskips)r argskwr-r rrszTestResult.__init__c s"ddl}|d}t||jr6|jtvr6ts6t|}n>t||jrb|jtj tj tj fvrbt|}nt|t rttt }t|tr |j d}zt|j }WnttfyYn0|j|d|j|d7<|jr|jd|fn|jr|jd|jdStt|||dS)zmCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info(). rNrz SKIP (%s)S) pywintypesrerrorrRnon_admin_error_codesrSrbrPrQZCO_E_CLASSSTRINGZREGDB_E_CLASSNOTREGZTYPE_E_LIBNOTREGISTEREDNotImplementedErrorrltupler3 TypeErrorrk setdefaultZshowAllstreamwritelnZdotswriteflushrjriaddError)r rEerrrpZexc_valreasonrnr rr{s@        zTestResult.addErrorcs:tt||jD]\}}|jd||fqdS)NzSKIPPED: %d tests - %s)rjri printErrorsrkitemsrwrx)r r}Z num_skippedrnr rr~,szTestResult.printErrors)r6r7r8rr{r~ __classcell__r r rnrris  /ric@seZdZddZdS) TestRunnercCst|j|j|jSr!)rirwZ descriptions verbosityr"r r r _makeResult4szTestRunner._makeResultN)r6r7r8rr r r rr3src@seZdZddZdS) TestProgramcCst|jd|_tj|dS)N)r)rrZ testRunnerrrrunTestsr"r r rr;szTestProgram.runTestsN)r6r7r8rr r r rr:srcOs8|}d|vrt|d<|dt}||i|dS)NZ testLoaderZ testProgram)copyr:getr)rlrmZnew_kwZ program_classr r rtestmainBs   r)rT)r'rVr^rrrRrrrrrr:ZERROR_ACCESS_DENIEDZERROR_PRIVILEGE_NOT_HELDrrrOrSrh ExceptionrbZ_TextTestResultZTextTestResultr3riZTextTestRunnerrrrr r r rs2  O5    ;