j f@@sddZddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z dZ ej dejZGdd d e jZd d Zd d ZddZddZddZGdddeZeZdddZe jddZde je jddZde je jddZdS)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/python34/lib64/python3.4/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%srcCst|||S)N)r)rr rrrr_make_failed_load_tests)srcCst||}||fS)N)r) methodnamer rtestrrrr,srcCsYtjt|dd}i||6}tdtjf|}|||fS)NcSsdS)Nr)r rrr testSkipped1sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)rr rr!attrsZ TestClassrrr_make_skipped_test0s! r'cCs7|jjdr#|ddStjj|dS)Nz $py.class ri)lowerendswithospathsplitext)r,rrr_jython_aware_splitext8sr.c@seZdZdZdZeejZe j Z dZ ddZ dddZdd d Zdd d Zd dZddddZddZddZddZddZdddZdS) TestLoaderz This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite r NcCsnt|tjr!tdn|j|}| rRt|drRdg}n|jt||}|S)zpartsZ parts_copyrApartparentZinstr rrrloadTestsFromNamefsJ      !     zTestLoader.loadTestsFromNamecs)fdd|D}j|S)zReturn a suite of all tests cases found using the given sequence of string specifiers. See 'loadTestsFromName()'. cs"g|]}j|qSr)rP).0r)r>r rr s z1TestLoader.loadTestsFromNames..)r)r namesr>Zsuitesr)r>r rloadTestsFromNamesszTestLoader.loadTestsFromNamescCs\||jdd}tt|t|}|jrX|jdtj|jn|S)zLReturn a sorted sequence of method names found within testCaseClass cSs"|j|o!tt||S)N) startswithrLr:)Zattrnamer6prefixrrr isTestMethodsz1TestLoader.getTestCaseNames..isTestMethodkey)testMethodPrefixlistfilterr9sortTestMethodsUsingsort functools cmp_to_key)r r6rWZ testFnNamesrrrr3s  zTestLoader.getTestCaseNamesztest*.pyc Csd}|dkr-|jdk r-|j}n|dkrHd}|}ntjj|}|tjkrtjjd|n||_d}d}g}tjjtjj|rtjj|}||krtjjtjj|d }qnyt |Wnt k r&d}YnXtj |}|j dd} y%tjjtjj |j}Wn!tk ry |j} Wntk rd} YnX| rO| jdkrO| jdk rd}x{|jD]m} | r| j| rqn| j |jjdtjjd|_|j|j| |ddqWqn<|jtjkrstddntd j|dYnX|r|s|j| |_tjj|qtjj|n|rt d |n|st|j||}n|j |S) aFind 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. 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__.pyrD 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,abspathsysinsertisdirisfilerHrGrmodulesrFdirname__file__AttributeError__spec__loadersubmodule_search_locations__path__rUrreplacesepextend _find_testsbuiltin_module_namesr2format _get_directory_containing_moduleremoverZr) r start_dirpatternZ top_level_dirZset_implicit_topZis_not_importable is_namespacer@Z the_moduleZtop_partspecr,rrrdiscoversv     (          zTestLoader.discovercCsstj|}tjj|j}tjj|jjdr_tjj tjj |Stjj |SdS)Nz __init__.py) rcrgr+r,rbribasenamer)rUrh)r Z module_namer> full_pathrrrrus  !z+TestLoader._get_directory_containing_modulecCsttjj|}tjj||j}tjj| sOtd|jd sktd|j tjj d}|S)NzPath must be within the projectz..rD) r.r+r,normpathrelpathraisabsAssertionErrorrUrorp)r r,Z_relpathrrrr_get_name_from_path"s zTestLoader._get_name_from_pathcCst|tj|S)N)rGrcrg)r rrrr_get_module_from_name,s z TestLoader._get_module_from_namecCs t||S)N)r)r r,r}rxrrr _match_path0szTestLoader._match_pathFccsttj|}x|D]}tjj||}tjj|rtj|s^qn|j|||syqn|j |}y|j |}WnTt j k r} zt || |jVWYdd} ~ Xqt||jVYqXtjjt|d|} ttjj| } ttjj|} | j| jkrtjj| } ttjj|}tjj|}d}t||| |fn|j|Vqtjj|r| rtjjtjj|d rqnd}d}t||rk|j |}|j |}t|dd}|j|dd}n|dkr|dk r|Vn|j||d|DdHqy||||VWqtk r} zt|j| |jVWYdd} ~ XqXqqWdS) z/Used by discovery. Yields test suites it loads.NrizW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?z __init__.pyr8r?Fr`)sortedr+listdirr,rHrfVALID_MODULE_NAMEmatchrrrrZSkipTestr'rrrbr:r.realpathr)rhr|rrCrerrrr=rr)r rwrxr`pathsr,r}rr>rBZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr8r@packagerrrrr4s\ &"   zTestLoader._find_tests)rrr__doc__rY staticmethodr three_way_cmpr\rr1rrar7rCrPrTr3r{rurrrrrrrrrr/>s   3 j  r/cCs1t}||_||_|r-||_n|S)N)r/r\rYr)rV sortUsingrrlrrr _makeLoaderss     rcCst||j|S)N)rr3)r6rVrrrrr3{sr3r cCst|||j|S)N)rr7)r6rVrrrrr makeSuite~srcCst|||j|S)N)rrC)r>rVrrrrr findTestCasessr) rr+rercrrIr^rrrrZ __unittestcompile IGNORECASErr%rrrrr'r.objectr/ZdefaultTestLoaderrrr3r1rrrrrrs2           3