[Checkins] SVN: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/ Added setupBuildout to the testing environment. Added an uninstall_args

Aaron Lehmann aaron at zope.com
Sat Aug 2 13:13:32 EDT 2008


Log message for revision 89238:
  Added setupBuildout to the testing environment.  Added an uninstall_args
  argument to Buildout.install, to get around a bug where one could not remove
  ALL the parts of a buildout via install.
  
  

Changed:
  U   zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py
  U   zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py
  U   zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt

-=-
Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py	2008-08-02 16:44:29 UTC (rev 89237)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py	2008-08-02 17:13:31 UTC (rev 89238)
@@ -297,7 +297,9 @@
 
     init = bootstrap
 
-    def install(self, install_args):
+    def install(self, install_args, uninstall_args=None):
+        if uninstall_args is None:
+            uninstall_args = []
         __doing__ = 'Installing.'
 
         self._load_extensions()
@@ -345,7 +347,7 @@
         # load and initialize recipes
         [self[part]['recipe'] for part in install_parts]
         if not install_args:
-            install_parts = self._parts
+            install_parts = [p for p in self._parts if p not in uninstall_args]
 
         if self._log_level < logging.DEBUG:
             sections = list(self)

Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py	2008-08-02 16:44:29 UTC (rev 89237)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py	2008-08-02 17:13:31 UTC (rev 89238)
@@ -22,6 +22,7 @@
 
 import zc.buildout.buildout
 import zc.buildout.easy_install
+import logging
 
 from rmtree import rmtree
 
@@ -219,6 +220,52 @@
         register_teardown(lambda: stop_server(url, thread))
         return url
 
+    def setupBuildout(test, *args):
+        args = list(args)
+        cfg = args.pop()
+        filename = args.pop()
+        directory = os.path.join(*args)
+        eggs = os.path.join(os.path.join(directory, 'eggs'))
+        eggs = os.path.join(os.path.join(directory, 'eggs'))
+        path = os.path.join(directory, filename)
+        install_eggs = test.globs.get('eggs', tuple())
+        sample_buildout = test.globs['sample_buildout']
+        rmdir(directory)
+        test.globs['sample_buildout'] = sample_buildout = tmpdir(sample_buildout)
+        write(path, cfg)
+        os.chdir(sample_buildout)
+        buildout = zc.buildout.buildout.Buildout(
+            path,
+            [# trick bootstrap into putting the buildout develop egg
+            # in the eggs dir.
+            ('buildout', 'develop-eggs-directory', 'eggs'),
+            ],
+            user_defaults=False
+            )
+        # Create the develop-eggs dir, which didn't get created the usual
+        # way due to the trick above:
+        os.mkdir('develop-eggs')
+
+        #Raise the log threshold for the bootstrap, because we don't care about
+        #it
+        logger = logging.getLogger('zc.buildout')
+        level = logging.getLogger('zc.buildout').level
+        logging.getLogger('zc.buildout').setLevel(99999)
+        buildout.bootstrap([])
+        logging.getLogger('zc.buildout').setLevel(level)
+
+        #Remove extra log handlers that dump output outside of the test or mess
+        #the test up.
+        logger.removeHandler(logger.handlers[0])
+        if logger.parent:
+            logger.parent.removeHandler(logger.parent.handlers[1])
+
+        #Install the eggs we need.
+        for egg in install_eggs:
+            zc.buildout.testing.install(egg, eggs)
+        return buildout
+
+
     test.globs.update(dict(
         sample_buildout = sample,
         ls = ls,
@@ -236,6 +283,7 @@
         bdist_egg = bdist_egg,
         start_server = start_server,
         buildout = os.path.join(sample, 'bin', 'buildout'),
+        setupBuildout = lambda *args:setupBuildout(test, *args),
         ))
     
     zc.buildout.easy_install.prefer_final(prefer_final)

Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt	2008-08-02 16:44:29 UTC (rev 89237)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt	2008-08-02 17:13:31 UTC (rev 89238)
@@ -129,6 +129,13 @@
     - on Unix, try running python%(version)s or just python to get the
       executable
 
+``setupBuildout(path, buildout)``
+    This function rebuilds the buildout using the buildout in the string
+    buildout, and returns the object.  The object can then be introspected as a
+    mapping or manipulated via buildout.install().  This is useful for testing,
+    because pdb can be used normally, which is prevented when one uses system() to
+    fork a process.
+
 ``zc.buildout.testing.buildoutTearDown(test)``
 ----------------------------------------------
 



More information about the Checkins mailing list