samba.tests.source: Check for trailing whitespace in Python files.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 27 Sep 2012 16:30:26 +0000 (09:30 -0700)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 27 Sep 2012 16:45:12 +0000 (18:45 +0200)
source4/scripting/python/samba/tests/source.py

index 0876b043d0cce5c573d20ed902947c3e507c7f12..2612ae68cf5b4a7aac885a6ea29b625a75d078b2 100644 (file)
@@ -183,6 +183,16 @@ class TestSource(TestCase):
             self.fail(self._format_message(illegal_newlines,
                 'Non-unix newlines were found in the following source files:'))
 
+    def test_trailing_whitespace(self):
+        """Check that there is not trailing whitespace in Python files."""
+        trailing_whitespace = {}
+        for fname, line_no, line in self._iter_source_files_lines():
+            if line.rstrip("\n").endswith(" "):
+                self._push_file(trailing_whitespace, fname, line_no)
+        if trailing_whitespace:
+            self.fail(self._format_message(trailing_whitespace,
+                'Trailing whitespace was found in the following source files.'))
+
     def test_shebang_lines(self):
         """Check that files with shebang lines and only those are executable."""
         files_with_shebang = {}
@@ -246,4 +256,9 @@ class TestSource(TestCase):
             checker.report_error = report_error
             checker.check_all()
         if len(pep8_errors) > 0:
-            self.fail('there were %d pep8 errors' % len(pep8_errors))
+            d = {}
+            for (fname, line_no, offset, text, check) in pep8_errors:
+                d.setdefault(fname, []).append(line_no - 1)
+            self.fail(self._format_message(d,
+                'There were %d PEP8 errors:' % len(pep8_errors)))
+