Skip to content
Snippets Groups Projects
Commit 8cab6999 authored by Pierre Penninckx's avatar Pierre Penninckx
Browse files

produce try pass parsing error

parent 5bf309db
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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")
 
 
Loading
Loading
Loading
Loading
@@ -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"
}
],
}
])
Loading
Loading
@@ -275,8 +275,8 @@ def test_trailing_spaces():
"""
if a:
if b:
pass
"""
check([
Loading
Loading
@@ -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', ''),
])
Loading
Loading
@@ -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:
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment