Merge lp:~allenap/maas/lint-checks-in-test-suite into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Rejected
Rejected by: MAAS Lander
Proposed branch: lp:~allenap/maas/lint-checks-in-test-suite
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 93 lines (+78/-0)
2 files modified
required-packages/dev (+2/-0)
src/maastesting/tests/test_lint.py (+76/-0)
To merge this branch: bzr merge lp:~allenap/maas/lint-checks-in-test-suite
Reviewer Review Type Date Requested Status
MAAS Maintainers Pending
Review via email: mp+121022@code.launchpad.net

Commit message

Run pyflakes and pep8 checks as part of the test suite.

To post a comment you must log in.
918. By Gavin Panella

Require the pep8 and pyflakes packages.

Revision history for this message
Gavin Panella (allenap) wrote :

We're using flake8 in Makefile, and pep8+pyflakes here. Would probably be better to settle on one.

Revision history for this message
MAAS Lander (maas-lander) wrote :

Transitioned to Git.

lp:maas has now moved from Bzr to Git.
Please propose your branches with Launchpad using Git.

git clone https://git.launchpad.net/maas

Unmerged revisions

918. By Gavin Panella

Require the pep8 and pyflakes packages.

917. By Gavin Panella

Do Python lint checks as part of the test suite.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'required-packages/dev'
2--- required-packages/dev 2012-07-30 15:52:46 +0000
3+++ required-packages/dev 2012-08-23 16:01:22 +0000
4@@ -2,6 +2,8 @@
5 curl
6 firefox
7 make
8+pep8
9+pyflakes
10 python-lxml
11 python-pip
12 python-pocket-lint
13
14=== added file 'src/maastesting/tests/test_lint.py'
15--- src/maastesting/tests/test_lint.py 1970-01-01 00:00:00 +0000
16+++ src/maastesting/tests/test_lint.py 2012-08-23 16:01:22 +0000
17@@ -0,0 +1,76 @@
18+# Copyright 2012 Canonical Ltd. This software is licensed under the
19+# GNU Affero General Public License version 3 (see the file LICENSE).
20+
21+"""Miscellaneous lint checks."""
22+
23+from __future__ import (
24+ absolute_import,
25+ print_function,
26+ unicode_literals,
27+ )
28+
29+__metaclass__ = type
30+__all__ = []
31+
32+from itertools import (
33+ chain,
34+ imap,
35+ repeat,
36+ )
37+from os import walk
38+from os.path import (
39+ dirname,
40+ join,
41+ pardir,
42+ relpath,
43+ )
44+from subprocess import (
45+ PIPE,
46+ Popen,
47+ STDOUT,
48+ )
49+
50+from maastesting.testcase import TestCase
51+
52+
53+root = join(dirname(__file__), pardir, pardir, pardir)
54+
55+
56+# Predicates.
57+p_python = lambda path, filename: filename.endswith(".py")
58+p_not_hidden = lambda path, filename: not filename.startswith(".")
59+p_not_migration = lambda path, filename: not path.endswith("/migrations")
60+
61+
62+def gen_sources(root, combinator, *predicates):
63+ for dirpath, dirnames, filenames in walk(root):
64+ for filename in filenames:
65+ if combinator(p(dirpath, filename) for p in predicates):
66+ yield join(dirpath, filename)
67+
68+
69+class TestPythonLint(TestCase):
70+ """Check for lint in Python source files."""
71+
72+ @property
73+ def sources(self):
74+ return chain(
75+ [join(root, "setup.py")],
76+ gen_sources(
77+ join(root, "src"), all, p_python, p_not_hidden,
78+ p_not_migration),
79+ gen_sources(
80+ join(root, "templates"), all, p_python, p_not_hidden))
81+
82+ def execute(self, *command):
83+ sources = imap(relpath, self.sources, repeat(root))
84+ command = tuple(chain(command, sources))
85+ process = Popen(command, stdout=PIPE, stderr=STDOUT, cwd=root)
86+ output, ignored = process.communicate()
87+ self.assertEqual(0, process.wait(), output)
88+
89+ def test_pyflakes(self):
90+ self.execute("pyflakes")
91+
92+ def test_pep8(self):
93+ self.execute("pep8", "--repeat", "--")