Skip to content

Commit e8ed965

Browse files
bpo-32416: Add two new tests in test_sys_settrace. (#5072)
Move other test to more proper place.
1 parent 1470914 commit e8ed965

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,14 @@ def test_jump_within_except_block(output):
789789
output.append(6)
790790
output.append(7)
791791

792+
@jump_test(2, 4, [1, 4, 5, -4])
793+
def test_jump_across_with(output):
794+
output.append(1)
795+
with tracecontext(output, 2):
796+
output.append(3)
797+
with tracecontext(output, 4):
798+
output.append(5)
799+
792800
@jump_test(8, 11, [1, 3, 5, 11, 12])
793801
def test_jump_out_of_complex_nested_blocks(output):
794802
output.append(1)
@@ -840,6 +848,17 @@ def test_jump_over_break_in_try_finally_block(output):
840848
break
841849
output.append(13)
842850

851+
@jump_test(1, 7, [7, 8])
852+
def test_jump_over_for_block_before_else(output):
853+
output.append(1)
854+
if not output: # always false
855+
for i in [3]:
856+
output.append(4)
857+
else:
858+
output.append(6)
859+
output.append(7)
860+
output.append(8)
861+
843862
# The second set of 'jump' tests are for things that are not allowed:
844863

845864
@jump_test(2, 3, [1], (ValueError, 'after'))
@@ -997,21 +1016,24 @@ def test_no_jump_out_of_finally_block(output):
9971016
finally:
9981017
output.append(5)
9991018

1000-
@jump_test(2, 4, [1, 4, 5, -4])
1001-
def test_jump_across_with(output):
1019+
@jump_test(3, 5, [1, 2, -2], (ValueError, 'into'))
1020+
def test_no_jump_between_with_blocks(output):
10021021
output.append(1)
10031022
with tracecontext(output, 2):
10041023
output.append(3)
10051024
with tracecontext(output, 4):
10061025
output.append(5)
10071026

1008-
@jump_test(3, 5, [1, 2, -2], (ValueError, 'into'))
1009-
def test_jump_across_with_2(output):
1027+
@jump_test(7, 4, [1, 6], (ValueError, 'into'))
1028+
def test_no_jump_into_for_block_before_else(output):
10101029
output.append(1)
1011-
with tracecontext(output, 2):
1012-
output.append(3)
1013-
with tracecontext(output, 4):
1014-
output.append(5)
1030+
if not output: # always false
1031+
for i in [3]:
1032+
output.append(4)
1033+
else:
1034+
output.append(6)
1035+
output.append(7)
1036+
output.append(8)
10151037

10161038
def test_no_jump_to_non_integers(self):
10171039
self.run_test(no_jump_to_non_integers, 2, "Spam", [True])

0 commit comments

Comments
 (0)