From d96cef92c980c644b8c0fe48033734e095b41460 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 26 Feb 2015 18:23:52 -0800 Subject: [PATCH] Respect autopep8 config. Resolves #38. --- pre_commit_hooks/autopep8_wrapper.py | 2 +- setup.py | 2 +- tests/autopep8_wrapper_test.py | 25 +++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pre_commit_hooks/autopep8_wrapper.py b/pre_commit_hooks/autopep8_wrapper.py index a79a120..f6f55fb 100644 --- a/pre_commit_hooks/autopep8_wrapper.py +++ b/pre_commit_hooks/autopep8_wrapper.py @@ -10,7 +10,7 @@ import autopep8 def main(argv=None): argv = argv if argv is not None else sys.argv[1:] - args = autopep8.parse_args(argv) + args = autopep8.parse_args(argv, apply_config=True) retv = 0 for filename in args.files: diff --git a/setup.py b/setup.py index 4fb9139..b86acd1 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup( packages=find_packages('.', exclude=('tests*', 'testing*')), install_requires=[ 'argparse', - 'autopep8', + 'autopep8>=1.1', 'flake8', 'plumbum', 'pyflakes', diff --git a/tests/autopep8_wrapper_test.py b/tests/autopep8_wrapper_test.py index f32e8a0..9a395c9 100644 --- a/tests/autopep8_wrapper_test.py +++ b/tests/autopep8_wrapper_test.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from __future__ import unicode_literals import io -import os.path +import os import pytest @@ -17,9 +17,30 @@ from pre_commit_hooks.autopep8_wrapper import main ), ) def test_main_failing(tmpdir, input_src, expected_ret, output_src): - filename = os.path.join(tmpdir.strpath, 'test.py') + filename = tmpdir.join('test.py').strpath with io.open(filename, 'w') as file_obj: file_obj.write(input_src) ret = main([filename, '-i', '-v']) assert ret == expected_ret assert io.open(filename).read() == output_src + + +@pytest.yield_fixture +def in_tmpdir(tmpdir): + pwd = os.getcwd() + os.chdir(tmpdir.strpath) + try: + yield + finally: + os.chdir(pwd) + + +@pytest.mark.usefixtures('in_tmpdir') +def test_respects_config_file(): + with io.open('setup.cfg', 'w') as setup_cfg: + setup_cfg.write('[pep8]\nignore=E221') + + with io.open('test.py', 'w') as test_py: + test_py.write('print(1 + 2)\n') + + assert main(['test.py', '-i', '-v']) == 0