OLD | NEW |
1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 1 # This file is part of Adblock Plus <https://adblockplus.org/>, |
2 # Copyright (C) 2006-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 Eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
12 # | 12 # |
13 # You should have received a copy of the GNU General Public License | 13 # You should have received a copy of the GNU General Public License |
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
16 from __future__ import print_function | 16 from __future__ import print_function |
17 | 17 |
18 import os | 18 import os |
19 import glob | 19 import glob |
20 import tokenize | 20 import tokenize |
21 import sys | 21 import sys |
22 import re | 22 import re |
23 | 23 import subprocess |
24 try: | |
25 from StringIO import StringIO | |
26 except ImportError: | |
27 from io import StringIO | |
28 | 24 |
29 from setuptools import setup, Command | 25 from setuptools import setup, Command |
30 | 26 |
31 | 27 |
32 class TestCommand(Command): | 28 class TestCommand(Command): |
33 user_options = [] | 29 user_options = [] |
34 | 30 |
35 def _get_expected_errors(self, filename): | 31 def _get_expected_errors(self, filename): |
36 errors = set() | 32 errors = set() |
37 | 33 |
(...skipping 11 matching lines...) Expand all Loading... |
49 | 45 |
50 with open(filename, 'rb') as file: | 46 with open(filename, 'rb') as file: |
51 if sys.version_info[0] >= 3: | 47 if sys.version_info[0] >= 3: |
52 for token in tokenize.tokenize(file.readline): | 48 for token in tokenize.tokenize(file.readline): |
53 tokeneater(*token) | 49 tokeneater(*token) |
54 else: | 50 else: |
55 tokenize.tokenize(file.readline, tokeneater) | 51 tokenize.tokenize(file.readline, tokeneater) |
56 | 52 |
57 return errors | 53 return errors |
58 | 54 |
59 def _get_reported_errors(self, filename, style_guide): | 55 def _get_reported_errors(self, filename): |
60 orig_stdout = sys.stdout | 56 output = subprocess.Popen(['flake8', filename], |
61 sys.stdout = stdout = StringIO() | 57 stdout=subprocess.PIPE).communicate()[0] |
62 | 58 |
63 try: | |
64 style_guide.check_files([filename]) | |
65 finally: | |
66 sys.stdout = orig_stdout | |
67 | |
68 stdout.seek(0) | |
69 errors = set() | 59 errors = set() |
70 | 60 for line in output.decode('utf-8').splitlines(): |
71 for line in stdout: | |
72 _, lineno, colno, error = line.split(':', 3) | 61 _, lineno, colno, error = line.split(':', 3) |
73 errors.add((int(lineno), int(colno), error.split()[0])) | 62 errors.add((int(lineno), int(colno), error.split()[0])) |
74 | 63 |
75 return errors | 64 return errors |
76 | 65 |
77 def initialize_options(self): | 66 def initialize_options(self): |
78 pass | 67 pass |
79 | 68 |
80 def finalize_options(self): | 69 def finalize_options(self): |
81 pass | 70 pass |
82 | 71 |
83 def run(self): | 72 def run(self): |
84 try: | |
85 import flake8.engine as api | |
86 except ImportError: | |
87 import flake8.api.legacy as api | |
88 | |
89 directory = os.path.dirname(__file__) | 73 directory = os.path.dirname(__file__) |
90 filenames = glob.glob(os.path.join(directory, 'tests', '*.py')) | 74 filenames = glob.glob(os.path.join(directory, 'tests', '*.py')) |
91 style_guide = api.get_style_guide() | |
92 failed = False | 75 failed = False |
93 | 76 |
94 for filename in sorted(filenames): | 77 for filename in sorted(filenames): |
95 expected = self._get_expected_errors(filename) | 78 expected = self._get_expected_errors(filename) |
96 reported = self._get_reported_errors(filename, style_guide) | 79 reported = self._get_reported_errors(filename) |
97 failures = expected ^ reported | 80 failures = expected ^ reported |
98 | 81 |
99 if not failures: | 82 if not failures: |
100 print(filename + ': OK') | 83 print(filename + ': OK') |
101 continue | 84 continue |
102 | 85 |
103 for record in sorted(failures): | 86 for record in sorted(failures): |
104 lineno, colno, error = record | 87 lineno, colno, error = record |
105 | 88 |
106 print('{}:{}:{}: '.format(filename, lineno, colno), end='') | 89 print('{}:{}:{}: '.format(filename, lineno, colno), end='') |
(...skipping 15 matching lines...) Expand all Loading... |
122 entry_points={ | 105 entry_points={ |
123 'flake8.extension': [ | 106 'flake8.extension': [ |
124 'eyeo.A = flake8_eyeo:ASTChecker', | 107 'eyeo.A = flake8_eyeo:ASTChecker', |
125 'eyeo.A1 = flake8_eyeo:check_quotes', | 108 'eyeo.A1 = flake8_eyeo:check_quotes', |
126 'eyeo.A111 = flake8_eyeo:check_redundant_parenthesis', | 109 'eyeo.A111 = flake8_eyeo:check_redundant_parenthesis', |
127 'eyeo.A303 = flake8_eyeo:check_non_default_encoding', | 110 'eyeo.A303 = flake8_eyeo:check_non_default_encoding', |
128 ], | 111 ], |
129 }, | 112 }, |
130 cmdclass={'test': TestCommand} | 113 cmdclass={'test': TestCommand} |
131 ) | 114 ) |
OLD | NEW |