← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/lint-checks-in-test-suite into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/lint-checks-in-test-suite into lp:maas.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~allenap/maas/lint-checks-in-test-suite/+merge/121022
-- 
https://code.launchpad.net/~allenap/maas/lint-checks-in-test-suite/+merge/121022
Your team MAAS Maintainers is requested to review the proposed merge of lp:~allenap/maas/lint-checks-in-test-suite into lp:maas.
=== added file 'src/maastesting/tests/test_lint.py'
--- src/maastesting/tests/test_lint.py	1970-01-01 00:00:00 +0000
+++ src/maastesting/tests/test_lint.py	2012-08-23 15:25:27 +0000
@@ -0,0 +1,76 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Miscellaneous lint checks."""
+
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = []
+
+from itertools import (
+    chain,
+    imap,
+    repeat,
+    )
+from os import walk
+from os.path import (
+    dirname,
+    join,
+    pardir,
+    relpath,
+    )
+from subprocess import (
+    PIPE,
+    Popen,
+    STDOUT,
+    )
+
+from maastesting.testcase import TestCase
+
+
+root = join(dirname(__file__), pardir, pardir, pardir)
+
+
+# Predicates.
+p_python = lambda path, filename: filename.endswith(".py")
+p_not_hidden = lambda path, filename: not filename.startswith(".")
+p_not_migration = lambda path, filename: not path.endswith("/migrations")
+
+
+def gen_sources(root, combinator, *predicates):
+    for dirpath, dirnames, filenames in walk(root):
+        for filename in filenames:
+            if combinator(p(dirpath, filename) for p in predicates):
+                yield join(dirpath, filename)
+
+
+class TestPythonLint(TestCase):
+    """Check for lint in Python source files."""
+
+    @property
+    def sources(self):
+        return chain(
+            [join(root, "setup.py")],
+            gen_sources(
+                join(root, "src"), all, p_python, p_not_hidden,
+                p_not_migration),
+            gen_sources(
+                join(root, "templates"), all, p_python, p_not_hidden))
+
+    def execute(self, *command):
+        sources = imap(relpath, self.sources, repeat(root))
+        command = tuple(chain(command, sources))
+        process = Popen(command, stdout=PIPE, stderr=STDOUT, cwd=root)
+        output, ignored = process.communicate()
+        self.assertEqual(0, process.wait(), output)
+
+    def test_pyflakes(self):
+        self.execute("pyflakes")
+
+    def test_pep8(self):
+        self.execute("pep8", "--repeat", "--")


Follow ups