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_get_diff_text_without_newline(self):
# We ignore the first two lines since it differs on Python 2.6.
self.assertEqual(
"""\
-foo
\\ No newline at end of file
+foo
""",
'\n'.join(autopep8.get_diff_text(['foo'],
['foo\n'],
'').split('\n')[3:]))
def test_get_diff_text(self):
# We ignore the first two lines since it differs on Python 2.6.
self.assertEqual(
"""\
-foo
+bar
""",
'\n'.join(autopep8.get_diff_text(['foo\n'],
['bar\n'],
'').split('\n')[3:]))
formatted_source = format_code(
source,
aggressive=args.aggressive,
apply_config=args.config,
filename=filename,
remove_all_unused_imports=args.remove_all_unused_imports,
remove_unused_variables=args.remove_unused_variables)
if source != formatted_source:
if args.in_place:
with autopep8.open_with_encoding(filename, mode='w',
encoding=encoding) as output_file:
output_file.write(formatted_source)
else:
diff = autopep8.get_diff_text(
io.StringIO(source).readlines(),
io.StringIO(formatted_source).readlines(),
filename)
standard_out.write(''.join(diff))
return True
return False