[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/ Added missing tests for the buildout module.

Jim Fulton jim at zope.com
Fri Jun 9 11:44:07 EDT 2006


Log message for revision 68547:
  Added missing tests for the buildout module.
  

Changed:
  U   zc.buildout/trunk/src/zc/buildout/buildout.py
  U   zc.buildout/trunk/src/zc/buildout/buildout.txt
  U   zc.buildout/trunk/src/zc/buildout/tests.py

-=-
Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py	2006-06-09 14:46:58 UTC (rev 68546)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2006-06-09 15:44:07 UTC (rev 68547)
@@ -44,7 +44,6 @@
         try:
             return super(Options, self).__getitem__(option)
         except KeyError:
-            # XXX need test
             raise MissingOption("Missing option", self.section, option)
 
     def copy(self):
@@ -69,8 +68,6 @@
         links = options.get('find_links', '')
         self._links = links and links.split() or ()
 
-        # XXX need tests for alternate directory locations
-
         for name in ('bin', 'parts', 'eggs'):
             d = self.buildout_path(options[name+'_directory'])
             setattr(self, name, d)
@@ -103,8 +100,6 @@
                     options[option] = value
                 converted[(section, option)] = value
 
-        # XXX need various error tests
-
         return data
 
     def _dosubs(self, section, option, value, data, converted, seen):
@@ -135,7 +130,7 @@
                 if v is None:
                     raise KeyError("Referenced option does not exist", *s)
                 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
                 converted[s] = v
             subs.append(v)

Modified: zc.buildout/trunk/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.txt	2006-06-09 14:46:58 UTC (rev 68546)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt	2006-06-09 15:44:07 UTC (rev 68547)
@@ -202,8 +202,7 @@
 
     >>> import os
     >>> os.chdir(sample_buildout)
-    >>> runscript = os.path.join(sample_buildout, 'bin', 'buildout')
-    >>> print system(runscript),
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
     Creating directory mystuff
 
 We see that the recipe created the directory, as expected:
@@ -247,7 +246,7 @@
     ... path = mydata
     ... """)
 
-    >>> print system(runscript),
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
     Creating directory mydata
 
     >>> ls(sample_buildout)
@@ -339,7 +338,7 @@
 Now, if we run the buildout, we'll see the options with the values
 substituted. 
 
-    >>> print system(runscript),
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
     Creating directory mydata
     base var
     file1 mydata/file
@@ -353,7 +352,7 @@
 recipe, so it assumed it could and reinstalled mydata.  If we rerun
 the buildout:
 
-    >>> print system(runscript),
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
     base var
     file1 mydata/file
     file2 mydata/file.out
@@ -361,3 +360,37 @@
     recipe recipes:debug
 
 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)

Modified: zc.buildout/trunk/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/tests.py	2006-06-09 14:46:58 UTC (rev 68546)
+++ zc.buildout/trunk/src/zc/buildout/tests.py	2006-06-09 15:44:07 UTC (rev 68547)
@@ -21,6 +21,50 @@
 
 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():
     return unittest.TestSuite((
         #doctest.DocTestSuite(),
@@ -32,6 +76,8 @@
                 '__buildout_signature__ = recipes-SSSSSSSSSSS'),
                ])
             ),
+        doctest.DocTestSuite(
+            setUp=buildoutSetUp, tearDown=buildoutTearDown),
         ))
 
 if __name__ == '__main__':



More information about the Checkins mailing list