Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split this up because if not value could be any falsey value and the docstring states that this function returns a list, thus it should return an empty list in these cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @willkg, I'd be interested to hear what your case was where this was failing for you. I'm tempted to update this to the following to handle the case where it isn't a list or a string coming in. Alternatively, perhaps it would be better to raise a ValueError at that point.

if not value:
    return []
if isinstance(value, list):
    return value
if not isinstance(value, str):
    return []

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a preference one way or the other. I changed this code because the docstring says it returns a list, but the code was just returning falsey values. I don't have a preference for my version or your version or even changing it to raise a ValueError.

paths = []
for path in value.split(','):
path = path.strip()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for issue #339. It strips whitespace before and after the path before doing further processing.

if '/' in path:
path = os.path.abspath(os.path.join(parent, path))
paths.append(path.rstrip('/'))
Expand Down
3 changes: 2 additions & 1 deletion testsuite/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ def test_own_dog_food(self):


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


Expand Down
20 changes: 20 additions & 0 deletions testsuite/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import unittest

import pep8


class UtilTestCase(unittest.TestCase):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called this UtilTestCase figuring this is a good place to test some of the other functions in pep8.py that have no tests. If you want me to name it something else, I'm game.

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/*'])