Mercurial > bitten > bitten-test
changeset 217:44e91849ca43
Handle relative file paths in `trace.py` output. Closes #51.
author | cmlenz |
---|---|
date | Wed, 21 Sep 2005 22:20:11 +0000 |
parents | 581f42b03d2c |
children | b329b4d4d184 |
files | bitten/build/pythontools.py bitten/build/tests/pythontools.py |
diffstat | 2 files changed, 75 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/build/pythontools.py +++ b/bitten/build/pythontools.py @@ -120,26 +120,28 @@ for summary_line in summary_file: match = summary_line_re.search(summary_line) if match: - filename = os.path.realpath(match.group(4)) modname = match.group(3) - cov = int(match.group(2)) - if filename.startswith(ctxt.basedir): - filename = filename[len(ctxt.basedir) + 1:] - if not filename in fileset: - continue - missing_files.remove(filename) - covered_modules.add(modname) - module = xmlio.Element('coverage', name=modname, - file=filename.replace(os.sep, '/'), - percentage=cov) - coverage_path = ctxt.resolve(coverdir, - modname + '.cover') - if not os.path.exists(coverage_path): - log.warning('No coverage file for module %s at %s', - modname, coverage_path) - continue + filename = match.group(4) + if not os.path.isabs(filename): + filename = os.path.normpath(os.path.join(ctxt.basedir, + filename)) + else: + filename = os.path.realpath(filename) + if not filename.startswith(ctxt.basedir): + continue + filename = filename[len(ctxt.basedir) + 1:] + if not filename in fileset: + continue + + missing_files.remove(filename) + covered_modules.add(modname) + module = xmlio.Element('coverage', name=modname, + file=filename.replace(os.sep, '/'), + lines=int(match.group(1)), + percentage=int(match.group(2))) + coverage_path = ctxt.resolve(coverdir, modname + '.cover') + if os.path.exists(coverage_path): coverage_file = open(coverage_path, 'r') - num_lines = 0 lines = [] try: for num, coverage_line in enumerate(coverage_file): @@ -148,16 +150,17 @@ hits = match.group(1) if hits: lines.append(hits) - num_lines += 1 else: - if coverage_line.startswith('>'): - num_lines += 1 lines.append('0') finally: coverage_file.close() - module.attr['lines'] = len(lines) - module.append(xmlio.Element('line_hits')[' '.join(lines)]) - coverage.append(module) + module.append(xmlio.Element('line_hits')[ + ' '.join(lines) + ]) + else: + log.warning('No coverage file for module %s at %s', + modname, coverage_path) + coverage.append(module) for filename in missing_files: modname = os.path.splitext(filename.replace(os.sep, '.'))[0]
--- a/bitten/build/tests/pythontools.py +++ b/bitten/build/tests/pythontools.py @@ -29,6 +29,14 @@ def tearDown(self): shutil.rmtree(self.basedir) + def _create_file(self, *path): + filename = os.path.join(self.basedir, *path) + dirname = os.path.dirname(filename) + os.makedirs(dirname) + fd = file(filename, 'w') + fd.close() + return filename[len(self.basedir) + 1:] + def test_missing_param_summary(self): self.summary.close() self.assertRaises(AssertionError, pythontools.trace, self.ctxt, @@ -49,6 +57,46 @@ self.assertEqual('coverage', category) self.assertEqual(0, len(xml.children)) + def test_summary_with_absolute_path(self): + self.summary.write(""" +lines cov%% module (path) + 60 100%% test.module (%s/test/module.py) +""" % self.ctxt.basedir) + self.summary.close() + self._create_file('test', 'module.py') + pythontools.trace(self.ctxt, summary=self.summary.name, + include='test/*', coverdir=self.coverdir) + type, category, generator, xml = self.ctxt.output.pop() + self.assertEqual(Recipe.REPORT, type) + self.assertEqual('coverage', category) + self.assertEqual(1, len(xml.children)) + child = xml.children[0] + self.assertEqual('coverage', child.name) + self.assertEqual('test.module', child.attr['name']) + self.assertEqual('test/module.py', child.attr['file']) + self.assertEqual(100, child.attr['percentage']) + self.assertEqual(60, child.attr['lines']) + + def test_summary_with_relative_path(self): + self.summary.write(""" +lines cov% module (path) + 60 100% test.module (./test/module.py) +""") + self.summary.close() + self._create_file('test', 'module.py') + pythontools.trace(self.ctxt, summary=self.summary.name, + include='test/*', coverdir=self.coverdir) + type, category, generator, xml = self.ctxt.output.pop() + self.assertEqual(Recipe.REPORT, type) + self.assertEqual('coverage', category) + self.assertEqual(1, len(xml.children)) + child = xml.children[0] + self.assertEqual('coverage', child.name) + self.assertEqual('test.module', child.attr['name']) + self.assertEqual('test/module.py', child.attr['file']) + self.assertEqual(100, child.attr['percentage']) + self.assertEqual(60, child.attr['lines']) + class UnittestTestCase(unittest.TestCase):