3 \V@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z dZ ej dejZGddde jZd d Zd d Zd dZddZddZGdddeZeZdddZe jfddZde je jfddZde je jfddZdS)N)fnmatch)casesuiteutilTz[_a-z]\w*\.py$cs,eZdZdZfddZfddZZS) _FailedTestNcs||_tt|j|dS)N) _exceptionsuperr__init__)selfZ method_name exception) __class__'/usr/lib64/python3.6/unittest/loader.pyr sz_FailedTest.__init__cs*|jkrttj|Sfdd}|S)Ncs jdS)N)rr)r rr testFailure!sz,_FailedTest.__getattr__..testFailure)_testMethodNamer r __getattr__)r namer)r )r rrs  z_FailedTest.__getattr__)__name__ __module__ __qualname__rr r __classcell__rr)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&srcCsdtjf}t||||S)NzFailed to call load_tests: %s)rrr)rr rrrrr_make_failed_load_tests+srcCst||}||f|fS)N)r) methodnamer rrtestrrrr0s rcCs<tjt|dd}||i}tdtjf|}|||fS)NcSsdS)Nr)r rrr testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)r r rr"ZattrsZ TestClassrrr_make_skipped_test4sr'cCs*|jjdr|ddStjj|dS)Nz $py.class ri)lowerendswithospathsplitext)r,rrr_jython_aware_splitext<s r.cseZdZdZeejZej Z dZ fddZ ddZ dddd Zd d d Zd!d d ZddZd"ddZddZddZddZddZd#ddZd$ddZZS)% TestLoaderr!Ncs tt|jg|_t|_dS)N)r r/r errorsset_loading_packages)r )r rrr LszTestLoader.__init__cCsHt|tjrtd|j|}| r4t|dr4dg}|jt||}|S)NzYTest 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.loadTestsFromTestCase)patternc Os2t|dksd|kr,tjdt|jddt|dkrRt|d}tdj|t|dkrxt|d}tdj|g}x@t|D]4}t ||}t |t rt |t jr|j|j|qWt |dd} |j|}| dk r.y | |||Stk r,} z$t|j| |j\} } |jj| | Sd} ~ XnX|S)NrZuse_load_testsz(use_load_tests is deprecated and ignoredrzCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}' load_tests)lenwarningswarnDeprecationWarningpopr5formatsorteddirgetattr isinstancer%r3rr&appendr:r Exceptionrrr0) r moduler;argsZkwsZ complainttestsrobjr<e error_case error_messagerrrloadTestsFromModuleas4           zTestLoader.loadTestsFromModulecCs>|jd}d\}}|dkr|dd}xb|rydj|}t|}PWq(tk r|j}t||j\}}|s|jj||SYq(Xq(W|dd}|} x|D]} y| t | | } } Wqt k r2} z\t | dddk r|dk r|jj||St | | |jdt j f\}}|jj||SWYdd} ~ XqXqWt| tjrP|j| St| trtt| tjrt|j| St| tjrt| trt| tjr|d}| |} tt | |tjs|j| gSnt| tjr| St| r.| }t|tjr|St|tjr|j|gStd| |fn td| dS) N.r__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__rrArrr0rGrEAttributeErrorrrrrFtypes ModuleTyperPr%r3rr&r: FunctionTyperr4callabler5)r rrIpartsrNrOZ parts_copy module_nameZnext_attributerLpartparentrMZinstr!rrrloadTestsFromNamesl             zTestLoader.loadTestsFromNamecsfdd|D}j|S)Ncsg|]}j|qSr)r`).0r)rIr rr sz1TestLoader.loadTestsFromNames..)r)r namesrIZsuitesr)rIr rloadTestsFromNamesszTestLoader.loadTestsFromNamescCs@||jfdd}tt|t|}|jr<|jtj|jd|S)NcSs|j|ott||S)N) startswithr[rE)Zattrnamer9prefixrrr isTestMethods z1TestLoader.getTestCaseNames..isTestMethod)key)testMethodPrefixlistfilterrDsortTestMethodsUsingsort functools cmp_to_key)r r9rgZ testFnNamesrrrr6s zTestLoader.getTestCaseNamestest*.pyc CsRd}|dkr|jdk r|j}n|dkr.d}|}tjj|}|tjkrRtjjd|||_d}d}g}tjjtjj|rtjj|}||krtjjtjj|d }nxy t |Wnt k rd}YnRXtj |}|j dd} ytjjtjj |j}Wntk ry |j} Wntk r8d} YnX| r| jdkr| jdk rd}x|jD]T} | r| j| rqd| j |jjdtjjd|_|j|j| |ddqdWn*|jtjkrtddntdj|dYnX|r |s|j| |_tjj|n tjj||r2t d ||sHt|j||}|j |S) NFTrz __init__.pyrQ) 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,abspathsysinsertisdirisfilerUrVrmodulesrTdirname__file__rW__spec__loadersubmodule_search_locationsrRrerreplacesepextend _find_testsbuiltin_module_namesr5rB _get_directory_containing_moduleremoverjr) r start_dirr;Z top_level_dirZset_implicit_topZis_not_importable is_namespacerKZ the_moduleZtop_partspecr,rrrdiscoversv               zTestLoader.discovercCsRtj|}tjj|j}tjj|jjdrBtjj tjj |Stjj |SdS)Nz __init__.py) rtrxr+r,rsrzbasenamer)rery)r r]rI full_pathrrrrXs  z+TestLoader._get_directory_containing_modulecCsB||jkrdSttjj|}tjj||j}|jtjjd}|S)NrQ)rrr.r+r,normpathrelpathr~r)r r,Z_relpathrrrr_get_name_from_pathds  zTestLoader._get_name_from_pathcCst|tj|S)N)rVrtrx)r rrrr_get_module_from_namepsz TestLoader._get_module_from_namecCs t||S)N)r)r r,rr;rrr _match_pathtszTestLoader._match_pathFc cs|j|}|dkrD||jkrD|j|||\}}|dk r<|V|sDdSttj|}x||D]t}tjj||} |j| ||\}}|dk r|V|rX|j| }|jj|z|j | ||EdHWd|jj |XqXWdS)NrQ) rr2_find_test_pathrCr+listdirr,rUaddrdiscard) r rr;rqrrKZshould_recursepathsr,rrrrrxs*    zTestLoader._find_testscCsPtjj|}tjj|rFtj|s(dS|j|||s:d S|j|}y|j|}WnXt j k r}zt |||j dfSd}~Xnt ||j \}} |jj| |dfStjjt|d|} ttjj| } ttjj|} | j| jkr0tjj| } ttjj|}tjj|}d}t||| |f|j||ddfSntjj|rH| rztjjtjj|d rzd Sd}d}|j|}y|j|}WnZt j k r}zt |||j dfSd}~Xnzt ||j \}} |jj| |dfSt|dd}|jj|z(|j||d}|dk r0|dfS|dfS|jj|Xnd SdS) NFrzzW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?)r;z __init__.pyr<T)NF)NF)NF)NF)r+r,rrwVALID_MODULE_NAMEmatchrrrrZSkipTestr'rrr0rGrsrEr.realpathr)ryrrPrvrUr2rr)r rr;rqrrrIrMrNrOZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr<rKpackagerrrrsl           zTestLoader._find_test_path)N)N)rpN)F)F)rrrri staticmethodr three_way_cmprlrr4rrrr r:rPr`rdr6rrrrrrrrrr)r rr/Bs"  ( N  n   "r/cCs t}||_||_|r||_|S)N)r/rlrir)rf sortUsingrr|rrr _makeLoaders rcCst||j|S)N)rr6)r9rfrrrrr6sr6r!cCst|||j|S)N)rr:)r9rfrrrrr makeSuites rcCst|||j|S)N)rrP)rIrfrrrrr findTestCasess r)N) r+rertrrXrnr>rrrrZ __unittestcompile IGNORECASErr&rrrrr'r.objectr/ZdefaultTestLoaderrrr6r4rrrrrrs6 '