Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_fix_file_with_diff(self):
filename = os.path.join(ROOT_DIR, 'test', 'example.py')
self.assertIn(
'@@',
autopep8.fix_file(
filename=filename,
options=autopep8.parse_args(['--diff', filename])))
def check(expected_filename, input_filename, aggressive):
"""Test and compare output.
Return True on success.
"""
got = autopep8.fix_file(
input_filename,
options=autopep8.parse_args([''] + aggressive * ['--aggressive']))
try:
with autopep8.open_with_encoding(expected_filename) as expected_file:
expected = expected_file.read()
except IOError:
expected = None
if expected == got:
return True
else:
got_filename = expected_filename + '.err'
encoding = autopep8.detect_encoding(input_filename)
with autopep8.open_with_encoding(got_filename,
def test_fix_file(self):
self.assertIn(
'import ',
autopep8.fix_file(
filename=os.path.join(ROOT_DIR, 'test', 'example.py')))
def autopep8_context(line, options=None):
if not options:
options = []
with temporary_file_context(line) as filename:
options = autopep8.parse_args([filename] + list(options))
yield autopep8.fix_file(filename=filename, options=options)
def run_autopep(filename):
cmd_args = ['dummy', '-d']
args = autopep8.parse_args(cmd_args)
args.aggressive = 2
args.in_place = True
args.diff = False
args.max_line_length = 66
autopep8.fix_file(filename, args)
if not any(x in filename for x in import_fixed) or "internal" in filename:
isort.SortImports(filename)
run_autoflake(filename)
if any(x not in args for x in ['-i', '--in-place']):
args.append('-i')
args.append('--ignore=E261,E265,E402,E501')
args.insert(0, 'dummy')
cmd_args = autopep8.parse_args(args)
excludes = ('ext-lib', 'ext-src')
for p in options.plugin.source_dir.walk():
if any(exclude in p for exclude in excludes):
continue
if p.fnmatch('*.py'):
autopep8.fix_file(p, options=cmd_args)