o ?OgX@sdZddlZddlZddlZddlZddlZddlZddlZddlmZm Z ddl m Z m Z m Z dZedejZGdd d e jZd d Zd d ZddZddZddZGdddeZeZdddZe jdfddZde je jfddZ de je jfddZ!dS) zLoading unittests.N)fnmatch fnmatchcase)casesuiteutilTz[_a-z]\w*\.py$cs,eZdZdZfddZfddZZS) _FailedTestNcs||_tt||dSN) _exceptionsuperr__init__)selfZ method_name exception __class__6/opt/alt/python310/lib64/python3.10/unittest/loader.pyr sz_FailedTest.__init__cs*|jkr tt|Sfdd}|S)Ncsjr )r rr rr testFailure!sz,_FailedTest.__getattr__..testFailure)_testMethodNamer r __getattr__)r namerrrrrs  z_FailedTest.__getattr__)__name__ __module__ __qualname__rr r __classcell__rrrrrs rcCs"d|tf}t|t|||S)Nz#Failed to import test module: %s %s) traceback format_exc_make_failed_test ImportError)r suiteClassmessagerrr_make_failed_import_test&sr"cCsdtf}t||||S)NzFailed to call load_tests: %s)rrr)rrr r!rrr_make_failed_load_tests+sr#cCst||}||f|fSr )r) methodnamerr r!testrrrr0s rcCs<tt|dd}||i}tdtjf|}|||fS)NcSsdSr rrrrr testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)r$rr r&ZattrsZ TestClassrrr_make_skipped_test4s  r+cCs*|dr |ddStj|dS)Nz $py.classir)lowerendswithospathsplitext)r/rrr_jython_aware_splitext<s r1cseZdZdZdZeejZdZ e j Z dZ fddZddZddd d Zd!d d Zd!d dZddZd"ddZddZddZddZddZd#ddZd#dd ZZS)$ TestLoaderz This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite r%Ncs tt|g|_t|_dSr )r r2r errorsset_loading_packagesrrrrr Ms zTestLoader.__init__cCsFt|tjr td||}|st|drdg}|t||}|S)z;Return a suite of all test cases contained in testCaseClasszYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest) issubclassr TestSuite TypeErrorgetTestCaseNameshasattrr map)r testCaseClassZ testCaseNamesZ loaded_suiterrrloadTestsFromTestCaseTs  z TestLoader.loadTestsFromTestCasepatternc Os4t|dks d|vrtdt|ddt|dkr)t|d}td|t|dkrReturn a suite of all test cases contained in the given modulerZuse_load_testsz(use_load_tests is deprecated and ignoredNrzCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}' load_tests)lenwarningswarnDeprecationWarningpopr8formatsorteddirgetattr isinstancer)r6rr*appendr=r Exceptionr#rr3) r moduler?argsZkwsZ complainttestsrobjr@e error_case error_messagerrrloadTestsFromModulebs>           zTestLoader.loadTestsFromModulec Cs2|d}d\}}|durJ|dd}|rDz d|}t|}Wn#tyA|}t||j\}}|s?|j||YSYnw|s|dd}|} |D]S} z | t | | } } WqNt y} z;t | dddur~|dur~|j||WYd} ~ St | | |jdt f\}}|j||WYd} ~ Sd} ~ wwt| tjr|| St| trt| tjr|| St| tjrt| trt| tjr|d}| |} tt | |tjs|| gSnt| tjr| St| r| }t|tjr|St|tjr ||gStd| |ftd | ) aSReturn a suite of all test cases given a string specifier. The name may resolve either to a module, a test case class, a test method within a test case class, or a callable object which returns a TestCase or TestSuite instance. The method optionally resolves the names relative to a given module. .NNNr__path__zFailed to access attribute: %sz"calling %s returned %s, not a testz$don't know how to make test from: %s)splitjoin __import__rrEr"r r3rKrIAttributeErrorrrrrJtypes ModuleTyperTr)r6rr*r= FunctionTyperr7callabler8)r rrMpartsrRrSZ parts_copy module_nameZnext_attributerPpartparentrQinstr%rrrloadTestsFromNames                   zTestLoader.loadTestsFromNamecsfdd|D}|S)zReturn a suite of all test cases found using the given sequence of string specifiers. See 'loadTestsFromName()'. csg|]}|qSr)rf).0rrMr rr sz1TestLoader.loadTestsFromNames..)r )r namesrMZsuitesrrhrloadTestsFromNamess zTestLoader.loadTestsFromNamescs>fdd}tt|t}jr|jtjd|S)zLReturn a sorted sequence of method names found within testCaseClass csZ|jsdSt|}t|sdSdjj|fjdup,tfddjDS)NFz%s.%s.%sc3s|]}t|VqdSr )r)rgr?ZfullNamerr szKTestLoader.getTestCaseNames..shouldIncludeMethod..) startswithtestMethodPrefixrIr`rrtestNamePatternsany)attrnameZtestFuncr r<rlrshouldIncludeMethods    z8TestLoader.getTestCaseNames..shouldIncludeMethod)key)listfilterrHsortTestMethodsUsingsort functools cmp_to_key)r r<rtZ testFnNamesrrsrr9s  zTestLoader.getTestCaseNamestest*.pyc Cs&d}|dur|jdur|j}n|durd}|}tj|}|tjvr)tjd|||_d}d}g}tjtj|rStj|}||krRtjtj|d }nzt |Wn t ydd}Ynwtj |}| dd} z tjtj |j}Wndtyz|j} Wn tyd} Ynw| r| jdur| jdurd}|jD]$} |s| |sq| |jdtjjd|_||j| |ddqn|jtjvrtddtd |dYnw|r|s|| |_tj|ntj||rt d ||st|||}| |S) a%Find and return all test modules from the specified start directory, recursing into subdirectories to find them and return all tests found within them. Only test files that match the pattern will be loaded. (Using shell style pattern matching.) All test modules must be importable from the top level of the project. If the start directory is not the top level directory then the top level directory must be specified separately. If a test package name (directory with '__init__.py') matches the pattern then the package will be checked for a 'load_tests' function. If this exists then it will be called with (loader, tests, pattern) unless the package has already had load_tests called from the same discovery invocation, in which case the package module object is not scanned for tests - this ensures that when a package uses discover to further discover child tests that infinite recursion does not happen. If load_tests exists then discovery does *not* recurse into the package, load_tests is responsible for loading all tests in the package. The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover(). Paths are sorted before being imported to ensure reproducible execution order even on filesystems with non-alphabetical ordering like ext3/4. FNTr __init__.pyrU) namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr.r/abspathsysinsertisdirisfilerZr[rmodulesrYdirname__file__r\__spec__loadersubmodule_search_locationsrWrnrreplacesepextend _find_testsbuiltin_module_namesr8rF _get_directory_containing_moduleremovervr ) r start_dirr?Z top_level_dirZset_implicit_topZis_not_importable is_namespacerOZ the_moduleZtop_partspecr/rrrdiscovers                   zTestLoader.discovercCsNtj|}tj|j}tj|dr!tj tj |Stj |S)Nr}) rrr.r/rrbasenamer,rnr)r rbrM full_pathrrrr`s  z+TestLoader._get_directory_containing_modulecCsh||jkrdSttj|}tj||j}tj|r!Jd|dr*Jd|tjj d}|S)NrUzPath must be within the projectz..) rr1r.r/normpathrelpathisabsrnrr)r r/Z_relpathrrrr_get_name_from_pathls zTestLoader._get_name_from_pathcCst|tj|Sr )r[rr)r rrrr_get_module_from_namexs z TestLoader._get_module_from_namecCs t||Sr )r)r r/rr?rrr _match_path|s zTestLoader._match_pathFc cs||}|dkr#||jvr#||||\}}|dur|V|s#dStt|}|D]@}tj||} || ||\}}|durE|V|rl|| }|j|z| | ||EdHW|j |q,|j |wq,dS)z/Used by discovery. Yields test suites it loads.rUN) rr5_find_test_pathrGr.listdirr/rZaddrdiscard) r rr?r~rrOZshould_recursepathsr/rrrrrs4   zTestLoader._find_testsc Csltj|}tj|rt|sdS||||sdS||}z||}Wn2t j yD}zt |||j dfWYd}~Sd}~wt ||j \}} |j| |dfYStjt|d|} ttj| } ttj|} | | krtj| } ttj|}tj|}d}t||| |f|j||ddfStj|r4|stjtj|dsdSd}d}||}z||}Wn2t j y}zt |||j dfWYd}~Sd}~wt ||j \}} |j| |dfYSt|dd}|j|z"|j||d}|dur"|dfW|j|S|d fW|j|S|j|wdS) zUsed by discovery. Loads tests from a single file, or a directories' __init__.py when passed the directory. Returns a tuple (None_or_tests_from_file, should_recurse). )NFFNrzW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?r>r}r@T)r.r/rrVALID_MODULE_NAMEmatchrrrrZSkipTestr+r r"r3rKrrIr1realpathr,rrrTrrZr5rr)r rr?r~rrrMrQrRrSZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr@rOpackagerrrrs                     zTestLoader._find_test_pathr )r|N)F)rrr__doc__ro staticmethodr three_way_cmprxrprr7r rr r=rTrfrkr9rrrrrrrrrrrrr2Bs(   ( N n   "r2cCs&t}||_||_||_|r||_|Sr )r2rxrorpr )prefix sortUsingr rprrrr _makeLoadersrcCst|||d|S)N)rp)rr9)r<rrrprrrr9sr9r%cCt||||Sr )rr=)r<rrr rrr makeSuite rcCrr )rrT)rMrrr rrr findTestCasesrrrV)"rr.rerrr]rzrBrrrrrZ __unittestcompile IGNORECASErr*rr"r#rr+r1objectr2ZdefaultTestLoaderrrr9r7rrrrrrs>/