summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <sigmavirus24@users.noreply.github.com>2015-09-07 14:07:09 -0500
committerIan Cordasco <sigmavirus24@users.noreply.github.com>2015-09-07 14:07:09 -0500
commit5feba521a7cbe51b2bcb0be5f7d5c06710c1a8d3 (patch)
treef99ed0fb6ead6415707d0a0d71f9e93fa1b353f9
parent151758ce8f29fd65e10dc0720446c5a3bb164602 (diff)
parente7d64d3062421707a1c896b25cc5134922bcd9ee (diff)
downloadpep8-5feba521a7cbe51b2bcb0be5f7d5c06710c1a8d3.tar.gz
Merge pull request #429 from doismellburning/feature/file-parsing-flexibility
Multi-line ignore parsing in config_file
-rwxr-xr-xpep8.py22
-rw-r--r--testsuite/test_all.py3
-rw-r--r--testsuite/test_parser.py61
3 files changed, 82 insertions, 4 deletions
diff --git a/pep8.py b/pep8.py
index 34ce07a..206e339 100755
--- a/pep8.py
+++ b/pep8.py
@@ -2081,10 +2081,10 @@ def process_options(arglist=None, parse_argv=False, config_file=None,
options = read_config(options, args, arglist, parser)
options.reporter = parse_argv and options.quiet == 1 and FileReport
- options.filename = options.filename and options.filename.split(',')
+ options.filename = _parse_multi_options(options.filename.split(','))
options.exclude = normalize_paths(options.exclude)
- options.select = options.select and options.select.split(',')
- options.ignore = options.ignore and options.ignore.split(',')
+ options.select = _parse_multi_options(options.select.split(','))
+ options.ignore = _parse_multi_options(options.ignore.split(','))
if options.diff:
options.reporter = DiffReport
@@ -2095,6 +2095,22 @@ def process_options(arglist=None, parse_argv=False, config_file=None,
return options, args
+def _parse_multi_options(options):
+ r"""Split and strip and discard empties.
+
+ Turns the following:
+
+ A,
+ B,
+
+ into ["A", "B"]
+ """
+ if options:
+ return [o.strip() for o in options if o.strip()]
+ else:
+ return options
+
+
def _main():
"""Parse options and run checks on Python source."""
import signal
diff --git a/testsuite/test_all.py b/testsuite/test_all.py
index 50e2cb9..bfb61d5 100644
--- a/testsuite/test_all.py
+++ b/testsuite/test_all.py
@@ -46,11 +46,12 @@ class Pep8TestCase(unittest.TestCase):
def suite():
- from testsuite import test_api, test_shell, test_util
+ from testsuite import test_api, test_parser, test_shell, test_util
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Pep8TestCase))
suite.addTest(unittest.makeSuite(test_api.APITestCase))
+ suite.addTest(unittest.makeSuite(test_parser.ParserTestCase))
suite.addTest(unittest.makeSuite(test_shell.ShellTestCase))
suite.addTest(unittest.makeSuite(test_util.UtilTestCase))
return suite
diff --git a/testsuite/test_parser.py b/testsuite/test_parser.py
new file mode 100644
index 0000000..1d9e1ac
--- /dev/null
+++ b/testsuite/test_parser.py
@@ -0,0 +1,61 @@
+import os
+import tempfile
+import unittest
+
+import pep8
+
+
+def _process_file(contents):
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ f.write(contents)
+
+ options, args = pep8.process_options(config_file=f.name)
+ os.remove(f.name)
+
+ return options, args
+
+
+class ParserTestCase(unittest.TestCase):
+
+ def test_vanilla_ignore_parsing(self):
+ contents = b"""
+[pep8]
+ignore = E226,E24
+ """
+ options, args = _process_file(contents)
+
+ self.assertEqual(options.ignore, ["E226", "E24"])
+
+ def test_multiline_ignore_parsing(self):
+ contents = b"""
+[pep8]
+ignore =
+ E226,
+ E24
+ """
+
+ options, args = _process_file(contents)
+
+ self.assertEqual(options.ignore, ["E226", "E24"])
+
+ def test_trailing_comma_ignore_parsing(self):
+ contents = b"""
+[pep8]
+ignore = E226,
+ """
+
+ options, args = _process_file(contents)
+
+ self.assertEqual(options.ignore, ["E226"])
+
+ def test_multiline_trailing_comma_ignore_parsing(self):
+ contents = b"""
+[pep8]
+ignore =
+ E226,
+ E24,
+ """
+
+ options, args = _process_file(contents)
+
+ self.assertEqual(options.ignore, ["E226", "E24"])