# HG changeset patch # User osimons # Date 1248731304 0 # Node ID 538e4f975505a3953332f7fddc9d82dd0709298c # Parent a4d3998fe0f3324d847641a92f01afd4254caf67 0.6dev: Fix for filenames in pylint report that made incorrect absolute pathnames. Filenames should now be properly shortened, and link correctly to source browser from lint report. Also added some tests for lint report filename handling. Closes #418. diff --git a/bitten/build/pythontools.py b/bitten/build/pythontools.py --- a/bitten/build/pythontools.py +++ b/bitten/build/pythontools.py @@ -152,10 +152,11 @@ category = msg_categories.get(msg_type[0]) if len(msg_type) == 1: msg_type = None - filename = os.path.realpath(match.group('file')) - if filename.startswith(ctxt.basedir): + filename = match.group('file') + if os.path.isabs(filename) \ + and filename.startswith(ctxt.basedir): filename = filename[len(ctxt.basedir) + 1:] - filename = filename.replace(os.sep, '/') + filename = filename.replace('\\', '/') lineno = int(match.group('line')) tag = match.group('tag') problems.append(xmlio.Element('problem', category=category, 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 @@ -200,6 +200,54 @@ self.assertEqual('test/module.py', child.attr['file']) +class PyLintTestCase(unittest.TestCase): + + def setUp(self): + self.basedir = os.path.realpath(tempfile.mkdtemp()) + self.ctxt = Context(self.basedir) + self.summary = open(os.path.join(self.basedir, '.lint'), 'w') + + def tearDown(self): + shutil.rmtree(self.basedir) + + def test_summary_with_absolute_path(self): + # One posix + one windows path to normalize + self.summary.write(""" +%s/module/file1.py:42: [C] Missing docstring +%s\\module\\file2.py:42: [C] Missing docstring +""" % (self.ctxt.basedir, self.ctxt.basedir)) + self.summary.close() + pythontools.pylint(self.ctxt, file_=self.summary.name) + type, category, generator, xml = self.ctxt.output.pop() + self.assertEqual(Recipe.REPORT, type) + self.assertEqual('lint', category) + self.assertEqual(2, len(xml.children)) + child = xml.children[0] + self.assertEqual('problem', child.name) + self.assertEqual('module/file1.py', child.attr['file']) + child = xml.children[1] + self.assertEqual('problem', child.name) + self.assertEqual('module/file2.py', child.attr['file']) + + def test_summary_with_relative_path(self): + # One posix + one windows path to normalize + self.summary.write(""" +module/file1.py:42: [C] Missing docstring +module\\file2.py:42: [C] Missing docstring +""") + self.summary.close() + pythontools.pylint(self.ctxt, file_=self.summary.name) + type, category, generator, xml = self.ctxt.output.pop() + self.assertEqual(Recipe.REPORT, type) + self.assertEqual('lint', category) + self.assertEqual(2, len(xml.children)) + child = xml.children[0] + self.assertEqual('problem', child.name) + self.assertEqual('module/file1.py', child.attr['file']) + child = xml.children[1] + self.assertEqual('problem', child.name) + self.assertEqual('module/file2.py', child.attr['file']) + class FigleafTestCase(unittest.TestCase): def setUp(self): @@ -404,6 +452,7 @@ suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(CoverageTestCase, 'test')) suite.addTest(unittest.makeSuite(TraceTestCase, 'test')) + suite.addTest(unittest.makeSuite(PyLintTestCase, 'test')) suite.addTest(unittest.makeSuite(FigleafTestCase, 'test')) suite.addTest(unittest.makeSuite(FilenameNormalizationTestCase, 'test')) suite.addTest(unittest.makeSuite(UnittestTestCase, 'test'))