[Checkins] SVN: zc.buildout/trunk/ Improved the handling of
temporary directories in tests.
Jim Fulton
jim at zope.com
Tue Jun 27 06:54:29 EDT 2006
Log message for revision 68866:
Improved the handling of temporary directories in tests.
Now the test namespace has a helper for creating temporary directories
that are automatically cleaned up.
Changed:
U zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/tests.py
U zc.buildout/trunk/src/zc/buildout/buildout.txt
U zc.buildout/trunk/src/zc/buildout/easy_install.txt
U zc.buildout/trunk/src/zc/buildout/testing.py
U zc.buildout/trunk/src/zc/buildout/tests.py
-=-
Modified: zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/tests.py
===================================================================
--- zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/tests.py 2006-06-27 10:30:16 UTC (rev 68865)
+++ zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/tests.py 2006-06-27 10:54:28 UTC (rev 68866)
@@ -36,7 +36,6 @@
def tearDown(test):
- shutil.rmtree(test.globs['_sample_eggs_container'])
zc.buildout.testing.buildoutTearDown(test)
zc.buildout.testing.stop_server(test.globs['link_server'])
Modified: zc.buildout/trunk/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.txt 2006-06-27 10:30:16 UTC (rev 68865)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt 2006-06-27 10:54:28 UTC (rev 68866)
@@ -500,8 +500,7 @@
Here is a more elaborate example.
- >>> import tempfile
- >>> extensions = tempfile.mkdtemp()
+ >>> extensions = mkdtemp()
>>> write(sample_buildout, 'buildout.cfg',
... """
@@ -626,7 +625,7 @@
enviornment variable. The '/' is replaced by the operating system file
delimiter.)
- >>> home = tempfile.mkdtemp()
+ >>> home = mkdtemp()
>>> mkdir(home, '.buildout')
>>> write(home, '.buildout', 'default.cfg',
... """
@@ -934,7 +933,7 @@
directory in the directory containing the configuration file. You can
provide alternate locations, and even names for these directories.
- >>> alt = tempfile.mkdtemp('sample-alt')
+ >>> alt = mkdtemp('sample-alt')
>>> write(sample_buildout, 'buildout.cfg',
... """
@@ -972,12 +971,9 @@
>>> ls(alt, 'developbasket')
- recipes.egg-link
- >>> import shutil
- >>> shutil.rmtree(alt)
-
You can also specify an alternate buildout directory:
- >>> alt = tempfile.mkdtemp('sample-alt')
+ >>> alt = mkdtemp('sample-alt')
>>> write(sample_buildout, 'buildout.cfg',
... """
@@ -1007,9 +1003,6 @@
>>> ls(alt, 'develop-eggs')
- recipes.egg-link
- >>> import shutil
- >>> shutil.rmtree(alt)
-
Logging control
---------------
@@ -1150,7 +1143,7 @@
with it's own local copies of zc.buildout and setuptools and with
local buildout scripts. There must be an existing setup.cfg:
- >>> sample_bootstrapped = tempfile.mkdtemp('sample-bootstrapped')
+ >>> sample_bootstrapped = mkdtemp('sample-bootstrapped')
>>> write(sample_bootstrapped, 'setup.cfg',
... '''
... [buildout]
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.txt 2006-06-27 10:30:16 UTC (rev 68865)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.txt 2006-06-27 10:54:28 UTC (rev 68866)
@@ -80,8 +80,7 @@
let's make directory and install the demo egg to it, using the demo:
- >>> import tempfile
- >>> dest = tempfile.mkdtemp('sample-install')
+ >>> dest = mkdtemp('sample-install')
>>> import zc.buildout.easy_install
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
@@ -139,9 +138,7 @@
We can specify an alternate Python executable, and we can specify
that, when we retrieve (or create) an egg, it should be unzipped.
- >>> import shutil
- >>> shutil.rmtree(dest)
- >>> dest = tempfile.mkdtemp('sample-install')
+ >>> dest = mkdtemp('sample-install')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... always_unzip=True, executable= python2_3_executable)
@@ -150,8 +147,7 @@
d demo-0.3-py2.3.egg
d demoneeded-1.1-py2.3.egg
- >>> shutil.rmtree(dest)
- >>> dest = tempfile.mkdtemp('sample-install')
+ >>> dest = mkdtemp('sample-install')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... always_unzip=True, executable=python2_4_executable)
@@ -179,7 +175,7 @@
destination directory for it to place them in:
>>> import tempfile
- >>> bin = tempfile.mkdtemp()
+ >>> bin = mkdtemp()
Now, we'll use the scripts method to generate scripts in this directory
from the demo egg:
@@ -261,9 +257,7 @@
and to provie script names. The argument is a dictionary mapping
original script names to new script names.
- >>> import shutil
- >>> shutil.rmtree(bin)
- >>> bin = tempfile.mkdtemp()
+ >>> bin = mkdtemp()
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo==0.1'], ws, python2_4_executable, bin, dict(demo='run'))
>>> scripts == [os.path.join(bin, 'run')]
Modified: zc.buildout/trunk/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/testing.py 2006-06-27 10:30:16 UTC (rev 68865)
+++ zc.buildout/trunk/src/zc/buildout/testing.py 2006-06-27 10:54:28 UTC (rev 68866)
@@ -63,7 +63,13 @@
# to restore whatever it was after the test.
test.globs['_oldhome'] = os.environ.pop('HOME', None)
- sample = tempfile.mkdtemp('sample-buildout')
+ temporary_directories = []
+ def mkdtemp(*args):
+ d = tempfile.mkdtemp(*args)
+ temporary_directories.append(d)
+ return d
+
+ sample = mkdtemp('sample-buildout')
for name in ('bin', 'eggs', 'develop-eggs', 'parts'):
os.mkdir(os.path.join(sample, name))
@@ -98,10 +104,13 @@
system = system,
get = get,
__original_wd__ = os.getcwd(),
+ __temporary_directories__ = temporary_directories,
+ mkdtemp = mkdtemp,
))
def buildoutTearDown(test):
- shutil.rmtree(test.globs['sample_buildout'])
+ for d in test.globs['__temporary_directories__']:
+ shutil.rmtree(d)
os.chdir(test.globs['__original_wd__'])
if test.globs.get('_oldhome') is not None:
os.environ['HOME'] = test.globs['_oldhome']
@@ -131,11 +140,10 @@
os.chdir(here)
def create_sample_eggs(test, executable=sys.executable):
- if '_sample_eggs_container' in test.globs:
- sample = test.globs['_sample_eggs_container']
+ if 'sample_eggs' in test.globs:
+ sample = os.path.dirname(test.globs['sample_eggs'])
else:
- sample = tempfile.mkdtemp('sample-eggs')
- test.globs['_sample_eggs_container'] = sample
+ sample = test.globs['mkdtemp']('sample-eggs')
test.globs['sample_eggs'] = os.path.join(sample, 'dist')
write(sample, 'README.txt', '')
Modified: zc.buildout/trunk/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/tests.py 2006-06-27 10:30:16 UTC (rev 68865)
+++ zc.buildout/trunk/src/zc/buildout/tests.py 2006-06-27 10:54:28 UTC (rev 68866)
@@ -72,16 +72,9 @@
)
def linkerTearDown(test):
- shutil.rmtree(test.globs['_sample_eggs_container'])
zc.buildout.testing.buildoutTearDown(test)
zc.buildout.testing.stop_server(test.globs['link_server'])
-
-def buildoutTearDown(test):
- shutil.rmtree(test.globs['extensions'])
- shutil.rmtree(test.globs['home'])
- zc.buildout.testing.buildoutTearDown(test)
-
class PythonNormalizing(renormalizing.RENormalizing):
def _transform(self, want, got):
@@ -141,7 +134,7 @@
doctest.DocFileSuite(
'buildout.txt',
setUp=zc.buildout.testing.buildoutSetUp,
- tearDown=buildoutTearDown,
+ tearDown=zc.buildout.testing.buildoutTearDown,
checker=renormalizing.RENormalizing([
(re.compile('__buildout_signature__ = recipes-\S+'),
'__buildout_signature__ = recipes-SSSSSSSSSSS'),
More information about the Checkins
mailing list