a dhN@sdZddlZddlZddlZddlZddlZddlZddlmZddl Z ddl m Z ddl mZmZmZmZmZddlmZGdddeZGd d d eZGd d d ZGd ddeZddZddZddZdS)z&Support code for distutils test cases.N)deepcopy)log)DEBUGINFOWARNERRORFATAL) Distributioncs@eZdZfddZfddZddZddZd d ZZS) LoggingSilencercs6tttj|_tjj|_|jtj_g|_ dSN) supersetUpr set_thresholdr thresholdLog_log_old_loglogsself __class__8/opt/imh-python/lib/python3.9/distutils/tests/support.pyr s    zLoggingSilencer.setUpcs$t|j|jtj_tdSr )rrrrrrr tearDownrrrrrs  zLoggingSilencer.tearDowncCsT|tttttfvr"tdt|t|ts>tdt |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-szLoggingSilencer.clear_logs) r __module__ __qualname__r rrr*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 r osgetcwdold_cwdtempdirsrrrrr 7s  zTempdirManager.setUpcs8t|jt|jr4|j}tj |qdSr ) r0chdirr2r rr3poptestsupportrmtree)rZtmpdirrrrr<s    zTempdirManager.tearDowncCst}|j||S)zjCreate a temporary directory that will be cleaned up. Returns the path of the directory. )tempfilemkdtempr3r!)rdrrrr:Es zTempdirManager.mkdtempxxxcCsJt|ttfrtjj|}t|d}z||W|n |0dS)zWWrites a file in the given path. path can be a string or a sequence. wN) rlisttupler0pathjoinopenwriteclose)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. )attrs)r:r0r@rAmkdirr )rZpkg_namekwZtmp_dirZpkg_dirdistrrr create_dist\s   zTempdirManager.create_dist)r<)rG) r r,r-__doc__r rr:rFrLr.rrrrr/1s    r/c@s eZdZdZddZddZdS) DummyCommandzAClass to store options for retrieval via set_undefined_options().cKs"|D]\}}t|||qdSr )itemssetattr)rkwargsrJvalrrr__init__qszDummyCommand.__init__cCsdSr rrrrrensure_finalizeduszDummyCommand.ensure_finalizedN)r r,r-rMrSrTrrrrrNnsrNcs(eZdZfddZfddZZS) EnvironGuardcstt|ttj|_dSr )r rUr rr0environ old_environrrrrr {szEnvironGuard.setUpcsf|jD]"\}}tj||kr |tj|<q ttjD]}||jvrcannot find xxmodule.c (test must run in the python build dir))_get_xxmodule_pathunittestZSkipTestshutilcopy)Z directoryfilenamerrrcopy_xxmodule_cs  rac Csftd}tjtjtdtj|ddtj|dddddg}|D]}tj|rH|SqHdS)Nsrcdirz xxmodule.cZModulesz..) sysconfigget_config_varr0r@rAdirname__file__exists)rbZ candidatesr@rrrr\s   r\cCs~tjdkrtjd|_n`tdrztd}|dur@dg|_n:tj dkrRg|_n(| d\}}}d d | tj D|_dS) 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%r;rrrr(z#fixup_build_ext..) r0namesys executableendswithdebugrcrdZ library_dirsplatform partitionsplitpathsep)cmdZ runsharedrmZequalsr[rrrfixup_build_exts     rw)rMr0rnr^r9r]rcr_rZ test.supportr6Z distutilsrZ distutils.logrrrrrZdistutils.corer objectr r/rNrUrar\rwrrrrs$   !=