1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
From 51daaefdfd68ee805bc5380f68ae88a32ef72a72 Mon Sep 17 00:00:00 2001
From: Jeff Quast <contact@jeffquast.com>
Date: Thu, 22 Mar 2018 17:46:26 -0700
Subject: [PATCH] Bugfix python3 entry point for cmake_pprint (#2)
* Update cmake_pprint.py
* pprint doesn't make a difference
* update flake8 test from rosdep repository
* py2.7 fix
* ignore some rules
---
parse_cmake/cmake_pprint.py | 4 +--
tests/test_code_format.py | 57 ++++++++++++++++++++++++++++++-------
2 files changed, 48 insertions(+), 13 deletions(-)
diff --git a/parse_cmake/cmake_pprint.py b/parse_cmake/cmake_pprint.py
index 18e4e9e..d6865ef 100644
--- a/parse_cmake/cmake_pprint.py
+++ b/parse_cmake/cmake_pprint.py
@@ -18,7 +18,7 @@
import argparse
import sys
-import parsing as cmp
+from .parsing import parse
def main():
@@ -40,7 +40,7 @@ def main():
for (name, file) in files:
with file:
input = file.read()
- tree = cmp.parse(input, path=name)
+ tree = parse(input, path=name)
if args.tree:
# Print out AST
print(repr(tree))
diff --git a/tests/test_code_format.py b/tests/test_code_format.py
index 287e6e1..9ab09e2 100644
--- a/tests/test_code_format.py
+++ b/tests/test_code_format.py
@@ -12,18 +12,53 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import flake8.engine
+from __future__ import print_function
+
import os
+import sys
+
+# flake8 doesn't support Python < 2.7 anymore
+if sys.version_info[0] > 2 or sys.version_info[1] >= 7:
+ from flake8.api.legacy import get_style_guide
+else:
+ get_style_guide = None
def test_flake8():
- """Test source code for pyFlakes and PEP8 conformance"""
- flake8style = flake8.engine.StyleGuide(max_line_length=100)
- report = flake8style.options.report
- report.start()
- this_dir = os.path.dirname(os.path.abspath(__file__))
- flake8style.input_dir(os.path.join(this_dir, '..', 'parse_cmake'))
- report.stop()
- assert report.total_errors == 0, \
- ("Found '{0}' code style errors (and warnings)."
- .format(report.total_errors))
+ if get_style_guide is None:
+ # skip test on Python 2.6 and older
+ return
+
+ style_guide = get_style_guide(
+ exclude=[],
+ ignore=[
+ 'E731', # ignore assign lambda warning
+ 'E226', # ignore whitespace around arithmetic operators
+ 'E305', # ignore whitespace before/after functions rule
+ 'D', # ignore documentation related warnings
+ 'I', # ignore import order related warnings
+ 'N802', # ignore presence of upper case in function names
+ ],
+ max_line_length=100,
+ max_complexity=10,
+ show_source=True,
+ )
+
+ stdout = sys.stdout
+ sys.stdout = sys.stderr
+ # implicitly calls report_errors()
+ report = style_guide.check_files([
+ os.path.dirname(os.path.dirname(__file__)),
+ ])
+ sys.stdout = stdout
+
+ if report.total_errors:
+ # output summary with per-category counts
+ print()
+ report._application.formatter.show_statistics(report._stats)
+ print(
+ 'flake8 reported {report.total_errors} errors'
+ .format_map(locals()), file=sys.stderr)
+
+ assert not report.total_errors, \
+ 'flake8 reported {report.total_errors} errors'.format(**locals())
|