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(argv, expected_output=''):
with Replacer() as r:
r.replace('sys.argv', ['x']+argv)
r.replace('picky.main.conda_env_export',
mock_conda_env_export)
with OutputCapture() as output:
rc = main()
output.compare(expected_output)
return rc
def check_if_config_file_is_used(self, method_to_write_config):
(file_path, lines) = self.write_python_file(
'import os\n'
'from sys import path\n',
)
method_to_write_config('lines_between_types=1')
with OutputCapture():
checker = Flake8Isort(None, file_path, lines)
ret = list(checker.run())
self.assertEqual(len(ret), 1)
self.assertEqual(ret[0][0], 2)
self.assertEqual(ret[0][1], 0)
self.assertTrue(ret[0][2].startswith('I003 '))
def test_same(self):
with OutputCapture() as output:
result = diff(sample_env, sample_env)
assert result == 0
output.compare('')
def test_imports_unexpected_blank_line(self):
(file_path, lines) = self.write_python_file(
'from __future__ import division\n'
'\n'
'import threading\n'
'\n'
'from sys import pid\n',
)
with OutputCapture():
checker = Flake8Isort(None, file_path, lines)
ret = list(checker.run())
self.assertEqual(len(ret), 1)
self.assertEqual(ret[0][0], 4)
self.assertEqual(ret[0][1], 0)
self.assertTrue(ret[0][2].startswith('I004 '))
def test_file_skipped_with_comment(self):
# Note: files skipped in this way are not marked as
# "skipped" by isort <= 4.2.15, so we handle them in a
# different code path and test to ensure they also work.
(file_path, lines) = self.write_python_file(
'# isort:skip_file',
)
with OutputCapture():
checker = Flake8Isort(None, file_path, lines)
ret = list(checker.run())
self.assertEqual(ret, [])
def test_with_eof_blank_lines(self):
"""Pass with eof blank line as flake8 will flag them"""
(file_path, lines) = self.write_python_file(
'import os\n'
'from sys import path\n'
'\n'
'\n'
' \n',
)
with OutputCapture():
checker = Flake8Isort(None, file_path, lines)
ret = list(checker.run())
self.assertEqual(ret, [])
def run(self):
if self.filename is not self.stdin_display_name:
file_path = self.filename
else:
file_path = None
with OutputCapture() as buffer:
sort_result = SortImports(
file_path=file_path,
file_contents=''.join(self.lines),
check=True,
show_diff=True,
)
traceback = self._format_isort_output(buffer)
for line_num, message in self.sortimports_linenum_msg(sort_result):
if self.show_traceback:
message += traceback
yield line_num, 0, message, type(self)