Skip to content

Commit 78d959d

Browse files
committed
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
1 parent 4c5bf00 commit 78d959d

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

pep8.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,13 @@ def normalize_paths(value, parent=os.curdir):
11551155
11561156
Return a list of absolute paths.
11571157
"""
1158-
if not value or isinstance(value, list):
1158+
if not value:
1159+
return []
1160+
if isinstance(value, list):
11591161
return value
11601162
paths = []
11611163
for path in value.split(','):
1164+
path = path.strip()
11621165
if '/' in path:
11631166
path = os.path.abspath(os.path.join(parent, path))
11641167
paths.append(path.rstrip('/'))

testsuite/test_all.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ def test_own_dog_food(self):
4646

4747

4848
def suite():
49-
from testsuite import test_api, test_shell
49+
from testsuite import test_api, test_shell, test_util
5050

5151
suite = unittest.TestSuite()
5252
suite.addTest(unittest.makeSuite(Pep8TestCase))
5353
suite.addTest(unittest.makeSuite(test_api.APITestCase))
5454
suite.addTest(unittest.makeSuite(test_shell.ShellTestCase))
55+
suite.addTest(unittest.makeSuite(test_util.UtilTestCase))
5556
return suite
5657

5758

testsuite/test_util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import os
4+
import unittest
5+
6+
import pep8
7+
8+
9+
class UtilTestCase(unittest.TestCase):
10+
def test_normalize_paths(self):
11+
cwd = os.getcwd()
12+
13+
self.assertEquals(pep8.normalize_paths(''), [])
14+
self.assertEquals(pep8.normalize_paths(['foo']), ['foo'])
15+
self.assertEquals(pep8.normalize_paths('foo'), ['foo'])
16+
self.assertEquals(pep8.normalize_paths('foo,bar'), ['foo', 'bar'])
17+
self.assertEquals(pep8.normalize_paths('/foo/bar,baz/../bat'),
18+
['/foo/bar', cwd + '/bat'])
19+
self.assertEquals(pep8.normalize_paths(".pyc,\n build/*"),
20+
['.pyc', cwd + '/build/*'])

0 commit comments

Comments
 (0)