Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More tests to 3.13.7
  • Loading branch information
ShaharNaveh committed Sep 20, 2025
commit 98a6466f8b301a8fb3fdbd8755dca9ccdcd53088
18 changes: 16 additions & 2 deletions Lib/test/test_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ def test_class_cause(self):
else:
self.fail("No exception raised")

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: 'classmethod' object is not callable
def test_class_cause_nonexception_result(self):
class ConstructsNone(BaseException):
@classmethod
def __new__(*args, **kwargs):
return None
try:
raise IndexError from ConstructsNone
except TypeError as e:
self.assertIn("should have returned an instance of BaseException", str(e))
except IndexError:
self.fail("Wrong kind of exception raised")
else:
self.fail("No exception raised")

def test_instance_cause(self):
cause = KeyError()
try:
Expand Down Expand Up @@ -233,8 +248,7 @@ class TestTracebackType(unittest.TestCase):
def raiser(self):
raise ValueError

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_attrs(self):
try:
self.raiser()
Expand Down
80 changes: 76 additions & 4 deletions Lib/test/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,57 @@ def bar():
self.assertEqual(foo(a=42), 50)
self.assertEqual(foo(), 25)

def testCellIsArgAndEscapes(self):
# We need to be sure that a cell passed in as an arg still
# gets wrapped in a new cell if the arg escapes into an
# inner function (closure).

def external():
value = 42
def inner():
return value
cell, = inner.__closure__
return cell
cell_ext = external()

def spam(arg):
def eggs():
return arg
return eggs

eggs = spam(cell_ext)
cell_closure, = eggs.__closure__
cell_eggs = eggs()

self.assertIs(cell_eggs, cell_ext)
self.assertIsNot(cell_eggs, cell_closure)

def testCellIsLocalAndEscapes(self):
# We need to be sure that a cell bound to a local still
# gets wrapped in a new cell if the local escapes into an
# inner function (closure).

def external():
value = 42
def inner():
return value
cell, = inner.__closure__
return cell
cell_ext = external()

def spam(arg):
cell = arg
def eggs():
return cell
return eggs

eggs = spam(cell_ext)
cell_closure, = eggs.__closure__
cell_eggs = eggs()

self.assertIs(cell_eggs, cell_ext)
self.assertIsNot(cell_eggs, cell_closure)

def testRecursion(self):

def f(x):
Expand Down Expand Up @@ -641,10 +692,7 @@ def dec(self):
self.assertEqual(c.dec(), 1)
self.assertEqual(c.dec(), 0)

# TODO: RUSTPYTHON, figure out how to communicate that `y = 9` should be
# stored as a global rather than a STORE_NAME, even when
# the `global y` is in a nested subscope
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; figure out how to communicate that `y = 9` should be stored as a global rather than a STORE_NAME, even when the `global y` is in a nested subscope
def testGlobalInParallelNestedFunctions(self):
# A symbol table bug leaked the global statement from one
# function to other nested functions in the same block.
Expand Down Expand Up @@ -763,6 +811,30 @@ def dig(self):
gc_collect() # For PyPy or other GCs.
self.assertIsNone(ref())

def test_multiple_nesting(self):
# Regression test for https://github.com/python/cpython/issues/121863
class MultiplyNested:
def f1(self):
__arg = 1
class D:
def g(self, __arg):
return __arg
return D().g(_MultiplyNested__arg=2)

def f2(self):
__arg = 1
class D:
def g(self, __arg):
return __arg
return D().g

inst = MultiplyNested()
with self.assertRaises(TypeError):
inst.f1()

closure = inst.f2()
with self.assertRaises(TypeError):
closure(_MultiplyNested__arg=2)

if __name__ == '__main__':
unittest.main()
3 changes: 1 addition & 2 deletions Lib/test/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ def test_deepcopy(self):
self.assertIsNot(s.stop, c.stop)
self.assertIsNot(s.step, c.step)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_cycle(self):
class myobj(): pass
o = myobj()
Expand Down
Loading