Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tearDown(self):
sys.argv = self._saved_argv
sys.stdout = self._saved_stdout
sys.stderr = self._saved_stderr
pycodestyle.PROJECT_CONFIG = self._saved_pconfig
pycodestyle.RawConfigParser._read = self._saved_cpread
pycodestyle.stdin_get_value = self._saved_stdin_get_value
def _checker(data):
pycodestyle.stdin_get_value = lambda: data
tree = ast.parse(data)
checker = ImportOrderChecker(None, tree)
checker.options = {}
return checker
def test_linter():
argv = ['--application-import-names=flake8_import_order']
parser = pycodestyle.get_parser('', '')
Linter.add_options(parser)
options, args = parser.parse_args(argv)
Linter.parse_options(options)
data = 'import ast\nimport flake8_import_order\n'
pycodestyle.stdin_get_value = lambda: data
tree = ast.parse(data)
checker = Linter(tree, None)
for lineno, col_offset, msg, instance in checker.run():
assert msg.startswith(
'I201 Missing newline between import groups.',
)
def source(self):
if self._source is None:
if self.filename != 'stdin':
self._source = read_file_using_source_encoding(self.filename)
elif six.PY2: # ✘py33 ✘py34 ✘py35
# On python 2, reading from stdin gives you bytes, which must
# be decoded.
self._source = decode_string_using_source_encoding(
pycodestyle.stdin_get_value())
else: # ✘py27
# On python 3, reading from stdin gives you text.
self._source = pycodestyle.stdin_get_value()
return self._source
def _process_file(filename):
if filename == 'stdin':
code = pycodestyle.stdin_get_value()
else:
with open(filename, 'rb') as f:
code = f.read().decode('utf-8')
return _process_code(code)
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))
def source(self):
if self._source is None:
if self.filename != 'stdin':
self._source = read_file_using_source_encoding(self.filename)
elif six.PY2: # ✘py33 ✘py34 ✘py35
# On python 2, reading from stdin gives you bytes, which must
# be decoded.
self._source = decode_string_using_source_encoding(
pycodestyle.stdin_get_value())
else: # ✘py27
# On python 3, reading from stdin gives you text.
self._source = pycodestyle.stdin_get_value()
return self._source
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 self.tree is None:
self.tree = ast.parse(''.join(self.lines))