Skip to content

Commit

Permalink
produce try pass parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Penninckx committed Dec 22, 2016
1 parent 5bf309d commit 8cab699
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 2 deletions.
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

0 comments on commit 8cab699

Please sign in to comment.