Commit a5b288e5 authored by Jim Fulton's avatar Jim Fulton

Improved the handling of temporary directories in tests.

Now the test namespace has a helper for creating temporary directories
that are automatically cleaned up.
parent f3f3bd91
......@@ -36,7 +36,6 @@ def setUp(test):
def tearDown(test):
shutil.rmtree(test.globs['_sample_eggs_container'])
zc.buildout.testing.buildoutTearDown(test)
zc.buildout.testing.stop_server(test.globs['link_server'])
......
......@@ -500,8 +500,7 @@ customization.
Here is a more elaborate example.
>>> import tempfile
>>> extensions = tempfile.mkdtemp()
>>> extensions = mkdtemp()
>>> write(sample_buildout, 'buildout.cfg',
... """
......@@ -626,7 +625,7 @@ reading the configuration file. ($HOME is the value of the HOME
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 @@ The buildout normally puts the bin, eggs, and parts directories in the
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 @@ provide alternate locations, and even names for these directories.
>>> 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 @@ You can also specify an alternate buildout directory:
>>> ls(alt, 'develop-eggs')
- recipes.egg-link
>>> import shutil
>>> shutil.rmtree(alt)
Logging control
---------------
......@@ -1150,7 +1143,7 @@ If zc.buildout is installed, you can use it to create a new buildout
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]
......
......@@ -80,8 +80,7 @@ We have a link server that has a number of eggs:
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 @@ dependencies. We might do this to specify a sprcific version.
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 @@ that, when we retrieve (or create) an egg, it should be unzipped.
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 @@ The scripts method can be used to generate scripts. Let's create a
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 @@ An additional argumnet can be passed to define which scripts to install
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')]
......
......@@ -63,7 +63,13 @@ def buildoutSetUp(test, clear_home=True):
# 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 @@ def buildoutSetUp(test, clear_home=True):
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 @@ def runsetup(d, executable):
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', '')
......
......@@ -72,15 +72,8 @@ def linkerSetUp(test):
)
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):
......@@ -141,7 +134,7 @@ def test_suite():
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'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment