From 71198d3847ef1e227401dfd09c81d08ff6699405 Mon Sep 17 00:00:00 2001 From: Kristian Glass Date: Sat, 22 Aug 2015 11:32:27 +0100 Subject: [PATCH] Test behaviour regarding multi-line ignore parsing in config_file At time of writing, these tests fail. If this is later fixed, someone may wish to remove this warning! --- testsuite/test_all.py | 3 +- testsuite/test_parser.py | 61 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 testsuite/test_parser.py diff --git a/testsuite/test_all.py b/testsuite/test_all.py index 50e2cb9f..bfb61d5f 100644 --- a/testsuite/test_all.py +++ b/testsuite/test_all.py @@ -46,11 +46,12 @@ def test_own_dog_food(self): 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 00000000..1b7fa315 --- /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 = """ +[pep8] +ignore = E226,E24 + """ + options, args = _process_file(contents) + + self.assertEqual(options.ignore, ["E226", "E24"]) + + def test_multiline_ignore_parsing(self): + contents = """ +[pep8] +ignore = + E226, + E24 + """ + + options, args = _process_file(contents) + + self.assertEqual(options.ignore, ["E226", "E24"]) + + def test_trailing_comma_ignore_parsing(self): + contents = """ +[pep8] +ignore = E226, + """ + + options, args = _process_file(contents) + + self.assertEqual(options.ignore, ["E226"]) + + def test_multiline_trailing_comma_ignore_parsing(self): + contents = """ +[pep8] +ignore = + E226, + E24, + """ + + options, args = _process_file(contents) + + self.assertEqual(options.ignore, ["E226", "E24"])