Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

produce try pass parsing error #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions tests/test_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def test_try_finally():


def test_try_except():
check_dumps("try: pass\n\nexcept:\n pass\n")


def test_try_except_named():
check_dumps("try : pass\nexcept Exception : pass\n")


Expand Down
141 changes: 141 additions & 0 deletions tests/test_grammator_control_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,3 +1706,144 @@ def test_try_except_as_stmt_indent():
],
}
])

def test_try_excepts_stmt_empty_same_line():
"""
try: pass
except:
pass
"""
parse_multi([
('TRY', 'try'),
('COLON', ':'),
('PASS', 'pass', [('SPACE', ' ')]),
('ENDL', '\n'),
('EXCEPT', 'except'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('INDENT', ''),
('PASS', 'pass'),
('ENDL', '\n'),
('DEDENT', ''),
], [
{
"type": "try",
"first_formatting": [],
"second_formatting": [],
"else": {},
"finally": {},
"excepts": [
{
"type": "except",
"first_formatting": [],
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": [],
"delimiter": "",
"target": {},
"exception": {},
"value": [
{
"type": "endl",
"formatting": [],
"value": "\n",
"indent": " "
},
{
"type": "pass",
},
{
"indent": "",
"formatting": [],
"type": "endl",
"value": "\n"
}
]
}
],
"value": [
{
"type": "pass",
},
{
"indent": "",
"formatting": [],
"type": "endl",
"value": "\n"
}
],
}
])

def test_try_excepts_stmt_empty_same_line_spaced():
"""
try: pass

except:
pass
"""
parse_multi([
('TRY', 'try'),
('COLON', ':'),
('PASS', 'pass', [('SPACE', ' ')]),
('ENDL', '\n'),
('ENDL', '\n'),
('EXCEPT', 'except'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('INDENT', ''),
('PASS', 'pass'),
('ENDL', '\n'),
('DEDENT', ''),
], [
{
"type": "try",
"first_formatting": [],
"second_formatting": [],
"else": {},
"finally": {},
"excepts": [
{
"type": "except",
"first_formatting": [],
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": [],
"delimiter": "",
"target": {},
"exception": {},
"value": [
{
"type": "endl",
"formatting": [],
"value": "\n",
"indent": " "
},
{
"type": "pass",
},
{
"indent": "",
"formatting": [],
"type": "endl",
"value": "\n"
}
]
}
],
"value": [
{
"type": "pass",
},
{
"indent": "",
"formatting": [],
"type": "endl",
"value": "\n"
}
],
}
])

39 changes: 37 additions & 2 deletions tests/test_indentation_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def test_trailing_spaces():
"""
if a:
if b:


pass
"""
check([
Expand Down Expand Up @@ -337,3 +337,38 @@ def test_tab_and_spaces_because_some_people_are_horrible():
('PASS', 'pass'),
('DEDENT', ''),
])


def test_try_pass_on_same_line():
"""
try: pass

except:
pass
"""
check([
('TRY', 'try'),
('COLON', ':', [], [('SPACE', ' ')]),
('PASS', 'pass'),
('ENDL', '\n'),
('ENDL', '\n'),
('EXCEPT', 'except'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('PASS', 'pass'),
('ENDL', '\n'),
], [
('TRY', 'try'),
('COLON', ':', [], [('SPACE', ' ')]),
('PASS', 'pass'),
('ENDL', '\n'),
('ENDL', '\n'),
('EXCEPT', 'except'),
('COLON', ':'),
('ENDL', '\n', [], [('SPACE', ' ')]),
('INDENT', ''),
('PASS', 'pass'),
('ENDL', '\n'),
('DEDENT', ''),
])

4 changes: 4 additions & 0 deletions tests/test_spliter.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ def test_backslash_in_comment():
def test_regression():
assert split("(r'[\"\\'](.|\n|\r)*[\"\\']', 'STRING'),") == ["(", "r", "'[\"\\'](.|\n|\r)*[\"\\']'", ",", " ", "'STRING'", ")", ","]


def test_try_pass():
assert split("try: pass\n\nexcept:\n pass") == ['try', ':', ' ', 'pass', '\n', '\n', 'except', ':', '\n', ' ', 'pass']

# TODO: make this test pass in python3 also
# requires to remove dependency on ast.py
if python_version == 2:
Expand Down