[MERGE] Fix installation of bzrlib.benchmarks

Martin Pool mbp at canonical.com
Thu Jun 22 07:54:09 BST 2006


On 21 Jun 2006, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:
> Jelmer Vernooij wrote:
> > Hi,
> > 
> > The attached bundle fixes the installation of bzrlib.benchmarks.
> 
> +1 and merged.  But this has happened often enough that I think we
> should be testing it.

I had a look at this.  It's actually a little hard to test because you
won't see the problem until you actually try to run the benchmarks in
the installed copy.  (More accurately, it's trivial to check that this
specific bug is fixed but harder to check that we have installed
everything the right way.)

Really it would be better to fix the Don'tRepeatYourself problem of
listing all the modules there - we should just get distutils to install
everything under that directory.  I think we can do that; I'll have a
look in a bit.

In the meantime this patch fixes something else that was annoying me:
the test for setup.py fails if you run it from a different working
directory.  This also changes it to test installation too.

=== modified file 'bzrlib/tests/test_setup.py'
--- bzrlib/tests/test_setup.py	2006-05-05 01:15:53 +0000
+++ bzrlib/tests/test_setup.py	2006-06-22 06:50:40 +0000
@@ -14,36 +14,59 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-""" test for setup.py build process """
+"""Tests for setup.py build process
+"""
 
 import os
 import sys
 import subprocess
 import shutil
+import tempfile
 from tempfile import TemporaryFile
 
 from bzrlib.tests import TestCase
 import bzrlib.osutils as osutils
 
-# TODO: ideally run this in a separate directory, so as not to clobber the
-# real build directory
+# XXX: This clobbers the build directory in the real source tree; it'd be nice
+# to avoid that.
+#
+# TODO: Run bzr from the installed copy to see if it works.  Really we need to
+# run something that exercises every module, just starting it may not detect
+# some missing modules.
+#
+# TODO: Check that the version numbers are in sync.  (Or avoid this...)
 
 class TestSetup(TestCase):
 
-    def test_build(self):
+    def test_build_and_install(self):
         """ test cmd `python setup.py build`
         
-        This typically catches new subdirectories which weren't added to setup.py
+        This typically catches new subdirectories which weren't added to
+        setup.py or similar errors.
         """
         self.log('test_build running in %s' % os.getcwd())
+        install_dir = tempfile.mkdtemp()
+        # setup.py must be run from the root source directory, but the tests
+        # are not necessarily invoked from there
+        self.source_dir = os.path.dirname(sys.argv[0])
         try:
-            # run setup.py build as subproces and catch return code
-            out_file = TemporaryFile()
-            err_file = TemporaryFile()
-            p = subprocess.Popen([sys.executable, 'setup.py', 'build'],
-                                 stdout=out_file, stderr=err_file)
-            s = p.communicate()
-            self.assertEqual(0, p.returncode, '`python setup.py build` fails')
+            self.run_setup(['clean'])
+            # build is implied by install
+            ## self.run_setup(['build'])
+            self.run_setup(['install', '--prefix', install_dir])
+            self.run_setup(['clean'])
         finally:
-            if os.path.exists('build'):
-                osutils.rmtree(u'build')
+            osutils.rmtree(install_dir)
+
+    def run_setup(self, args):
+        args = [sys.executable, './setup.py', ] + args
+        self.log('source base directory: %s', self.source_dir)
+        self.log('args: %r', args)
+        p = subprocess.Popen(args,
+                             cwd=self.source_dir,
+                             stdout=self._log_file,
+                             stderr=self._log_file,
+                             )
+        s = p.communicate()
+        self.assertEqual(0, p.returncode,
+                         'invocation of %r failed' % args)

-- 
Martin




More information about the bazaar mailing list