mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update test_ast.py from 3.14.3 (#7147)
This commit is contained in:
1 parent
1ead81f11e
commit
fbbd020e07
1 file changed
+37
-2
Vendored
+37
-2
@@ -24,7 +24,7 @@ except ImportError:
|
||||
|
||||
from test import support
|
||||
from test.support import os_helper
|
||||
from test.support import skip_emscripten_stack_overflow, skip_wasi_stack_overflow
|
||||
from test.support import skip_emscripten_stack_overflow, skip_wasi_stack_overflow, skip_if_unlimited_stack_size
|
||||
from test.support.ast_helper import ASTTestMixin
|
||||
from test.support.import_helper import ensure_lazy_imports
|
||||
from test.test_ast.utils import to_tuple
|
||||
@@ -994,10 +994,12 @@ class AST_Tests(unittest.TestCase):
|
||||
enum._test_simple_enum(_Precedence, _ast_unparse._Precedence)
|
||||
|
||||
@support.cpython_only
|
||||
@skip_if_unlimited_stack_size
|
||||
@skip_wasi_stack_overflow()
|
||||
@skip_emscripten_stack_overflow()
|
||||
def test_ast_recursion_limit(self):
|
||||
crash_depth = 500_000
|
||||
# Android test devices have less memory.
|
||||
crash_depth = 100_000 if sys.platform == "android" else 500_000
|
||||
success_depth = 200
|
||||
if _testinternalcapi is not None:
|
||||
remaining = _testinternalcapi.get_c_recursion_remaining()
|
||||
@@ -1118,6 +1120,7 @@ class CopyTests(unittest.TestCase):
|
||||
ast2 = pickle.loads(pickle.dumps(tree, protocol))
|
||||
self.assertEqual(to_tuple(ast2), to_tuple(tree))
|
||||
|
||||
@skip_if_unlimited_stack_size
|
||||
def test_copy_with_parents(self):
|
||||
# gh-120108
|
||||
code = """
|
||||
@@ -1436,6 +1439,14 @@ class CopyTests(unittest.TestCase):
|
||||
self.assertIs(node.ctx, context)
|
||||
self.assertRaises(AttributeError, getattr, node, 'unknown')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
|
||||
def test_replace_non_str_kwarg(self):
|
||||
node = ast.Name(id="x")
|
||||
errmsg = "got an unexpected keyword argument <object object"
|
||||
with self.assertRaisesRegex(TypeError, errmsg):
|
||||
node.__replace__(**{object(): "y"})
|
||||
|
||||
|
||||
class ASTHelpers_Test(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
@@ -1977,6 +1988,7 @@ Module(
|
||||
self.assertIn('sleep', ns)
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON; crash")
|
||||
@skip_if_unlimited_stack_size
|
||||
@skip_emscripten_stack_overflow()
|
||||
def test_recursion_direct(self):
|
||||
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))
|
||||
@@ -1986,6 +1998,7 @@ Module(
|
||||
compile(ast.Expression(e), "<test>", "eval")
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON; crash")
|
||||
@skip_if_unlimited_stack_size
|
||||
@skip_emscripten_stack_overflow()
|
||||
def test_recursion_indirect(self):
|
||||
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))
|
||||
@@ -3323,6 +3336,28 @@ class ASTConstructorTests(unittest.TestCase):
|
||||
self.assertIs(obj.a, None)
|
||||
self.assertEqual(obj.b, [])
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_non_str_kwarg(self):
|
||||
warn_msg = "got an unexpected keyword argument <object object"
|
||||
with (
|
||||
self.assertRaises(TypeError),
|
||||
self.assertWarnsRegex(DeprecationWarning, warn_msg),
|
||||
):
|
||||
ast.Name(**{object(): 'y'})
|
||||
|
||||
class FakeStr:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.value)
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, str) and self.value == other
|
||||
|
||||
with self.assertRaisesRegex(TypeError, "got multiple values for argument"):
|
||||
ast.Name("x", **{FakeStr('id'): 'y'})
|
||||
|
||||
|
||||
@support.cpython_only
|
||||
class ModuleStateTests(unittest.TestCase):
|
||||
|
||||
Reference in new issue
Block a user