U .c@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._logcsdd}fdd|jDS)NcSs||Sr r)r#r$rrr_format*sz)LoggingSilencer.get_logs.._formatcs"g|]\}}}|kr||qSrr).0r"r#r$levelsrr ,sz,LoggingSilencer.get_logs..r)rr(r%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 9s  zTempdirManager.setUpcs8t|jt|jr4|j}tj |qdSr ) r1chdirr3r rr4poptestZsupportZrmtree)rZtmpdirrrrr>s    zTempdirManager.tearDowncCst}|j||S)zjCreate a temporary directory that will be cleaned up. Returns the path of the directory. )tempfilemkdtempr4r!)rdrrrr9Gs zTempdirManager.mkdtempxxxcCsBt|ttfrtjj|}t|d}z||W5|XdS)zWWrites a file in the given path. path can be a string or a sequence. wN) rlisttupler1pathjoinopenclosewrite)rr?Zcontentfrrr write_filePs   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)r9r1r?r@mkdirr )rZpkg_namekwZtmp_dirZpkg_dirZdistrrr create_dist^s   zTempdirManager.create_dist)r;)rF) r r-r.__doc__r rr9rErJr/rrrrr03s    r0c@s eZdZdZddZddZdS) DummyCommandzAClass to store options for retrieval via set_undefined_options().cKs"|D]\}}t|||qdSr )itemssetattr)rkwargsrIvalrrr__init__sszDummyCommand.__init__cCsdSr rrrrrensure_finalizedwszDummyCommand.ensure_finalizedN)r r-r.rKrQrRrrrrrLpsrLcs(eZdZfddZfddZZS) EnvironGuardcstt|ttj|_dSr )r rSr rr1environ old_environrrrrr }szEnvironGuard.setUpcsf|jD]"\}}tj||kr |tj|<q ttjD]}||jkrkeysr rSr)rkeyvaluerrrrs   zEnvironGuard.tearDown)r r-r.r rr/rrrrrS{s rScCs(t}|dkrtdt||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|rH|SqHdS)Nsrcdirz xxmodule.cZModulesz..) sysconfigget_config_varr1r?r@dirname__file__exists)r`Z candidatesr?rrrrZs   rZcCs~tjdkrtjd|_n`tdrztd}|dkr@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)sz#fixup_build_ext..) r1namesys executableendswithdebugrarbZ library_dirsplatform partitionsplitpathsep)cmdZ runsharedrjZequalsrYrrrfixup_build_exts     rt)rKr1rkr\r8r[rar]rZ test.supportr7Z distutilsrZ distutils.logrrrrrZdistutils.corer objectr r0rLrSr_rZrtrrrrs$   #=