a XC?hN@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__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 rr3poptestZsupportZrmtree)rZtmpdirrrrr<s    zTempdirManager.tearDowncCst}|j||S)zjCreate a temporary directory that will be cleaned up. Returns the path of the directory. )tempfilemkdtempr3r!)rdrrrr8Es 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)r8r0r>r?mkdirr )rZpkg_namekwZtmp_dirZpkg_dirZdistrrr create_dist\s   zTempdirManager.create_dist)r:)rE) r r,r-__doc__r rr8rDrIr.rrrrr/1s    r/c@s eZdZdZddZddZdS) DummyCommandzAClass to store options for retrieval via set_undefined_options().cKs"|D]\}}t|||qdSr )itemssetattr)rkwargsrHvalrrr__init__qszDummyCommand.__init__cCsdSr rrrrrensure_finalizeduszDummyCommand.ensure_finalizedN)r r,r-rJrPrQrrrrrKnsrKcs(eZdZfddZfddZZS) EnvironGuardcstt|ttj|_dSr )r rRr 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  r^c Csftd}tjtjtdtj|ddtj|dddddg}|D]}tj|rH|SqHdS)Nsrcdirz xxmodule.cZModulesz..) sysconfigget_config_varr0r>r?dirname__file__exists)r_Z candidatesr>rrrrYs   rYcCs~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%r9rrrr(z#fixup_build_ext..) r0namesys executableendswithdebugr`raZ library_dirsplatform partitionsplitpathsep)cmdZ runsharedrjZequalsrXrrrfixup_build_exts     rt)rJr0rkr[r7rZr`r\rZ test.supportr6Z distutilsrZ distutils.logrrrrrZdistutils.corer objectr r/rKrRr^rYrtrrrrs$   !=