changeset 595:538e4f975505

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.
author osimons
date Mon, 27 Jul 2009 21:48:24 +0000
parents a4d3998fe0f3
children b1c90136f84a
files bitten/build/pythontools.py bitten/build/tests/pythontools.py
diffstat 2 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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,
--- 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'))
Copyright (C) 2012-2017 Edgewall Software