changeset 153:3ab91c56d7bc

* Fix `pythontools` unit tests on windows. * Handle import error when resolving the module in `<python:exec>`
author cmlenz
date Mon, 22 Aug 2005 11:21:18 +0000
parents 56027862f910
children d72d68471c10
files bitten/build/pythontools.py bitten/build/tests/pythontools.py scripts/build.py
diffstat 3 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/build/pythontools.py
+++ b/bitten/build/pythontools.py
@@ -54,11 +54,15 @@
 
     if module:
         # Script specified as module name, need to resolve that to a file
-        mod = __import__(module, globals(), locals(), [])
-        components = module.split('.')
-        for comp in components[1:]:
-            mod = getattr(mod, comp)
-        file_ = mod.__file__
+        try:
+            mod = __import__(module, globals(), locals(), [])
+            components = module.split('.')
+            for comp in components[1:]:
+                mod = getattr(mod, comp)
+            file_ = mod.__file__.replace('\\', '/')
+        except ImportError, e:
+            ctxt.error('Cannot execute Python module %s: %s' % (module, e))
+            return
 
     if args:
         args = file_ + ' ' + args
--- a/bitten/build/tests/pythontools.py
+++ b/bitten/build/tests/pythontools.py
@@ -30,22 +30,23 @@
 class TraceTestCase(unittest.TestCase):
 
     def setUp(self):
-        self.temp_dir = os.path.realpath(tempfile.gettempdir())
-        self.ctxt = Context(self.temp_dir)
-        self.summary = open(os.path.join(self.temp_dir, 'test-coverage.txt'),
+        self.basedir = os.path.realpath(tempfile.mkdtemp())
+        self.ctxt = Context(self.basedir)
+        self.summary = open(os.path.join(self.basedir, 'test-coverage.txt'),
                             'w')
-        self.coverdir = os.path.join(self.temp_dir, 'coverage')
+        self.coverdir = os.path.join(self.basedir, 'coverage')
         os.mkdir(self.coverdir)
 
     def tearDown(self):
-        shutil.rmtree(self.coverdir)
-        os.unlink(self.summary.name)
+        shutil.rmtree(self.basedir)
 
     def test_missing_param_summary(self):
+        self.summary.close()
         self.assertRaises(AssertionError, pythontools.trace, self.ctxt,
                           coverdir='coverage')
 
     def test_missing_param_coverdir(self):
+        self.summary.close()
         self.assertRaises(AssertionError, pythontools.trace, self.ctxt,
                           summary='test-coverage.txt')
 
@@ -63,15 +64,16 @@
 class UnittestTestCase(unittest.TestCase):
 
     def setUp(self):
-        self.temp_dir = tempfile.gettempdir()
-        self.ctxt = Context(self.temp_dir)
-        self.results_xml = open(os.path.join(self.temp_dir, 'test-results.xml'),
+        self.basedir = os.path.realpath(tempfile.mkdtemp())
+        self.ctxt = Context(self.basedir)
+        self.results_xml = open(os.path.join(self.basedir, 'test-results.xml'),
                                 'w')
 
     def tearDown(self):
-        os.unlink(os.path.join(self.temp_dir, 'test-results.xml'))
+        shutil.rmtree(self.basedir)
 
     def test_missing_file_param(self):
+        self.results_xml.close()
         self.assertRaises(AssertionError, pythontools.unittest, self.ctxt)
 
     def test_empty_results(self):
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -61,7 +61,7 @@
         for step in recipe:
             if not steps_to_run or step.id in steps_to_run:
                 print
-                print '-->', step.description or step.id
+                print '-->', step.id
                 for type, function, output in step.execute(recipe.ctxt):
                     if type == Recipe.ERROR:
                         log.error('Failure in step "%s": %s', step.id, output)
@@ -76,6 +76,8 @@
     try:
         main()
     except BuildError, e:
+        print
         print>>sys.stderr, 'FAILED: %s' % e
         sys.exit(-1)
+    print
     print 'SUCCESS'
Copyright (C) 2012-2017 Edgewall Software