# HG changeset patch # User cmlenz # Date 1124709678 0 # Node ID 3ab91c56d7bc08f0b4422ad5a46d778505cd13b6 # Parent 56027862f910b7cd22cb121fabd19d5c39525c2e * Fix `pythontools` unit tests on windows. * Handle import error when resolving the module in `` diff --git a/bitten/build/pythontools.py b/bitten/build/pythontools.py --- 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 diff --git a/bitten/build/tests/pythontools.py b/bitten/build/tests/pythontools.py --- 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): diff --git a/scripts/build.py b/scripts/build.py --- 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'