From 78d959d7ef3f9b4182905a30ec4a2e2c93381fe9 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Thu, 6 Nov 2014 20:23:46 -0500 Subject: Fix normalize_paths to allow whitespace This fixes normalize_paths so that it strips whitespace before and after paths before working on them. This allows you to do specify excludes with multiple lines in the config file. This also tweaks normalize_paths so that the behavior matches the docstring. This also adds tests. Fixes #339 --- pep8.py | 5 ++++- testsuite/test_all.py | 3 ++- testsuite/test_util.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 testsuite/test_util.py diff --git a/pep8.py b/pep8.py index b31a978..f32d27c 100755 --- a/pep8.py +++ b/pep8.py @@ -1155,10 +1155,13 @@ def normalize_paths(value, parent=os.curdir): Return a list of absolute paths. """ - if not value or isinstance(value, list): + if not value: + return [] + if isinstance(value, list): return value paths = [] for path in value.split(','): + path = path.strip() if '/' in path: path = os.path.abspath(os.path.join(parent, path)) paths.append(path.rstrip('/')) diff --git a/testsuite/test_all.py b/testsuite/test_all.py index 5160900..50e2cb9 100644 --- a/testsuite/test_all.py +++ b/testsuite/test_all.py @@ -46,12 +46,13 @@ class Pep8TestCase(unittest.TestCase): def suite(): - from testsuite import test_api, test_shell + from testsuite import test_api, test_shell, test_util suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(Pep8TestCase)) suite.addTest(unittest.makeSuite(test_api.APITestCase)) suite.addTest(unittest.makeSuite(test_shell.ShellTestCase)) + suite.addTest(unittest.makeSuite(test_util.UtilTestCase)) return suite diff --git a/testsuite/test_util.py b/testsuite/test_util.py new file mode 100644 index 0000000..84b736a --- /dev/null +++ b/testsuite/test_util.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import unittest + +import pep8 + + +class UtilTestCase(unittest.TestCase): + def test_normalize_paths(self): + cwd = os.getcwd() + + self.assertEquals(pep8.normalize_paths(''), []) + self.assertEquals(pep8.normalize_paths(['foo']), ['foo']) + self.assertEquals(pep8.normalize_paths('foo'), ['foo']) + self.assertEquals(pep8.normalize_paths('foo,bar'), ['foo', 'bar']) + self.assertEquals(pep8.normalize_paths('/foo/bar,baz/../bat'), + ['/foo/bar', cwd + '/bat']) + self.assertEquals(pep8.normalize_paths(".pyc,\n build/*"), + ['.pyc', cwd + '/build/*']) -- cgit v1.2.1 From fbc5e2d52549452c2adbe58644358cf3c4eeb526 Mon Sep 17 00:00:00 2001 From: Ian Lee Date: Fri, 12 Dec 2014 21:03:03 -0800 Subject: Add a few more cases of "not value" --- testsuite/test_util.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testsuite/test_util.py b/testsuite/test_util.py index 84b736a..658d057 100644 --- a/testsuite/test_util.py +++ b/testsuite/test_util.py @@ -11,9 +11,12 @@ class UtilTestCase(unittest.TestCase): cwd = os.getcwd() self.assertEquals(pep8.normalize_paths(''), []) + self.assertEquals(pep8.normalize_paths([]), []) + self.assertEquals(pep8.normalize_paths(None), []) self.assertEquals(pep8.normalize_paths(['foo']), ['foo']) self.assertEquals(pep8.normalize_paths('foo'), ['foo']) self.assertEquals(pep8.normalize_paths('foo,bar'), ['foo', 'bar']) + self.assertEquals(pep8.normalize_paths('foo, bar '), ['foo', 'bar']) self.assertEquals(pep8.normalize_paths('/foo/bar,baz/../bat'), ['/foo/bar', cwd + '/bat']) self.assertEquals(pep8.normalize_paths(".pyc,\n build/*"), -- cgit v1.2.1 From 4f5e7120a840a40e6184de06c2ec8b081196ccc1 Mon Sep 17 00:00:00 2001 From: Ian Lee Date: Sat, 13 Dec 2014 12:48:35 -0800 Subject: Update changelog for issue #339 / #343 --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 4bcfcf7..de027ea 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,8 @@ Changelog 1.x (unreleased) ---------------- +Bug fixes: + * Report E731 for lambda assignment. (Issue #277) * Report E704 for one-liner def instead of E701. @@ -16,6 +18,8 @@ Changelog * Report E266 instead of E265 when the block comment starts with multiple ``#``. (Issue #270) +* Strip whitespace from around paths during normalization. (Issue #339 / #343) + 1.5.7 (2014-05-29) ------------------ -- cgit v1.2.1