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_is_python_file(self):
self.assertTrue(autopep8.is_python_file(
os.path.join(ROOT_DIR, 'autopep8.py')))
with temporary_file_context('#!/usr/bin/env python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python3') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/pythonic') as filename:
self.assertFalse(autopep8.is_python_file(filename))
with temporary_file_context('###!/usr/bin/python') as filename:
self.assertFalse(autopep8.is_python_file(filename))
def test_is_python_file(self):
self.assertTrue(autopep8.is_python_file(
os.path.join(ROOT_DIR, 'autopep8.py')))
with temporary_file_context('#!/usr/bin/env python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python3') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/pythonic') as filename:
self.assertFalse(autopep8.is_python_file(filename))
with temporary_file_context('###!/usr/bin/python') as filename:
self.assertFalse(autopep8.is_python_file(filename))
self.assertFalse(autopep8.is_python_file(os.devnull))
self.assertFalse(autopep8.is_python_file('/bin/bash'))
def test_is_python_file(self):
self.assertTrue(autopep8.is_python_file(
os.path.join(ROOT_DIR, 'autopep8.py')))
with temporary_file_context('#!/usr/bin/env python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python3') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/pythonic') as filename:
self.assertFalse(autopep8.is_python_file(filename))
with temporary_file_context('###!/usr/bin/python') as filename:
self.assertFalse(autopep8.is_python_file(filename))
self.assertFalse(autopep8.is_python_file(os.devnull))
self.assertFalse(autopep8.is_python_file('/bin/bash'))
with temporary_file_context('#!/usr/bin/env python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python3') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/pythonic') as filename:
self.assertFalse(autopep8.is_python_file(filename))
with temporary_file_context('###!/usr/bin/python') as filename:
self.assertFalse(autopep8.is_python_file(filename))
self.assertFalse(autopep8.is_python_file(os.devnull))
self.assertFalse(autopep8.is_python_file('/bin/bash'))
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/python3') as filename:
self.assertTrue(autopep8.is_python_file(filename))
with temporary_file_context('#!/usr/bin/pythonic') as filename:
self.assertFalse(autopep8.is_python_file(filename))
with temporary_file_context('###!/usr/bin/python') as filename:
self.assertFalse(autopep8.is_python_file(filename))
self.assertFalse(autopep8.is_python_file(os.devnull))
self.assertFalse(autopep8.is_python_file('/bin/bash'))
'E301', 'E302', 'E303', 'E304', 'E306',
'E401',
'E502',
'W291', 'W292', 'W29',
'W391']
# Must be written as string since it is passed to command
number_of_pep8_passes = '2000'
# in-place, verbose, select only styles which are listed above,
# pep8-passes limit is to avoid infinite loop
autopep8_args = ['-i', '-v', '--select', ','.join(styles_to_be_corrected),
'--pep8-passes', number_of_pep8_passes]
if files is not None:
python_files = []
for filename in files:
if autopep8.is_python_file(filename):
python_files = python_files + [filename]
else:
if verbosity != 'silent':
print filename, 'is not a python file, skipping '
# execute autopep8 only on python files, without being recursive
autopep8_args = autopep8_args + python_files
if not python_files:
print 'No python files to process.'
sys.exit()
if verbosity != 'silent':
print 'Running autopep8 on the files: ', ' '.join(python_files)
else:
# perform recursive search in the given directory
if os.path.isdir(path):
os.chdir(path)
autopep8_args = autopep8_args + ['-r'] + ['.']