Skip to content

Commit 144a4d0

Browse files
committed
Merge branch 'willkg:normalize_path_fix'
Pull request #343, Issues #339 / #343
2 parents 4990135 + 4f5e712 commit 144a4d0

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Bug fixes:
2222
* Report E266 instead of E265 when the block comment starts with
2323
multiple ``#``. (Issue #270)
2424

25+
* Strip whitespace from around paths during normalization. (Issue #339 / #343)
26+
2527

2628
1.5.7 (2014-05-29)
2729
------------------

pep8.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,10 +1156,13 @@ def normalize_paths(value, parent=os.curdir):
11561156
11571157
Return a list of absolute paths.
11581158
"""
1159-
if not value or isinstance(value, list):
1159+
if not value:
1160+
return []
1161+
if isinstance(value, list):
11601162
return value
11611163
paths = []
11621164
for path in value.split(','):
1165+
path = path.strip()
11631166
if '/' in path:
11641167
path = os.path.abspath(os.path.join(parent, path))
11651168
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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([]), [])
15+
self.assertEquals(pep8.normalize_paths(None), [])
16+
self.assertEquals(pep8.normalize_paths(['foo']), ['foo'])
17+
self.assertEquals(pep8.normalize_paths('foo'), ['foo'])
18+
self.assertEquals(pep8.normalize_paths('foo,bar'), ['foo', 'bar'])
19+
self.assertEquals(pep8.normalize_paths('foo, bar '), ['foo', 'bar'])
20+
self.assertEquals(pep8.normalize_paths('/foo/bar,baz/../bat'),
21+
['/foo/bar', cwd + '/bat'])
22+
self.assertEquals(pep8.normalize_paths(".pyc,\n build/*"),
23+
['.pyc', cwd + '/build/*'])

0 commit comments

Comments
 (0)