bpo-32416: Add two new tests in test_sys_settrace. (GH-5072) (#5073) · python/cpython@439ce8a

@@ -743,6 +743,14 @@ def test_jump_within_except_block(output):

743743

output.append(6)

744744

output.append(7)

745745746+

@jump_test(2, 4, [1, 4, 5, -4])

747+

def test_jump_across_with(output):

748+

output.append(1)

749+

with tracecontext(output, 2):

750+

output.append(3)

751+

with tracecontext(output, 4):

752+

output.append(5)

753+746754

@jump_test(8, 11, [1, 3, 5, 11, 12])

747755

def test_jump_out_of_complex_nested_blocks(output):

748756

output.append(1)

@@ -794,6 +802,17 @@ def test_jump_over_break_in_try_finally_block(output):

794802

break

795803

output.append(13)

796804805+

@jump_test(1, 7, [7, 8])

806+

def test_jump_over_for_block_before_else(output):

807+

output.append(1)

808+

if not output: # always false

809+

for i in [3]:

810+

output.append(4)

811+

else:

812+

output.append(6)

813+

output.append(7)

814+

output.append(8)

815+797816

# The second set of 'jump' tests are for things that are not allowed:

798817799818

@jump_test(2, 3, [1], (ValueError, 'after'))

@@ -951,21 +970,24 @@ def test_no_jump_out_of_finally_block(output):

951970

finally:

952971

output.append(5)

953972954-

@jump_test(2, 4, [1, 4, 5, -4])

955-

def test_jump_across_with(output):

973+

@jump_test(3, 5, [1, 2, -2], (ValueError, 'into'))

974+

def test_no_jump_between_with_blocks(output):

956975

output.append(1)

957976

with tracecontext(output, 2):

958977

output.append(3)

959978

with tracecontext(output, 4):

960979

output.append(5)

961980962-

@jump_test(3, 5, [1, 2, -2], (ValueError, 'into'))

963-

def test_jump_across_with_2(output):

981+

@jump_test(7, 4, [1, 6], (ValueError, 'into'))

982+

def test_no_jump_into_for_block_before_else(output):

964983

output.append(1)

965-

with tracecontext(output, 2):

966-

output.append(3)

967-

with tracecontext(output, 4):

968-

output.append(5)

984+

if not output: # always false

985+

for i in [3]:

986+

output.append(4)

987+

else:

988+

output.append(6)

989+

output.append(7)

990+

output.append(8)

969991970992

def test_no_jump_to_non_integers(self):

971993

self.run_test(no_jump_to_non_integers, 2, "Spam", [True])