[Python-checkins] python/nondist/sandbox/setuptools/setuptools/command test.py, 1.1, 1.2

pje@users.sourceforge.net pje at users.sourceforge.net
Wed Jul 6 03:54:10 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21756/setuptools/command

Modified Files:
	test.py 
Log Message:
Enhanced the ``test`` command so that it doesn't install the package, but
instead builds any C extensions in-place, updates the ``.egg-info``
metadata, adds the source directory to ``sys.path``, and runs the tests
directly on the source.  This avoids an "unmanaged" installation of the
package to ``site-packages`` or elsewhere.  (Also, fix a breaking test of
older dependency support; this should probably be removed altogether, as
long as nobody's using it.)


Index: test.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/test.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test.py	19 Mar 2004 20:53:14 -0000	1.1
+++ test.py	6 Jul 2005 01:54:07 -0000	1.2
@@ -1,4 +1,4 @@
-from distutils.cmd import Command
+from setuptools import Command
 from distutils.errors import DistutilsOptionError
 import sys
 
@@ -40,35 +40,35 @@
 
 
     def run(self):
+        # Ensure metadata is up-to-date
+        self.run_command('egg_info')
 
-        # Install before testing
-        self.run_command('install')
+        # Build extensions in-place
+        self.reinitialize_command('build_ext', inplace=1)
+        self.run_command('build_ext')
 
         if self.test_suite:
             cmd = ' '.join(self.test_args)
-
             if self.dry_run:
                 self.announce('skipping "unittest %s" (dry run)' % cmd)
             else:
                 self.announce('running "unittest %s"' % cmd)
-                import unittest
-                unittest.main(None, None, [unittest.__file__]+self.test_args)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+                self.run_tests()
 
+    def run_tests(self):
+        import unittest, pkg_resources
+        old_path = sys.path[:]
+        ei_cmd = self.get_finalized_command("egg_info")
+        try:
+            # put the egg on sys.path, and require() it
+            sys.path.insert(0, ei_cmd.egg_base)
+            pkg_resources.require(
+                "%s==%s" % (ei_cmd.egg_name, ei_cmd.egg_version)
+            )
+            unittest.main(None, None, [unittest.__file__]+self.test_args)
+        finally:
+            sys.path[:] = old_path
+            # XXX later this might need to save/restore the WorkingSet
 
 
 



More information about the Python-checkins mailing list