o =?hZ@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZmZmZmZddlmZGdd d eZGd d d eZGd d d ZGdddeZddZddZddZdS)z&Support code for distutils test cases.N)deepcopy) os_helper)log)DEBUGINFOWARNERRORFATAL) Distributioncs@eZdZfddZfddZddZddZd d ZZS) LoggingSilencercs6tttj|_tjj|_|jtj_g|_ dSN) supersetUpr set_thresholdr thresholdLog_log_old_loglogsself __class__>/opt/alt/python310/lib64/python3.10/distutils/tests/support.pyrs    zLoggingSilencer.setUpcs$t|j|jtj_tdSr )rrrrrrr tearDownrrrrrs  zLoggingSilencer.tearDowncCsT|tttttfvrtdt|t|tstdt |j |j |||fdS)Nz%s wrong log levelzmsg should be str, not '%.200s') rrrrr ValueErrorstr isinstance TypeErrortype__name__rappend)rlevelmsgargsrrrr!s zLoggingSilencer._logcsfdd|jDS)Ncs"g|] \}}}|vr||qSrr).0r#r$r%levelsrr *sz,LoggingSilencer.get_logs..r)rr(rr'rget_logs)s zLoggingSilencer.get_logscCs g|_dSr r*rrrr clear_logs-s zLoggingSilencer.clear_logs) r! __module__ __qualname__rrrr+r, __classcell__rrrrr s   r csHeZdZdZfddZfddZddZdd d Zdd d ZZ S)TempdirManagerz}Mix-in class that handles temporary directories for test cases. This is intended to be used with unittest.TestCase. cstt|_g|_dSr )r rosgetcwdold_cwdtempdirsrrrrr7s   zTempdirManager.setUpcs>t|jt|jr|j}t||jsdSdSr ) r1chdirr3r rr4poprZrmtree)rZtmpdirrrrr<s    zTempdirManager.tearDowncCst}|j||S)zjCreate a temporary directory that will be cleaned up. Returns the path of the directory. )tempfilemkdtempr4r")rdrrrr8Es zTempdirManager.mkdtempxxxcCsHt|ttfr tjj|}t|d}z ||W|dS|w)zWWrites a file in the given path. path can be a string or a sequence. wN) rlisttupler1pathjoinopenwriteclose)rr>Zcontentfrrr write_fileNs    zTempdirManager.write_filefoocKs2|}tj||}t|t|d}||fS)aWill generate a test environment. This function creates: - a Distribution instance using keywords - a temporary directory with a package structure It returns the package directory and the distribution instance. )Zattrs)r8r1r>r?mkdirr )rZpkg_namekwZtmp_dirZpkg_dirZdistrrr create_dist\s    zTempdirManager.create_dist)r:)rE) r!r-r.__doc__rrr8rDrHr/rrrrr01s   r0c@s eZdZdZddZddZdS) DummyCommandzAClass to store options for retrieval via set_undefined_options().cKs"|D] \}}t|||qdSr )itemssetattr)rkwargsrGvalrrr__init__qszDummyCommand.__init__cCsdSr rrrrrensure_finalizeduszDummyCommand.ensure_finalizedN)r!r-r.rIrOrPrrrrrJns rJcs(eZdZfddZfddZZS) EnvironGuardcstt|ttj|_dSr )r rQrrr1environ old_environrrrrr{szEnvironGuard.setUpcsf|jD]\}}tj||kr|tj|<qttjD] }||jvr)tj|=qtt| dSr ) rSrKr1rRgetr=keysr rQr)rkeyvaluerrrrs  zEnvironGuard.tearDown)r!r-r.rrr/rrrrrQys rQcCs(t}|dur tdt||dS)akHelper for tests that need the xxmodule.c source file. Example use: def test_compile(self): copy_xxmodule_c(self.tmpdir) self.assertIn('xxmodule.c', os.listdir(self.tmpdir)) If the source file can be found, it will be copied to *directory*. If not, the test will be skipped. Errors during copy are not caught. Nz>cannot find xxmodule.c (test must run in the python build dir))_get_xxmodule_pathunittestZSkipTestshutilcopy)Z directoryfilenamerrrcopy_xxmodule_cs  r]c Csftd}tjtjtdtj|ddtj|dddddg}|D] }tj|r0|Sq$dS)Nsrcdirz xxmodule.cZModulesz..) sysconfigget_config_varr1r>r?dirname__file__exists)r^Z candidatesr>rrrrXs  rXcCstjdkrtjd|_dStdrBtd}|dur"dg|_dStj dkr,g|_dS| d\}}}d d | tj D|_dSdS) aFunction needed to make build_ext tests pass. When Python was built with --enable-shared on Unix, -L. is not enough to find libpython.so, because regrtest runs in a tempdir, not in the source directory where the .so lives. When Python was built with in debug mode on Windows, build_ext commands need their debug attribute set, and it is not done automatically for some reason. This function handles both of these things. Example use: cmd = build_ext(dist) support.fixup_build_ext(cmd) cmd.ensure_finalized() Unlike most other Unix platforms, Mac OS X embeds absolute paths to shared libraries into executables, so the fixup is not needed there. ntz_d.exeZPy_ENABLE_SHAREDZ RUNSHAREDN.darwin=cSsg|]}|r|qSrr)r&r9rrrr)sz#fixup_build_ext..) r1namesys executableendswithdebugr_r`Z library_dirsplatform partitionsplitpathsep)cmdZ runsharedrhZequalsrWrrrfixup_build_exts      rr)rIr1rirZr7rYr_r[rZ test.supportrZ distutilsrZ distutils.logrrrrr Zdistutils.corer objectr r0rJrQr]rXrrrrrrs&    !=