def run_tests(filename): """Run all the tests from a file.""" lines = readlines(filename) + ['#:\n'] line_offset = 0 codes = ['Okay'] testcase = [] count_files = report.counters['files'] for index, line in enumerate(lines): if not line.startswith('#:'): if codes: # Collect the lines of the test case testcase.append(line) continue if codes and index: if 'noeol' in codes: testcase[-1] = testcase[-1].rstrip('\n') codes = [c for c in codes if c not in ('Okay', 'noeol')] # Run the checker runner(filename, testcase, expected=codes, line_offset=line_offset) # output the real line numbers line_offset = index + 1 # configure the expected errors codes = line.split()[1:] # empty the test case buffer del testcase[:] report.counters['files'] = count_files + 1 return report.counters['failed tests']
def run_tests(filename): """Run all the tests from a file.""" lines = readlines(filename) + ["#:\n"] line_offset = 0 codes = ["Okay"] testcase = [] count_files = report.counters["files"] for index, line in enumerate(lines): if not line.startswith("#:"): if codes: # Collect the lines of the test case testcase.append(line) continue if codes and index: codes = [c for c in codes if c != "Okay"] # Run the checker runner(filename, testcase, expected=codes, line_offset=line_offset) # output the real line numbers line_offset = index + 1 # configure the expected errors codes = line.split()[1:] # empty the test case buffer del testcase[:] report.counters["files"] = count_files + 1 return report.counters["failed tests"]
def input_file(self, filename, lines=None, expected=None, line_offset=0): if lines is None: assert line_offset == 0 line_offset = LINES_SKIP lines = pep8.readlines(filename)[LINES_SKIP:] return super(PEP8, self).input_file( filename, lines=lines, expected=expected, line_offset=line_offset)
def load_file(self): if self.filename in ("stdin", "-", None): self.filename = "stdin" self.lines = pep8.stdin_get_value().splitlines(True) else: self.lines = pep8.readlines(self.filename) if not self.tree: self.tree = ast.parse("".join(self.lines))
def skip_file(path): """ Returns True if line with special commit is found in path: # flake8 : noqa """ try: return _flake8_noqa(''.join(readlines(path))) is not None except (OSError, IOError): return True
def __init__(self, tree=None, filename=None, lines=None): self.filename = filename if filename is None: self.filename = 'stdin' self.lines = lines or [] elif filename == '-': self.filename = 'stdin' self.lines = pep8.stdin_get_value().splitlines(True) elif lines is None: try: self.lines = pep8.readlines(filename) except IOError: (exc_type, exc) = sys.exc_info()[:2] self._io_error = '{}: {}'.format(exc_type.__name__, exc) self.lines = [] else: self.lines = lines
def get_file_contents(self): if self.filename in ('stdin', '-', None): return pep8.stdin_get_value().splitlines(True) else: return pep8.readlines(self.filename)
def read_headers(self): import pep8 if self.filename in ('stdin', '-', None): return pep8.stdin_get_value().splitlines(True)[:2] else: return pep8.readlines(self.filename)[:2]