B LgI@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZmZmZddlmZGdddeZGd 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|_ dS)N) supersetUpr set_thresholdr thresholdLog_log_old_loglogs)self) __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||S)Nr)r r!rrr_format)sz)LoggingSilencer.get_logs.._formatcs"g|]\}}}|kr||qSrr).0rr r!)levelsrr +sz,LoggingSilencer.get_logs..)r)rr$r"r)r$rget_logs(s zLoggingSilencer.get_logscCs g|_dS)N)r)rrrr clear_logs.szLoggingSilencer.clear_logs) r __module__ __qualname__r rrr&r' __classcell__rr)rrr 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|_dS)N)r r osgetcwdold_cwdtempdirs)r)rrrr 8s  zTempdirManager.setUpcsBt|jtx&|jr<|j}t|tj dkqWdS)N)ntcygwin) r,chdirr.r rr/popshutilZrmtreename)rd)rrrr=s    zTempdirManager.tearDowncCst}|j||S)zjCreate a temporary directory that will be cleaned up. Returns the path of the directory. )tempfilemkdtempr/r)rr6rrrr8Fs zTempdirManager.mkdtempxxxcCsBt|ttfrtjj|}t|d}z||Wd|XdS)zWWrites a file in the given path. path can be a string or a sequence. wN) rlisttupler,pathjoinopenwriteclose)rr=Zcontentfrrr write_fileOs   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)r8r,r=r>mkdirr )rZpkg_namekwZtmp_dirZpkg_dirZdistrrr create_dist]s   zTempdirManager.create_dist)r9)rD) rr(r)__doc__r rr8rCrGr*rr)rrr+2s    r+c@s eZdZdZddZddZdS) DummyCommandzAClass to store options for retrieval via set_undefined_options().cKs&x |D]\}}t|||q WdS)N)itemssetattr)rkwargsrFvalrrr__init__rszDummyCommand.__init__cCsdS)Nr)rrrrensure_finalizedvszDummyCommand.ensure_finalizedN)rr(r)rHrNrOrrrrrIosrIcs(eZdZfddZfddZZS) EnvironGuardcstt|ttj|_dS)N)r rPr rr,environ old_environ)r)rrrr |szEnvironGuard.setUpcsnx0|jD]"\}}tj||kr |tj|<q Wx(ttjD]}||jkrBtj|=qBWtt| dS)N) rRrJr,rQgetr<keysr rPr)rkeyvalue)rrrrs  zEnvironGuard.tearDown)rr(r)r rr*rr)rrrPzs rPcCs(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_pathunittestZSkipTestr4copy)Z directoryfilenamerrrcopy_xxmodule_cs  r[c Csftd}tjtjtdtj|ddtj|dddddg}x|D]}tj|rJ|SqJWdS)Nsrcdirz xxmodule.cZModulesz..) sysconfigget_config_varr,r=r>dirname__file__exists)r\Z candidatesr=rrrrWs   rWcCs~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. r0z_d.exeZPy_ENABLE_SHAREDZ RUNSHAREDN.darwin=cSsg|] }|r|qSrr)r#r6rrrr%sz#fixup_build_ext..) r,r5sys executableendswithdebugr]r^Z library_dirsplatform partitionsplitpathsep)cmdZ runsharedr5ZequalsrVrrrfixup_build_exts     rn)rHr,rer4r7rXr]rYrZ distutilsrZ distutils.logrrrrrZdistutils.corer objectr r+rIrPr[rWrnrrrrs"   #=