gc*dZddlZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z m Z ddlmZddlmZddlmZmZmZdd lmZmZdd lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#dd l$m%Z%m&Z&m'Z'dd lm(Z(m)Z)ddl*Z*ejVe,Z-ej\j^Z0ej\jbZ2ej\jfZ4ej\jjZ6ej\jnZ8d dgZ9Gdd ejtZ:e:Z;y)z Test Loader ----------- nose's test loader implements the same basic functionality as its superclass, unittest.TestLoader, but extends it by more liberal interpretations of what may be a test and how a test may be named. N) isfunction)unbound_methodismethod)FunctionTestCaseMethodTestCase)Failure)Config)Importeradd_path remove_path)defaultSelector TestAddress) func_lineno getpackageisclass isgenerator ispackageregex_last_key resolve_nametransplant_functransplant_class test_address)ContextSuiteFactory ContextList LazySuite) sort_list cmp_to_key TestLoaderdefaultTestLoaderceZdZdZdZdZdZdZdZ ddZ dZ dZ dZ dZ dZd Zd Zdd Zdd Zdd ZfdZdZddZddZdZdZxZS)raATest loader that extends unittest.TestLoader to: * Load tests from test-like functions and classes that are not unittest.TestCase subclasses * Find and load test modules in a directory * Support tests that are generators * Support easy extensions of or changes to that behavior through plugins Nc| t}| t|}| |j}| t|}nt |r||}||_||_tt||_||_ |jr t||t||_ tg|_t j"j%|y)aInitialize a test loader. Parameters (all optional): * config: provide a `nose.config.Config`_ or other config class instance; if not provided a `nose.config.Config`_ with default values is used. * importer: provide an importer instance that implements `importFromPath`. If not provided, a `nose.importer.Importer`_ is used. * workingDir: the directory to which file and module names are relative. If not provided, assumed to be the current working directory. * selector: a selector class or instance. If a class is provided, it will be instantiated with one argument, the current config. If not provided, a `nose.selector.Selector`_ is used. N)config)r r workingDirr rr"importer op_normpath op_abspathselectoraddPathsr r suiteClassset _visitedPathsunittestr__init__)selfr"r$r#r's :/opt/hc_python/lib/python3.12/site-packages/nose/loader.pyr-zTestLoader.__init__<s( >XF  v.H  **J  &v.H X 'H   %j&<=  ?? Z (-V< W$$T*cF|jjr tjj ||S||j fd}t t|t|}|st|drdg}|jrt|t|j|S)z_Override to select with selector, unless config.getTestCaseNamesCompat is True ct||d}t|r t||}n t|sy|j |SNFgetattrrrr wantMethodattrclsselitems r/wantedz+TestLoader.getTestCaseNames..wantedm=3d+D$%c40d^>>$' 'r0runTest) r"getTestCaseNamesCompatr,rgetTestCaseNamesr'listfilterdirhasattrsortTestMethodsUsingrr)r. testCaseClassr<casess r/r@zTestLoader.getTestCaseNamesfs ;; - -&&77mL L*  (VFC $678 :KE  $ $ eZ(A(AB C r0c$|y||jvSr3)r+r.paths r/ _haveVisitedzTestLoader._haveVisited~s <t))))r0c@||jj|yyN)r+addrIs r/_addVisitedPathzTestLoader._addVisitedPaths!      " "4 ( r0c#~ Ktjd|jj}|j |jj rt |j}tj|}t|tjj|D]P}|jdrtt|| t }d}|rd}j j# }n:t% }|r-|jdrwj j' }t) } |sj+ rj- |r\|j/|j1drj3 dnj5 |j7!| rj3 d:j9 fdSg} |j;|D]} | j=|  | rj9| jj rD] } tI| |jK|y #t>t@f$rj9tCtEjFgYyxYww) zLoad tests from the directory at path. This is a generator -- each suite of tests from a module or other file is yielded and is expected to be executed before the next file is examined. zload from dir %s.F_z.pyT discoveredc&jSrMloadTestsFromDir) entry_pathr.sr/z-TestLoader.loadTestsFromDir..s 5 5j Ar0N)&logdebugr"pluginsbeforeDirectoryr(r oslistdirrr testMatch startswithr&op_join op_isfiler'wantFileop_isdir wantDirectoryrrKrO beforeContextendswithloadTestsFromNameloadTestsFromFile afterContextr)rWappendKeyboardInterrupt SystemExitrsysexc_infor afterDirectory)r.rJr\ paths_addedentriesentryis_filer<is_dir is_packageteststestprXs` @r/rWzTestLoader.loadTestsFromDirse $d+++%%% ;;  "45K**T"'>$++*?*?@AE$#GD%$89J +GF// ;!*-'', !]]88DF":.Jd// ;$$Z0))+~~e,"44&4599#44Z@@((*00"t155//ACCWZ,,T2D LL 3 >ooe,, ;;   !n!t$":.   >//7CLLN#;"<= =s+E J=J= C J=,I;:J=;=J:8J=c tjd| |jjj |Dcgc]}|}}|r#|Dcgc]}|s| }}|j |St |djtd|zcc}wcc}w#ttf$rtj}|j t|d|d|d|ddfgcYSxYw) zLoad tests from a non-module file. Default is to raise a ValueError; plugins may implement `loadTestsFromFile` to provide a list of tests loaded from the file. zLoad from non-module file %srz!Unable to load tests from file %srNaddress)rZr[r"r\rjr)openclose ValueErrorrmrnrorpr)r.filenameryrx_fexcs r/rjzTestLoader.loadTestsFromFiles 0(; ;[[((::8DFD#TD F',2ere2u--Xs#))+ !D#+",--F 3":.   ;,,.C??QQQ"*D$!79:; ;s/'B! BB!BBB!/2B!!AC3c@|ffd }j|dS)zLazy-load tests from a generator function. The generator function may yield either: * a callable, or * a function name resolvable within the same module c 3JK |D]L}j|\}}t|tjs t ||}t |||Ny#t $rtj}t|d|d|dtYyxYww)Narg descriptorrr}r~r) parseGeneratedTest isinstance collectionsCallabler5rrmrorprr)gmry test_funcrr generatorr.s r/generatez3TestLoader.loadTestsFromGenerator..generates ?CD%)%<%.generates ?CD%)%<%.Ksajjr0)parent__path__zLoad tests from module path %s?z!path: %s os.path.realpath(%s): %sr)rZr[r' wantModulerCr5r wantClassrlr wantFunctionrrmakeTestr^rJnormcaserealpathr"traverseNamespaceraisdirextendrWr\loadTestsFromModuler)r) r.rrJrTrx test_classes test_funcsr;ryt module_paths module_paths r/rzTestLoader.loadTestsFromModule5s1 '0  T]]55f=F vtT24=}}..t4$++D1%$--*D*DT*J%%d+$ l$8 9 j+ .>JZ>WX>WT]]1V]4>WEX vz26 77##BGG$4$4T$:;D'K II7 E II9BGG,,[9gg&&rww'7'7 'DE G --TGG$$((577Az$7GH77==-LL!6!6{!CD(KK'';;FDID LL J{5&ABB5Ys-Kc & tjd||j}jjj ||}|r||St |j}|r|jr |j}j||\}}t|rVt|dd|jk7r.sD$9$9$$?r0zNo such file %szUnresolvable test name %s)&rZr[r)r"r\rirr#callresolverr5rrrrrrrrr beforeImportr$importFromPath afterImportrmrnrorptotuplerrrrerrcrjOSError) r.namerrTsuite plug_testsaddrrobjrpackagerJs ` @r/rizTestLoader.loadTestsFromNameis %tV4[[((::4H $ $4DOO< yyyy,,tV4KFCFL$76??J"30)&&//Bfcll3 II2FC H#w'cU|#[$--V*D)E179::{{D}},!-dkk!: ++88 MM4;;8<%)]]%A%A $ t{{&>  11$))G1LL~ )? AA"4#55d;;$ '1BT1I04 !@&A BB J(Cd(J$(LLN4566[!KK//;; $ t{{<):6D,,.C '#a&#a&#a&26,,.#B"CDDs& AN<=0M=-:N<=.wantedr=r0r) r'rBrCrr5r"r\loadTestsFromTestClassrlr)r)r.r9r<rrGrys r/rz!TestLoader.loadTestsFromTestClasss!dmm ($FCH575TwsD1375 7KK''>>sCD LL D{5#>?? 7s#B$c |j||S#ttf$rtj} t |}n#t$rd}YnxYwt |d|d|d|cYSxYw)Nrr}r~r) _makeTestrmrnrorprr)r.rrrrs r/rzTestLoader.makeTest s A>>#v. .!:.   A,,.C #C($  3q63q63q64@ @s %A2 AA2 AA2cg} t|}|jjj ||D]}|j | |r|j |S t|r(|r&t|tjs t||}t|t j"r|St%|rm|r/|j&|j(k7rt+||j(}t-|t j"r|j/|S|j1|St3|rb| |j4}t-|t j"r||j(St7|r|j9||St;|St|rY|r/|j&|j(k7rt=||j(}t7|r|j?||StA|SttBd|z|S#t$rd}YxYw#ttf$rtj}t|d|d|d|cYSxYw)zVGiven a test object and its parent, return a test case or test suite. Nrr}r~rzCan't make a test from %s)"rrmr"r\rrlr)rnrorprrrtypes ModuleTyperr,TestCaserrrr issubclassrrrrrrrrrrr)r.rrrrryrs r/rzTestLoader._makeTests  $D KK''00f=D   d #> Az22 c?vjAQAQ.R!-C c8,, -J S\#..FOO;&sFOO<#x00111#6622377 c]~&("3"34cll++s#<?Cs{r0ct|ts|t}}||fSt|dk(r|dt}}||fSt|dkDsJ|d|dd}}||fS)zGiven the yield value of a test generator, return a func and args. This is used in the two loadTestsFromGenerator* methods. r}rN)rtuplelen)r.ryrrs r/rzTestLoader.parseGeneratedTest_s| $&"EGsI #~ Y!^"1guwsI#~t9q= ="1gtABxsI#~r0)NNNNr3rM)rr __qualname____doc__r"r$r#r'r)r-r@rKrOrWrjrrrrirrrrrrr __classcell__)rs@r/rr-sFHJHJ>B(+T0*)K%Z;8M,*MX2Chj6X K&"@* A9)v  r0)rs  36 996###CB0g!gg WW__ '',, 77== GGNN  , -$$Br0