YfV@spdZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z dZ ejdejZGdd d e jZd d Zd d ZddZddZddZGdddeZeZdddZe jddZde je jddZde je jddZ dS)zLoading unittests.N)fnmatch)casesuiteutilTz[_a-z]\w*\.py$cs:eZdZdZfddZfddZS) _FailedTestNcs#||_tt|j|dS)N) _exceptionsuperr__init__)selfZ method_name exception) __class__4/opt/alt/python35/lib64/python3.5/unittest/loader.pyr s z_FailedTest.__init__cs;|jkr%ttj|Sfdd}|S)Ncs jdS)N)rr)r rr testFailure!sz,_FailedTest.__getattr__..testFailure)_testMethodNamer r __getattr__)r namer)r )r rrsz_FailedTest.__getattr__)__name__ __module__ __qualname__rr rrr)r rrs rcCs/d|tjf}t|t|||S)Nz#Failed to import test module: %s %s) traceback format_exc_make_failed_test ImportError)r suiteClassmessagerrr_make_failed_import_test&srcCs&dtjf}t||||S)NzFailed to call load_tests: %s)rrr)rr rrrrr_make_failed_load_tests+srcCs"t||}||f|fS)N)r) methodnamer rrtestrrrr0srcCsXtjt|dd}||i}tdtjf|}|||fS)NcSsdS)Nr)r rrr testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)rr rr!ZattrsZ TestClassrrr_make_skipped_test4s! r&cCs7|jjdr#|ddStjj|dS)Nz $py.class ri)lowerendswithospathsplitext)r+rrr_jython_aware_splitext<sr-cseZdZdZdZeejZe j Z dZ fddZ ddZddd d Zdd d Zdd dZddZddddZddZddZddZddZdddZddd ZS)! TestLoaderz This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite r Ncs,tt|jg|_t|_dS)N)r r.r errorsset_loading_packages)r )r rrr Ls zTestLoader.__init__cCsht|tjrtd|j|}| rLt|drLdg}|jt||}|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 TypeErrorgetTestCaseNameshasattrrmap)r testCaseClassZ testCaseNamesZ loaded_suiterrrloadTestsFromTestCaseSs  z TestLoader.loadTestsFromTestCasepatternc Ost|dksd|kr>tjdt|jddt|dkrut|d}tdj|t|dkrt|d}tdj|g}xZt|D]L}t ||}t |t rt |t jr|j|j|qWt |dd} |j|}| dk ry| |||SWnWtk r} z7t|j| |j\} } |jj| | SWYdd} ~ XnX|S) z>Return 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)lenwarningswarnDeprecationWarningpopr4formatsorteddirgetattr isinstancer$r2rr%appendr9r Exceptionrrr/) r moduler:argsZkwsZ complainttestsrobjr;e error_case error_messagerrrloadTestsFromModuleas4 ! zTestLoader.loadTestsFromModulecCs|jd}d\}}|dkr|dd}x}|ry dj|}t|}PWq:tk r|j}t||j\}}|s|jj||SYq:Xq:W|dd}|} x|D]} y| t | | } } Wqt k r} z|t | dddk rA|dk rA|jj||St | | |jdt j f\}}|jj||SWYdd} ~ XqXqWt| tjr|j| St| trt| tjr|j| St| tjr[t| tr[t| tjr[|d }| |} tt | |tjsq|j| gSnt| tjrq| St| r| }t|tjr|St|tjr|j|gStd| |fntd| dS) 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. .Nr__path__zFailed to access attribute: %sz"calling %s returned %s, not a testz$don't know how to make test from: %s)NN)splitjoin __import__rr@rrr/rFrDAttributeErrorrrrrEtypes ModuleTyperOr$r2rr%r9 FunctionTyperr3callabler4)r rrHpartsrMrNZ parts_copy module_nameZnext_attributerKpartparentrLZinstr rrrloadTestsFromNamesl            !     zTestLoader.loadTestsFromNamecs)fdd|D}j|S)zReturn a suite of all test cases found using the given sequence of string specifiers. See 'loadTestsFromName()'. cs"g|]}j|qSr)r_).0r)rHr rr s z1TestLoader.loadTestsFromNames..)r)r namesrHZsuitesr)rHr rloadTestsFromNamesszTestLoader.loadTestsFromNamescCsY||jdd}tt|t|}|jrU|jdtj|j|S)zLReturn a sorted sequence of method names found within testCaseClass cSs"|j|o!tt||S)N) startswithrZrD)Zattrnamer8prefixrrr isTestMethodsz1TestLoader.getTestCaseNames..isTestMethodkey)testMethodPrefixlistfilterrCsortTestMethodsUsingsort functools cmp_to_key)r r8rfZ testFnNamesrrrr5s  zTestLoader.getTestCaseNamesztest*.pyc Csd}|dkr-|jdk r-|j}n|dkrEd}|}tjj|}|tjkrytjjd|||_d}d}g}tjjtjj|rtjj|}||krtjjtjj|d }nyt |Wnt k rd}YnXtj |}|j dd} y%tjjtjj |j}Wntk ry |j} Wntk rd} YnX| r@| jdkr@| jdk r|d}x|jD]j} | r| j| rq| j |jjdtjjd|_|j|j| |ddqWn<|jtjkrdtddntd j|dYnX|r|s|j| |_tjj|ntjj||rt d ||st|j||}|j |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. FNTrz __init__.pyrP 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+abspathsysinsertisdirisfilerTrUrmodulesrSdirname__file__rV__spec__loadersubmodule_search_locationsrQrdrreplacesepextend _find_testsbuiltin_module_namesr4rA _get_directory_containing_moduleremoverir) r start_dirr:Z top_level_dirZset_implicit_topZis_not_importable is_namespacerJZ the_moduleZtop_partspecr+rrrdiscoversv    %          zTestLoader.discovercCsstj|}tjj|j}tjj|jjdr_tjj tjj |Stjj |SdS)Nz __init__.py) rrrvr*r+rqrxbasenamer(rdrw)r r\rH full_pathrrrrXs  !z+TestLoader._get_directory_containing_modulecCs||jkrdSttjj|}tjj||j}tjj| sbtd|jd s~td|j tjj d}|S)NrPzPath must be within the projectz..) rpr-r*r+normpathrelpathisabsAssertionErrorrdr|r})r r+Z_relpathrrrr_get_name_from_pathdszTestLoader._get_name_from_pathcCst|tj|S)N)rUrrrv)r rrrr_get_module_from_nameps z TestLoader._get_module_from_namecCs t||S)N)r)r r+rr:rrr _match_pathtszTestLoader._match_pathFc cs |j|}|dkr`||jkr`|j|||\}}|dk rV|V|s`dSttj|}x|D]}tjj||} |j| ||\}}|dk r|V|r||j| }|jj|z|j | ||EdHWd|jj |Xq|WdS)z/Used by discovery. Yields test suites it loads.rPN) rr1_find_test_pathrBr*listdirr+rTaddrdiscard) r rr:rorrJZshould_recursepathsr+rrrrrxs*   zTestLoader._find_testscCs0tjj|}tjj|rtj|s7d S|j|||sPd S|j|}y|j|}Wnzt j k r}zt |||j dfSWYdd}~Xq,t ||j \}} |jj| |dfSYq,Xtjjt|d|} ttjj| } ttjj|} | j| jkrtjj| } ttjj|}tjj|}d}t||| |f|j|d|dfSn`tjj|r(| r tjjtjj|d r d Sd}d}|j|}y|j|}Wnzt j k r|}zt |||j dfSWYdd}~Xq,t ||j \}} |jj| |dfSYq,Xt|dd}|jj|z9|j|d|}|dk r|dfS|dfSWd|jj|Xnd SdS) 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). NFrxzW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?r:z __init__.pyr;T)NF)NF)NF)NF)r*r+rruVALID_MODULE_NAMEmatchrrrrZSkipTestr&rrr/rFrqrDr-realpathr(rwrrOrtrTr1rr)r rr:rorrrHrLrMrNZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr;rJpackagerrrrsl+ "+  zTestLoader._find_test_path)rrr__doc__rh staticmethodr three_way_cmprkrr3rrpr r9rOr_rcr5rrrrrrrrr)r rr.Bs$   (N n  "r.cCs.t}||_||_|r*||_|S)N)r.rkrhr)re sortUsingrrzrrr _makeLoaders     rcCst||j|S)N)rr5)r8rerrrrr5sr5r cCst|||j|S)N)rr9)r8rerrrrr makeSuitesrcCst|||j|S)N)rrO)rHrerrrrr findTestCasessr)!rr*rerrrrWrmr=rrrrZ __unittestcompile IGNORECASErr%rrrrr&r-objectr.ZdefaultTestLoaderrrr5r3rrrrrrs4