Commit aab38b1a authored by Jim Fulton's avatar Jim Fulton

Added missing tests for the buildout module.

parent 2e7d2316
...@@ -44,7 +44,6 @@ class Options(dict): ...@@ -44,7 +44,6 @@ class Options(dict):
try: try:
return super(Options, self).__getitem__(option) return super(Options, self).__getitem__(option)
except KeyError: except KeyError:
# XXX need test
raise MissingOption("Missing option", self.section, option) raise MissingOption("Missing option", self.section, option)
def copy(self): def copy(self):
...@@ -69,8 +68,6 @@ class Buildout(dict): ...@@ -69,8 +68,6 @@ class Buildout(dict):
links = options.get('find_links', '') links = options.get('find_links', '')
self._links = links and links.split() or () self._links = links and links.split() or ()
# XXX need tests for alternate directory locations
for name in ('bin', 'parts', 'eggs'): for name in ('bin', 'parts', 'eggs'):
d = self.buildout_path(options[name+'_directory']) d = self.buildout_path(options[name+'_directory'])
setattr(self, name, d) setattr(self, name, d)
...@@ -103,8 +100,6 @@ class Buildout(dict): ...@@ -103,8 +100,6 @@ class Buildout(dict):
options[option] = value options[option] = value
converted[(section, option)] = value converted[(section, option)] = value
# XXX need various error tests
return data return data
def _dosubs(self, section, option, value, data, converted, seen): def _dosubs(self, section, option, value, data, converted, seen):
...@@ -135,7 +130,7 @@ class Buildout(dict): ...@@ -135,7 +130,7 @@ class Buildout(dict):
if v is None: if v is None:
raise KeyError("Referenced option does not exist", *s) raise KeyError("Referenced option does not exist", *s)
if '$' in v: if '$' in v:
v = _dosubs(s[0], s[1], v, data, converted, seen) v = self._dosubs(s[0], s[1], v, data, converted, seen)
options[s[1]] = v options[s[1]] = v
converted[s] = v converted[s] = v
subs.append(v) subs.append(v)
......
...@@ -202,8 +202,7 @@ buildout: ...@@ -202,8 +202,7 @@ buildout:
>>> import os >>> import os
>>> os.chdir(sample_buildout) >>> os.chdir(sample_buildout)
>>> runscript = os.path.join(sample_buildout, 'bin', 'buildout') >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print system(runscript),
Creating directory mystuff Creating directory mystuff
We see that the recipe created the directory, as expected: We see that the recipe created the directory, as expected:
...@@ -247,7 +246,7 @@ we'll see that the directory gets removed and recreated: ...@@ -247,7 +246,7 @@ we'll see that the directory gets removed and recreated:
... path = mydata ... path = mydata
... """) ... """)
>>> print system(runscript), >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
Creating directory mydata Creating directory mydata
>>> ls(sample_buildout) >>> ls(sample_buildout)
...@@ -339,7 +338,7 @@ option name joined by a colon. ...@@ -339,7 +338,7 @@ option name joined by a colon.
Now, if we run the buildout, we'll see the options with the values Now, if we run the buildout, we'll see the options with the values
substituted. substituted.
>>> print system(runscript), >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
Creating directory mydata Creating directory mydata
base var base var
file1 mydata/file file1 mydata/file
...@@ -353,7 +352,7 @@ The buildout system didn't know if this module could effect the mkdir ...@@ -353,7 +352,7 @@ The buildout system didn't know if this module could effect the mkdir
recipe, so it assumed it could and reinstalled mydata. If we rerun recipe, so it assumed it could and reinstalled mydata. If we rerun
the buildout: the buildout:
>>> print system(runscript), >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
base var base var
file1 mydata/file file1 mydata/file
file2 mydata/file.out file2 mydata/file.out
...@@ -361,3 +360,37 @@ the buildout: ...@@ -361,3 +360,37 @@ the buildout:
recipe recipes:debug recipe recipes:debug
We can see that mydata was not recreated. We can see that mydata was not recreated.
Alternate directory locations
-----------------------------
The buildout normally puts the bin, eggs, and parts directories in the
directory it is run from. You can provide alternate locations, and
even names for these directories.
>>> import tempfile
>>> alt = tempfile.mkdtemp()
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... develop = recipes
... parts =
... eggs_directory = %(alt)s/basket
... bin_directory = %(alt)s/scripts
... parts_directory = %(alt)s/work
... """ % dict(alt=alt))
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> ls(alt)
d basket
d scripts
d work
>>> ls(alt, 'basket')
- recipes.egg-link
>>> import shutil
>>> shutil.rmtree(alt)
...@@ -21,6 +21,50 @@ from zope.testing import doctest, renormalizing ...@@ -21,6 +21,50 @@ from zope.testing import doctest, renormalizing
from zc.buildout.testing import buildoutSetUp, buildoutTearDown from zc.buildout.testing import buildoutSetUp, buildoutTearDown
def buildout_error_handling():
r'''Buildout error handling
Asking for a section that doesn't exist, yields a key error:
>>> import os
>>> os.chdir(sample_buildout)
>>> import zc.buildout.buildout
>>> buildout = zc.buildout.buildout.Buildout()
>>> buildout['eek']
Traceback (most recent call last):
...
KeyError: 'eek'
Asking for an option that doesn't exist, a MissingOption error is raised:
>>> buildout['buildout']['eek']
Traceback (most recent call last):
...
MissingOption: ('Missing option', 'buildout', 'eek')
It is an error to create a variable-reference cycle:
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... develop = recipes
... parts = data_dir debug
... x = ${buildout:y}
... y = ${buildout:z}
... z = ${buildout:x}
... """)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
Traceback (most recent call last):
...
ValueError: ('Circular references',
[('buildout', 'y'), ('buildout', 'z'), ('buildout', 'x')],
('buildout', 'y'))
'''
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
#doctest.DocTestSuite(), #doctest.DocTestSuite(),
...@@ -32,6 +76,8 @@ def test_suite(): ...@@ -32,6 +76,8 @@ def test_suite():
'__buildout_signature__ = recipes-SSSSSSSSSSS'), '__buildout_signature__ = recipes-SSSSSSSSSSS'),
]) ])
), ),
doctest.DocTestSuite(
setUp=buildoutSetUp, tearDown=buildoutTearDown),
)) ))
if __name__ == '__main__': if __name__ == '__main__':
......
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