|
4 | 4 | import re
|
5 | 5 | import sys
|
6 | 6 |
|
7 |
| -from pycodestyle import BaseReport |
8 |
| -from pycodestyle import Checker |
9 | 7 | from pycodestyle import readlines
|
10 | 8 | from pycodestyle import StandardReport
|
11 |
| -from pycodestyle import StyleGuide |
12 | 9 |
|
13 | 10 | SELFTEST_REGEX = re.compile(r'\b(Okay|[EW]\d{3}):\s(.*)')
|
14 | 11 | ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
|
@@ -87,68 +84,6 @@ def print_results(self):
|
87 | 84 | print("Test failed." if self.total_errors else "Test passed.")
|
88 | 85 |
|
89 | 86 |
|
90 |
| -class InMemoryReport(BaseReport): |
91 |
| - """ |
92 |
| - Collect the results in memory, without printing anything. |
93 |
| - """ |
94 |
| - |
95 |
| - def __init__(self, options): |
96 |
| - super().__init__(options) |
97 |
| - self.in_memory_errors = [] |
98 |
| - |
99 |
| - def error(self, line_number, offset, text, check): |
100 |
| - """ |
101 |
| - Report an error, according to options. |
102 |
| - """ |
103 |
| - code = text[:4] |
104 |
| - self.in_memory_errors.append('{}:{}:{}'.format( |
105 |
| - code, line_number, offset + 1)) |
106 |
| - return super().error( |
107 |
| - line_number, offset, text, check) |
108 |
| - |
109 |
| - |
110 |
| -def selftest(options): |
111 |
| - """ |
112 |
| - Test all check functions with test cases in docstrings. |
113 |
| - """ |
114 |
| - count_failed = count_all = 0 |
115 |
| - report = BaseReport(options) |
116 |
| - counters = report.counters |
117 |
| - checks = options.physical_checks + options.logical_checks |
118 |
| - for name, check, argument_names in checks: |
119 |
| - for line in check.__doc__.splitlines(): |
120 |
| - line = line.lstrip() |
121 |
| - match = SELFTEST_REGEX.match(line) |
122 |
| - if match is None: |
123 |
| - continue |
124 |
| - code, source = match.groups() |
125 |
| - lines = [part.replace(r'\t', '\t') + '\n' |
126 |
| - for part in source.split(r'\n')] |
127 |
| - checker = Checker(lines=lines, options=options, report=report) |
128 |
| - checker.check_all() |
129 |
| - error = None |
130 |
| - if code == 'Okay': |
131 |
| - if len(counters) > len(options.benchmark_keys): # pragma: no cover # noqa: E501 |
132 |
| - codes = [key for key in counters |
133 |
| - if key not in options.benchmark_keys] |
134 |
| - error = "incorrectly found %s" % ', '.join(codes) |
135 |
| - elif not counters.get(code): # pragma: no cover |
136 |
| - error = "failed to find %s" % code |
137 |
| - # Keep showing errors for multiple tests |
138 |
| - for key in set(counters) - set(options.benchmark_keys): |
139 |
| - del counters[key] |
140 |
| - count_all += 1 |
141 |
| - if not error: |
142 |
| - if options.verbose: # pragma: no cover |
143 |
| - print(f"{code}: {source}") |
144 |
| - else: # pragma: no cover |
145 |
| - count_failed += 1 |
146 |
| - print("pycodestyle.py: %s:" % error) |
147 |
| - for line in checker.lines: |
148 |
| - print(line.rstrip()) |
149 |
| - return count_failed, count_all |
150 |
| - |
151 |
| - |
152 | 87 | def init_tests(pep8style):
|
153 | 88 | """
|
154 | 89 | Initialize testing framework.
|
@@ -211,28 +146,6 @@ def run_tests(filename):
|
211 | 146 |
|
212 | 147 |
|
213 | 148 | def run_tests(style):
|
214 |
| - options = style.options |
215 |
| - if options.doctest: |
216 |
| - import doctest |
217 |
| - fail_d, done_d = doctest.testmod(report=False, verbose=options.verbose) |
218 |
| - fail_s, done_s = selftest(options) |
219 |
| - count_failed = fail_s + fail_d |
220 |
| - if not options.quiet: |
221 |
| - count_passed = done_d + done_s - count_failed |
222 |
| - print("%d passed and %d failed." % (count_passed, count_failed)) |
223 |
| - print("Test failed." if count_failed else "Test passed.") |
224 |
| - if count_failed: # pragma: no cover |
225 |
| - sys.exit(1) |
226 |
| - if options.testsuite: |
| 149 | + if style.options.testsuite: |
227 | 150 | init_tests(style)
|
228 | 151 | return style.check_files()
|
229 |
| - |
230 |
| - |
231 |
| -def errors_from_src(src: str) -> list[str]: |
232 |
| - guide = StyleGuide() |
233 |
| - reporter = guide.init_report(InMemoryReport) |
234 |
| - guide.input_file( |
235 |
| - filename='in-memory-test-file.py', |
236 |
| - lines=src.splitlines(True), |
237 |
| - ) |
238 |
| - return reporter.in_memory_errors |
0 commit comments