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_e271_ignore_redundant(self):
fix_pep8 = autopep8.FixPEP8(filename='',
options=autopep8.parse_args(['']),
contents='x = 1\n')
self.assertEqual(
[],
fix_pep8.fix_e271({'line': 1,
'column': 2}))
def test_fix_e225_avoid_failure(self):
fix_pep8 = autopep8.FixPEP8(filename='',
options=autopep8.parse_args(['']),
contents=' 1\n')
self.assertEqual(
[],
fix_pep8.fix_e225({'line': 1,
'column': 5}))
def test_fixpep8_class_constructor(self):
line = 'print 1\nprint 2\n'
with temporary_file_context(line) as filename:
pep8obj = autopep8.FixPEP8(filename, None)
self.assertEqual(''.join(pep8obj.source), line)
fixed_source = apply_global_fixes(tmp_source,
options,
filename=filename)
passes = 0
long_line_ignore_cache = set()
while hash(fixed_source) not in previous_hashes:
if options.pep8_passes >= 0 and passes > options.pep8_passes:
break
passes += 1
previous_hashes.add(hash(fixed_source))
tmp_source = copy.copy(fixed_source)
fix = FixPEP8(
filename,
options,
contents=tmp_source,
long_line_ignore_cache=long_line_ignore_cache)
fixed_source = fix.fix()
sio = io.StringIO(fixed_source)
return ''.join(normalize_line_endings(sio.readlines(), original_newline))
def supported_fixes():
"""Yield pep8 error codes that autopep8 fixes.
Each item we yield is a tuple of the code followed by its
description.
"""
yield ('E101', docstring_summary(reindent.__doc__))
instance = FixPEP8(filename=None, options=None, contents='')
for attribute in dir(instance):
code = re.match('fix_([ew][0-9][0-9][0-9])', attribute)
if code:
yield (
code.group(1).upper(),
re.sub(r'\s+', ' ',
docstring_summary(getattr(instance, attribute).__doc__))
)
for (code, function) in sorted(global_fixes()):
yield (code.upper() + (4 - len(code)) * ' ',
re.sub(r'\s+', ' ', docstring_summary(function.__doc__)))
for code in sorted(CODE_TO_2TO3):
yield (code.upper() + (4 - len(code)) * ' ',
re.sub(r'\s+', ' ', docstring_summary(fix_2to3.__doc__)))