Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 3041dcb

Browse files
committed
Fixed ParseError tests.
1 parent 22bcc87 commit 3041dcb

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/pydocstyle/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ def parse(self, filelike, filename):
274274
self.log = logging.getLogger()
275275
self.source = filelike.readlines()
276276
src = ''.join(self.source)
277+
try:
278+
compile(src, filename, 'exec')
279+
except SyntaxError as error:
280+
raise ParseError() from error
277281
self.stream = TokenStream(StringIO(src))
278282
self.filename = filename
279283
self.all = None

src/tests/parser_test.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,6 @@ def test_dunder_all(code):
518518
from __future__ import unicode_literals; from __future__ import \
519519
nested_scopes
520520
"""),
521-
# pep257 does not detect that 'import string' prevents
522-
# unicode_literals from being a valid __future__.
523-
# That is detected by pyflakes.
524-
CodeSnippet("""\
525-
from __future__ import unicode_literals; import string; from \
526-
__future__ import nested_scopes
527-
"""),
528521
))
529522
def test_future_import(code):
530523
"""Test that __future__ imports are properly parsed and collected."""
@@ -551,7 +544,13 @@ def foo(): # noqa: D100,D101
551544
try:
552545
pass
553546
"""),
554-
CodeSnippet("["),
547+
CodeSnippet("[\n"),
548+
# Should result in `SyntaxError: from __future__ imports must occur
549+
# at the beginning of the file`
550+
CodeSnippet("""\
551+
from __future__ import unicode_literals; import string; from \
552+
__future__ import nested_scopes
553+
"""),
555554
))
556555
def test_invalid_syntax(code):
557556
"""Test invalid code input to the parser."""

src/tests/test_cases/noqa.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Test case for "# noqa" comments."""
2+
from .expected import Expectation
3+
4+
5+
expectation = Expectation()
6+
expect = expectation.expect
7+
8+
9+
def docstring_bad_ignore_all(): # noqa
10+
"""Runs something"""
11+
pass
12+
13+
14+
def docstring_bad_ignore_one(): # noqa: D400,D401
15+
"""Runs something"""
16+
pass
17+
18+
19+
@expect("D401: First line should be in imperative mood ('Run', not 'Runs')")
20+
def docstring_ignore_violations_of_pydocstyle_D400_and_PEP8_E501_but_catch_D401(): # noqa: E501,D400
21+
"""Runs something"""
22+
pass

0 commit comments

Comments
 (0)