Skip to content

Commit

Permalink
Strip out trailing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Jul 12, 2016
1 parent 19bc89a commit 1220229
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flake8_putty/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def _parsed_lines(self):
assert selectors
assert codes

codes = codes.partition('#')[0].strip()
assert codes

selectors = SELECTOR_SPLITTER.findall(selectors)
selectors = [selector.strip() for selector in selectors]

Expand Down
18 changes: 18 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ class TestParser(TestCase):

"""Test config option rule parser."""

def test_selector_comment_empty_line(self):
p = Parser('# foo')
assert list(p._lines()) == []

def test_selector_comment_suffix(self):
p = Parser('E100 : E101 # foo')
assert list(p._lines()) == [
(1, 'E100 : E101 # foo'),
]

assert list(p._parsed_lines()) == [
(1, ['E100'], 'E101'),
]

assert p._rules == [
Rule([CodeSelector('E100')], 'E101'),
]

def test_selector_code(self):
p = Parser('E100 : E101')
assert list(p._lines()) == [
Expand Down

0 comments on commit 1220229

Please sign in to comment.