GeezerVison is showing github.com — Update `test_{list,listcomps}.py` from 3.13.5 (#5965) · RustPython/RustPython@4fe4ff4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_list.py +53-2Lines changed: 53 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import sys | | 2 | +import textwrap | 2 | 3 | from test import list_tests | 3 | 4 | from test.support import cpython_only | | 5 | +from test.support.script_helper import assert_python_ok | 4 | 6 | import pickle | 5 | 7 | import unittest | 6 | 8 |
| @@ -98,8 +100,13 @@ def imul(a, b): a *= b | 98 | 100 | self.assertRaises((MemoryError, OverflowError), mul, lst, n) | 99 | 101 | self.assertRaises((MemoryError, OverflowError), imul, lst, n) | 100 | 102 |
| | 103 | + def test_empty_slice(self): | | 104 | + x = [] | | 105 | + x[:] = x | | 106 | + self.assertEqual(x, []) | | 107 | + | 101 | 108 | # TODO: RUSTPYTHON | 102 | | - @unittest.skip("Crashes on windows debug build") | | 109 | + @unittest.skip("TODO: RUSTPYTHON crash") | 103 | 110 | def test_list_resize_overflow(self): | 104 | 111 | # gh-97616: test new_allocated * sizeof(PyObject*) overflow | 105 | 112 | # check in list_resize() | @@ -113,13 +120,28 @@ def test_list_resize_overflow(self): | 113 | 120 | with self.assertRaises((MemoryError, OverflowError)): | 114 | 121 | lst *= size | 115 | 122 |
| | 123 | + # TODO: RUSTPYTHON | | 124 | + @unittest.skip("TODO: RUSTPYTHON hangs") | | 125 | + def test_repr_mutate(self): | | 126 | + class Obj: | | 127 | + @staticmethod | | 128 | + def __repr__(): | | 129 | + try: | | 130 | + mylist.pop() | | 131 | + except IndexError: | | 132 | + pass | | 133 | + return 'obj' | | 134 | + | | 135 | + mylist = [Obj() for _ in range(5)] | | 136 | + self.assertEqual(repr(mylist), '[obj, obj, obj]') | | 137 | + | 116 | 138 | def test_repr_large(self): | 117 | 139 | # Check the repr of large list objects | 118 | 140 | def check(n): | 119 | 141 | l = [0] * n | 120 | 142 | s = repr(l) | 121 | 143 | self.assertEqual(s, | 122 | | - '[' + ', '.join(['0'] * n) + ']') | | 144 | + '[' + ', '.join(['0'] * n) + ']') | 123 | 145 | check(10) # check our checking code | 124 | 146 | check(1000000) | 125 | 147 |
| @@ -302,6 +324,35 @@ def __eq__(self, other): | 302 | 324 | lst = [X(), X()] | 303 | 325 | X() in lst | 304 | 326 |
| | 327 | + def test_tier2_invalidates_iterator(self): | | 328 | + # GH-121012 | | 329 | + for _ in range(100): | | 330 | + a = [1, 2, 3] | | 331 | + it = iter(a) | | 332 | + for _ in it: | | 333 | + pass | | 334 | + a.append(4) | | 335 | + self.assertEqual(list(it), []) | | 336 | + | | 337 | + def test_deopt_from_append_list(self): | | 338 | + # gh-132011: it used to crash, because | | 339 | + # of `CALL_LIST_APPEND` specialization failure. | | 340 | + code = textwrap.dedent(""" | | 341 | + l = [] | | 342 | + def lappend(l, x, y): | | 343 | + l.append((x, y)) | | 344 | + for x in range(3): | | 345 | + lappend(l, None, None) | | 346 | + try: | | 347 | + lappend(list, None, None) | | 348 | + except TypeError: | | 349 | + pass | | 350 | + else: | | 351 | + raise AssertionError | | 352 | + """) | | 353 | + | | 354 | + rc, _, _ = assert_python_ok("-c", code) | | 355 | + self.assertEqual(rc, 0) | 305 | 356 |
| 306 | 357 | if __name__ == "__main__": | 307 | 358 | unittest.main() |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_listcomps.py +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -177,7 +177,7 @@ def test_references___class___defined(self): | 177 | 177 | res = [__class__ for x in [1]] | 178 | 178 | """ | 179 | 179 | self._check_in_scopes( | 180 | | - code, outputs={"res": [2]}, scopes=["module", "function"]) | | 180 | + code, outputs={"res": [2]}, scopes=["module", "function"]) | 181 | 181 | self._check_in_scopes(code, raises=NameError, scopes=["class"]) | 182 | 182 |
| 183 | 183 | def test_references___class___enclosing(self): | @@ -648,11 +648,18 @@ def test_exception_in_post_comp_call(self): | 648 | 648 | """ | 649 | 649 | self._check_in_scopes(code, {"value": [1, None]}) | 650 | 650 |
| | 651 | + # TODO: RUSTPYTHON | | 652 | + @unittest.expectedFailure | 651 | 653 | def test_frame_locals(self): | 652 | 654 | code = """ | 653 | | - val = [sys._getframe().f_locals for a in [0]][0]["a"] | | 655 | + val = "a" in [sys._getframe().f_locals for a in [0]][0] | 654 | 656 | """ | 655 | 657 | import sys | | 658 | + self._check_in_scopes(code, {"val": False}, ns={"sys": sys}) | | 659 | + | | 660 | + code = """ | | 661 | + val = [sys._getframe().f_locals["a"] for a in [0]][0] | | 662 | + """ | 656 | 663 | self._check_in_scopes(code, {"val": 0}, ns={"sys": sys}) | 657 | 664 |
| 658 | 665 | def _recursive_replace(self, maybe_code): | @@ -736,7 +743,7 @@ def iter_raises(): | 736 | 743 | for func, expected in [(init_raises, "BrokenIter(init_raises=True)"), | 737 | 744 | (next_raises, "BrokenIter(next_raises=True)"), | 738 | 745 | (iter_raises, "BrokenIter(iter_raises=True)"), | 739 | | - ]: | | 746 | + ]: | 740 | 747 | with self.subTest(func): | 741 | 748 | exc = func() | 742 | 749 | f = traceback.extract_tb(exc.__traceback__)[0] | |
|