2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
4
# Partly based on a script from Review Board, MIT license; but modified to
7
from __future__ import print_function
14
CURDIR = os.path.dirname(os.path.abspath(__file__))
17
class TestPyflakesClean(unittest.TestCase):
18
""" ensure that the tree is pyflakes clean """
20
def read_exclusions(self):
23
excpath = os.path.join(CURDIR, "pyflakes.exclude")
24
with open(excpath, "r") as fp:
26
if not line.startswith("#"):
27
exclusions[line.rstrip()] = 1
32
def filter_exclusions(self, contents):
33
exclusions = self.read_exclusions()
35
if line.startswith("#"):
38
line = line.rstrip().split(CURDIR + '/', 1)[1]
39
test_line = re.sub(r":[0-9]+:", r":*:", line, 1)
40
test_line = re.sub(r"line [0-9]+", r"line *", test_line)
42
if test_line not in exclusions:
45
def test_pyflakes_clean(self):
46
# mvo: type -f here to avoid running pyflakes on imported files
47
# that are symlinks to other packages
48
cmd = 'find %s/.. -type f -name "*.py" | xargs pyflakes3' % CURDIR
50
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
51
close_fds=True, shell=True, universal_newlines=True)
52
contents = p.communicate()[0].splitlines()
53
filtered_contents = list(self.filter_exclusions(contents))
54
for line in filtered_contents:
56
self.assertEqual(0, len(filtered_contents))
59
if __name__ == "__main__":
61
logging.basicConfig(level=logging.DEBUG)