Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_tests(filename):
"""Run all the tests from a file."""
# Skip tests meant for higher versions of python
ver_match = re.search(r'python(\d)(\d)?\.py$', filename)
if ver_match:
test_against_version = tuple(int(val or 0)
for val in ver_match.groups())
if sys.version_info < test_against_version:
return
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
def get_lines(filename):
if filename in ('stdin', '-', None):
return stdin_utils.stdin_get_value().splitlines(True)
else:
return pep8.readlines(filename)
def load_file(self):
"""Loads the file in a way that auto-detects source encoding and deals
with broken terminal encodings for stdin.
Stolen from flake8_import_order because it's good.
"""
if self.filename in ("stdin", "-", None):
self.filename = "stdin"
self.lines = pycodestyle.stdin_get_value().splitlines(True)
else:
self.lines = pycodestyle.readlines(self.filename)
if not self.tree:
self.tree = ast.parse("".join(self.lines))
def _load_source(self):
"""Loads the file in a way that auto-detects source encoding and deals
with broken terminal encodings for stdin.
Stolen from flake8_import_order because it's good.
"""
if self.filename in ("stdin", "-", None):
self.filename = "stdin"
self.lines = stdin_utils.stdin_get_value().splitlines(True)
else:
self.lines = pycodestyle.readlines(self.filename)
if not self.tree:
self.tree = ast.parse("".join(self.lines))
def get_tokens(filename):
if filename == 'stdin':
file_contents = stdin_utils.stdin_get_value().splitlines(True)
else:
file_contents = pycodestyle.readlines(filename)
file_contents_iter = iter(file_contents)
def file_contents_next():
return next(file_contents_iter)
for t in tokenize.generate_tokens(file_contents_next):
yield Token(t)
def load_file(self):
"""
Loads the file in a way that auto-detects source encoding and deals
with broken terminal encodings for stdin.
Stolen from flake8_import_order because it's good.
"""
if self.filename in ("stdin", "-", None):
self.filename = "stdin"
self.lines = pycodestyle.stdin_get_value().splitlines(True)
else:
self.lines = pycodestyle.readlines(self.filename)
if not self.tree:
self.tree = ast.parse("".join(self.lines))
def load_file(self):
if self.filename in ("stdin", "-", None):
self.filename = "stdin"
self.lines = pycodestyle.stdin_get_value().splitlines(True)
else:
self.lines = pycodestyle.readlines(self.filename)
if not self.tree:
self.tree = ast.parse("".join(self.lines))