Skip to content

Commit

Permalink
[2.7] bpo-32478: Add tests for 'break' and 'return' inside 'finally' …
Browse files Browse the repository at this point in the history
…clause. (GH-5078). (#5084)

(cherry picked from commit 7cc42c3)
  • Loading branch information
serhiy-storchaka committed Jan 2, 2018
1 parent 2de47ca commit b495377
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Lib/test/test_grammar.py
Expand Up @@ -490,6 +490,80 @@ def g2(): return 1
x = g2()
check_syntax_error(self, "class foo:return 1")

def test_break_in_finally(self):
count = 0
while count < 2:
count += 1
try:
pass
finally:
break
self.assertEqual(count, 1)

count = 0
while count < 2:
count += 1
try:
continue
finally:
break
self.assertEqual(count, 1)

count = 0
while count < 2:
count += 1
try:
1/0
finally:
break
self.assertEqual(count, 1)

for count in [0, 1]:
self.assertEqual(count, 0)
try:
pass
finally:
break
self.assertEqual(count, 0)

for count in [0, 1]:
self.assertEqual(count, 0)
try:
continue
finally:
break
self.assertEqual(count, 0)

for count in [0, 1]:
self.assertEqual(count, 0)
try:
1/0
finally:
break
self.assertEqual(count, 0)

def test_return_in_finally(self):
def g1():
try:
pass
finally:
return 1
self.assertEqual(g1(), 1)

def g2():
try:
return 2
finally:
return 3
self.assertEqual(g2(), 3)

def g3():
try:
1/0
finally:
return 4
self.assertEqual(g3(), 4)

def testYield(self):
check_syntax_error(self, "class foo:yield 1")

Expand Down

0 comments on commit b495377

Please sign in to comment.