mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
gh-130080: fix warnings in tests (#131400)
This commit is contained in:
parent
51d309988b
commit
83479c2175
6 changed files with 82 additions and 77 deletions
|
|
@ -2415,7 +2415,9 @@ class TestStackSizeStability(unittest.TestCase):
|
|||
script = """def func():\n""" + i * snippet
|
||||
if async_:
|
||||
script = "async " + script
|
||||
code = compile(script, "<script>", "exec")
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', SyntaxWarning)
|
||||
code = compile(script, "<script>", "exec")
|
||||
exec(code, ns, ns)
|
||||
return ns['func'].__code__
|
||||
|
||||
|
|
|
|||
|
|
@ -3011,7 +3011,8 @@ class TestSingleDispatch(unittest.TestCase):
|
|||
try:
|
||||
yield str(arg)
|
||||
finally:
|
||||
return 'Done'
|
||||
pass
|
||||
return 'Done'
|
||||
|
||||
@classmethod_friendly_decorator
|
||||
@classmethod
|
||||
|
|
@ -3027,7 +3028,8 @@ class TestSingleDispatch(unittest.TestCase):
|
|||
try:
|
||||
yield str(arg)
|
||||
finally:
|
||||
return 'Done'
|
||||
pass
|
||||
return 'Done'
|
||||
|
||||
@functools.singledispatchmethod
|
||||
@classmethod_friendly_decorator
|
||||
|
|
|
|||
|
|
@ -917,56 +917,59 @@ class GrammarTests(unittest.TestCase):
|
|||
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)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', SyntaxWarning)
|
||||
|
||||
count = 0
|
||||
while count < 2:
|
||||
count += 1
|
||||
try:
|
||||
continue
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 1)
|
||||
count = 0
|
||||
while count < 2:
|
||||
count += 1
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
count = 0
|
||||
while count < 2:
|
||||
count += 1
|
||||
try:
|
||||
1/0
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 1)
|
||||
count = 0
|
||||
while count < 2:
|
||||
count += 1
|
||||
try:
|
||||
continue
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
for count in [0, 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)
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
for count in [0, 1]:
|
||||
for count in [0, 1]:
|
||||
self.assertEqual(count, 0)
|
||||
try:
|
||||
continue
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 0)
|
||||
try:
|
||||
continue
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
for count in [0, 1]:
|
||||
for count in [0, 1]:
|
||||
self.assertEqual(count, 0)
|
||||
try:
|
||||
1/0
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 0)
|
||||
try:
|
||||
1/0
|
||||
finally:
|
||||
break
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_continue_in_finally(self):
|
||||
count = 0
|
||||
|
|
|
|||
|
|
@ -920,20 +920,28 @@ class TraceTestCase(unittest.TestCase):
|
|||
|
||||
def func():
|
||||
try:
|
||||
2/0
|
||||
except IndexError:
|
||||
4
|
||||
finally:
|
||||
return 6
|
||||
try:
|
||||
2/0
|
||||
except IndexError:
|
||||
5
|
||||
finally:
|
||||
7
|
||||
except:
|
||||
pass
|
||||
return 10
|
||||
|
||||
self.run_and_compare(func,
|
||||
[(0, 'call'),
|
||||
(1, 'line'),
|
||||
(2, 'line'),
|
||||
(2, 'exception'),
|
||||
(3, 'line'),
|
||||
(6, 'line'),
|
||||
(6, 'return')])
|
||||
(3, 'exception'),
|
||||
(4, 'line'),
|
||||
(7, 'line'),
|
||||
(8, 'line'),
|
||||
(9, 'line'),
|
||||
(10, 'line'),
|
||||
(10, 'return')])
|
||||
|
||||
def test_finally_with_conditional(self):
|
||||
|
||||
|
|
@ -2228,21 +2236,6 @@ class JumpTestCase(unittest.TestCase):
|
|||
output.append(11)
|
||||
output.append(12)
|
||||
|
||||
@jump_test(5, 11, [2, 4], (ValueError, 'comes after the current code block'))
|
||||
def test_no_jump_over_return_try_finally_in_finally_block(output):
|
||||
try:
|
||||
output.append(2)
|
||||
finally:
|
||||
output.append(4)
|
||||
output.append(5)
|
||||
return
|
||||
try:
|
||||
output.append(8)
|
||||
finally:
|
||||
output.append(10)
|
||||
pass
|
||||
output.append(12)
|
||||
|
||||
@jump_test(3, 4, [1], (ValueError, 'after'))
|
||||
def test_no_jump_infinite_while_loop(output):
|
||||
output.append(1)
|
||||
|
|
@ -2766,7 +2759,7 @@ class JumpTestCase(unittest.TestCase):
|
|||
finally:
|
||||
output.append(4)
|
||||
output.append(5)
|
||||
return
|
||||
return
|
||||
output.append(7)
|
||||
|
||||
@jump_test(7, 4, [1, 6], (ValueError, 'into'))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import test.support
|
|||
import pathlib
|
||||
import random
|
||||
import tokenize
|
||||
import warnings
|
||||
import ast
|
||||
from test.support.ast_helper import ASTTestMixin
|
||||
|
||||
|
|
@ -839,13 +840,16 @@ class DirectoryTestCase(ASTTestCase):
|
|||
return items
|
||||
|
||||
def test_files(self):
|
||||
for item in self.files_to_test():
|
||||
if test.support.verbose:
|
||||
print(f"Testing {item.absolute()}")
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', SyntaxWarning)
|
||||
|
||||
with self.subTest(filename=item):
|
||||
source = read_pyfile(item)
|
||||
self.check_ast_roundtrip(source)
|
||||
for item in self.files_to_test():
|
||||
if test.support.verbose:
|
||||
print(f"Testing {item.absolute()}")
|
||||
|
||||
with self.subTest(filename=item):
|
||||
source = read_pyfile(item)
|
||||
self.check_ast_roundtrip(source)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -1520,8 +1520,9 @@ class TestInterestingEdgeCases(unittest.TestCase):
|
|||
try:
|
||||
yield yielded_first
|
||||
yield yielded_second
|
||||
finally:
|
||||
return returned
|
||||
except:
|
||||
pass
|
||||
return returned
|
||||
|
||||
def outer():
|
||||
return (yield from inner())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue