grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 \ÐVã@sdZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z dZ ejdejƒZGdd „d e jƒZd d „Zd d „Zdd„Zdd„Zdd„ZGdd„deƒZeƒZddd„Ze jfdd„Zde je jfdd„Zde je jfdd„Z dS) zLoading unittests.éN)Úfnmatché)ÚcaseÚsuiteÚutilTz[_a-z]\w*\.py$cs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú _FailedTestNcs||_tt|ƒj|ƒdS)N)Ú _exceptionÚsuperrÚ__init__)ÚselfZ method_nameÚ exception)Ú __class__©ú'/usr/lib64/python3.6/unittest/loader.pyr sz_FailedTest.__init__cs*|ˆjkrttˆƒj|ƒS‡fdd„}|S)Ncs ˆj‚dS)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|tjƒf}t|t|ƒ||ƒS)Nz#Failed to import test module: %s %s)Ú tracebackÚ format_excÚ_make_failed_testÚ ImportError)rÚ suiteClassÚmessagerrrÚ_make_failed_import_test&srcCsdtjƒf}t||||ƒS)NzFailed to call load_tests: %s)rrr)rr rrrrrÚ_make_failed_load_tests+srcCst||ƒ}||fƒ|fS)N)r)Ú methodnamer rrÚtestrrrr0s rcCs<tjt|ƒƒdd„ƒ}||i}tdtjf|ƒ}|||ƒfƒS)NcSsdS)Nr)r rrrÚ testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rÚskipÚstrÚtypeÚTestCase)r r rr"ÚattrsZ TestClassrrrÚ_make_skipped_test4sr(cCs*|jƒjdƒr|dd…Stjj|ƒdS)Nz $py.classé ri÷ÿÿÿ)ÚlowerÚendswithÚosÚpathÚsplitext)r-rrrÚ_jython_aware_splitext<s r/cs¨eZdZdZdZeejƒZe j Z dZ ‡fdd„Z dd„Zddœd d „Zd!d d „Zd"d d„Zdd„Zd#dd„Zdd„Zdd„Zdd„Zdd„Zd$dd„Zd%dd „Z‡ZS)&Ú TestLoaderz� This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite r!Ncs tt|ƒjƒg|_tƒ|_dS)N)r r0r ÚerrorsÚsetÚ_loading_packages)r )r rrr LszTestLoader.__init__cCsHt|tjƒrtdƒ‚|j|ƒ}| r4t|dƒr4dg}|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Ú TypeErrorÚgetTestCaseNamesÚhasattrrÚmap)r Ú testCaseClassZ testCaseNamesZ loaded_suiterrrÚloadTestsFromTestCaseSs  z TestLoader.loadTestsFromTestCase)Úpatternc Os2t|ƒdksd|kr,tjdtƒ|jddƒt|ƒdkrRt|ƒd}tdj|ƒƒ‚t|ƒdkrxt|ƒd}tdj|ƒƒ‚g}x@t|ƒD]4}t ||ƒ}t |t ƒr†t |t jƒr†|j|j|ƒƒq†Wt |ddƒ} |j|ƒ}| dk �r.y | |||ƒStk �r,} z$t|j| |jƒ\} } |jj| ƒ| Sd} ~ 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)ÚlenÚwarningsÚwarnÚDeprecationWarningÚpopr6ÚformatÚsortedÚdirÚgetattrÚ isinstancer%r4rr&Úappendr;rÚ Exceptionrrr1) r Úmoduler<ÚargsZkwsZ complaintÚtestsrÚobjr=ÚeÚ error_caseÚ error_messagerrrÚloadTestsFromModuleas4           zTestLoader.loadTestsFromModulecCs>|jdƒ}d\}}|dkr–|dd…}xb|rˆydj|ƒ}t|ƒ}PWq(tk r„|jƒ}t||jƒ\}}|s€|jj|ƒ|SYq(Xq(W|dd…}|} xœ|D]”} y| t | | ƒ} } Wq t k �r2} z\t | ddƒdk rô|dk rô|jj|ƒ|St | | |jdt j ƒfƒ\}}|jj|ƒ|SWYdd} ~ Xq Xq Wt| tjƒ�rP|j| ƒSt| tƒ�rtt| tjƒ�rt|j| ƒSt| tjƒ�rÎt| tƒ�rÎt| tjƒ�rÎ|d }| |ƒ} tt | |ƒtjƒ�sà|j| gƒSnt| tjƒ�rà| St| ƒ�r.| ƒ}t|tjƒ�r|St|tjƒ�r|j|gƒStd| |fƒ‚n td| ƒ‚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éÿÿÿÿ)ÚsplitÚjoinÚ __import__rrBrrr1rHrFÚAttributeErrorrrrrGÚtypesÚ ModuleTyperQr%r4rr&r;Ú FunctionTyperr5Úcallabler6)r rrJÚpartsrOrPZ parts_copyÚ module_nameZnext_attributerMÚpartÚparentrNZinstr!rrrÚloadTestsFromName‰sl             zTestLoader.loadTestsFromNamecs‡‡fdd„|Dƒ}ˆj|ƒS)z�Return a suite of all test cases found using the given sequence of string specifiers. See 'loadTestsFromName()'. csg|]}ˆj|ˆƒ‘qSr)ra)Ú.0r)rJr rrú Ûsz1TestLoader.loadTestsFromNames..)r)r ÚnamesrJZsuitesr)rJr rÚloadTestsFromNames×szTestLoader.loadTestsFromNamescCs@||jfdd„}tt|t|ƒƒƒ}|jr<|jtj|jƒd�|S)zLReturn a sorted sequence of method names found within testCaseClass cSs|j|ƒott||ƒƒS)N)Ú startswithr\rF)Zattrnamer:ÚprefixrrrÚ isTestMethodás z1TestLoader.getTestCaseNames..isTestMethod)Úkey)ÚtestMethodPrefixÚlistÚfilterrEÚsortTestMethodsUsingÚsortÚ functoolsÚ cmp_to_key)r r:rhZ testFnNamesrrrr7Þs zTestLoader.getTestCaseNamesútest*.pyc CsRd}|dkr|jdk r|j}n|dkr.d}|}tjj|ƒ}|tjkrRtjjd|ƒ||_d}d}g}tjjtjj|ƒƒr¨tjj|ƒ}||kr¤tjjtjj|dƒƒ }�nxy t |ƒWnt k rÎd}Y�nRXtj |}|j dƒd} ytjjtjj |jƒƒ}Wnêtk �rìy |j} Wntk �r8d} YnX| �r¾| jdk�r¾| jdk �rèd}xŠ|jD]T} | �r‚| j|ƒ �r‚�qd| j |jjdtjjƒƒd|_|j|j| |dd�ƒ�qdWn*|jtjk�rØtdƒd‚ntd j|ƒƒd‚YnX|�r |�s|j| ƒ|_tjj|ƒn tjj|ƒ|�r2t d |ƒ‚|�sHt|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__.pyrR)Ú 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-ÚabspathÚsysÚinsertÚisdirÚisfilerVrWrÚmodulesrUÚdirnameÚ__file__rXÚ__spec__ÚloaderÚsubmodule_search_locationsrSrfrÚreplaceÚsepÚextendÚ _find_testsÚbuiltin_module_namesr6rCÚ _get_directory_containing_moduleÚremoverkr) r Ú start_dirr<Z top_level_dirZset_implicit_topZis_not_importableÚ is_namespacerLZ the_moduleZtop_partÚspecr-rrrÚdiscoverêsv               zTestLoader.discovercCsRtj|}tjj|jƒ}tjj|ƒjƒjdƒrBtjj tjj |ƒƒStjj |ƒSdS)Nz __init__.py) ruryr,r-rtr{Úbasenamer*rfrz)r r^rJÚ full_pathrrrr„Xs  z+TestLoader._get_directory_containing_modulecCsl||jkrdSttjj|ƒƒ}tjj||jƒ}tjj|ƒ sDtdƒ‚|jdƒ sXtdƒ‚|j tjj dƒ}|S)NrRzPath must be within the projectz..) rsr/r,r-ÚnormpathÚrelpathÚisabsÚAssertionErrorrfrr€)r r-Z_relpathrrrrÚ_get_name_from_pathds zTestLoader._get_name_from_pathcCst|ƒtj|S)N)rWrury)r rrrrÚ_get_module_from_namepsz TestLoader._get_module_from_namecCs t||ƒS)N)r)r r-r‹r<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)z/Used by discovery. Yields test suites it loads.rRN) r�r3Ú_find_test_pathrDr,Úlistdirr-rVÚaddr‚Údiscard) r r†r<rrrrLZshould_recurseÚpathsr-r‹rrrr‚xs*    zTestLoader._find_testscCsPtjj|ƒ}tjj|ƒ�rFtj|ƒs(d S|j|||ƒs:d S|j|ƒ}y|j|ƒ}WnXt j k r‚}zt |||j ƒdfSd}~XnÀt ||j ƒ\}} |jj| ƒ|dfStjjt|d|ƒƒ} ttjj| ƒƒ} ttjj|ƒƒ} | jƒ| jƒk�r0tjj| ƒ} ttjj|ƒƒ}tjj|ƒ}d}t||| |fƒ‚|j||d�dfS�ntjj|ƒ�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) zÉUsed 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). NFr{zW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?)r<z __init__.pyr=T)NF)NF)NF)NF)r,r-rŠrxÚVALID_MODULE_NAMEÚmatchr’r�r‘rZSkipTestr(rrr1rHrtrFr/Úrealpathr*rzrrQrwrVr3r•r–)r r‹r<rrrŠrrJrNrOrPZmod_fileršZfullpath_noextZ module_dirZmod_nameZ expected_dirÚmsgr=rLÚpackagerrrr“šsl           zTestLoader._find_test_path)N)N)rqN)F)F)rrrÚ__doc__rjÚ staticmethodrÚ three_way_cmprmrr5rrsr r;rQrarer7r‰r„r�r‘r’r‚r“rrr)r rr0Bs$  ( N  n   "r0cCs tƒ}||_||_|r||_|S)N)r0rmrjr)rgÚ sortUsingrr}rrrÚ _makeLoaderés r¡cCst||ƒj|ƒS)N)r¡r7)r:rgr rrrr7ñsr7r!cCst|||ƒj|ƒS)N)r¡r;)r:rgr rrrrÚ makeSuiteôs r¢cCst|||ƒj|ƒS)N)r¡rQ)rJrgr rrrrÚ findTestCasesùs r£)N)!r�r,ÚrerurrYror?rÚrrrZ __unittestÚcompileÚ IGNORECASEr˜r&rrrrr(r/Úobjectr0ZdefaultTestLoaderr¡rŸr7r5r¢r£rrrrÚs8 '