Skip to content

Commit 3c01be2

Browse files
authored
Update some tests to 3.13.7 (RustPython#6171)
* Update `test_call.py` from 3.13.7 * Update `test_yield_from.py` from 3.13.7 * Update more tests to 3.13.7 * More tests to 3.13.7 * Remove patch from passing test
1 parent 24f4fba commit 3c01be2

File tree

9 files changed

+1332
-271
lines changed

9 files changed

+1332
-271
lines changed

Lib/test/test_call.py

Lines changed: 682 additions & 202 deletions
Large diffs are not rendered by default.

Lib/test/test_file.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,9 @@ def testIteration(self):
344344
class COtherFileTests(OtherFileTests, unittest.TestCase):
345345
open = io.open
346346

347-
# TODO: RUSTPYTHON
348-
@unittest.expectedFailure
347+
@unittest.expectedFailure # TODO: RUSTPYTHON
349348
def testSetBufferSize(self):
350-
super().testSetBufferSize()
349+
return super().testSetBufferSize()
351350

352351
class PyOtherFileTests(OtherFileTests, unittest.TestCase):
353352
open = staticmethod(pyio.open)

Lib/test/test_raise.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ def test_class_cause(self):
185185
else:
186186
self.fail("No exception raised")
187187

188+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: 'classmethod' object is not callable
189+
def test_class_cause_nonexception_result(self):
190+
class ConstructsNone(BaseException):
191+
@classmethod
192+
def __new__(*args, **kwargs):
193+
return None
194+
try:
195+
raise IndexError from ConstructsNone
196+
except TypeError as e:
197+
self.assertIn("should have returned an instance of BaseException", str(e))
198+
except IndexError:
199+
self.fail("Wrong kind of exception raised")
200+
else:
201+
self.fail("No exception raised")
202+
188203
def test_instance_cause(self):
189204
cause = KeyError()
190205
try:
@@ -233,8 +248,7 @@ class TestTracebackType(unittest.TestCase):
233248
def raiser(self):
234249
raise ValueError
235250

236-
# TODO: RUSTPYTHON
237-
@unittest.expectedFailure
251+
@unittest.expectedFailure # TODO: RUSTPYTHON
238252
def test_attrs(self):
239253
try:
240254
self.raiser()

Lib/test/test_scope.py

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,57 @@ def bar():
177177
self.assertEqual(foo(a=42), 50)
178178
self.assertEqual(foo(), 25)
179179

180+
def testCellIsArgAndEscapes(self):
181+
# We need to be sure that a cell passed in as an arg still
182+
# gets wrapped in a new cell if the arg escapes into an
183+
# inner function (closure).
184+
185+
def external():
186+
value = 42
187+
def inner():
188+
return value
189+
cell, = inner.__closure__
190+
return cell
191+
cell_ext = external()
192+
193+
def spam(arg):
194+
def eggs():
195+
return arg
196+
return eggs
197+
198+
eggs = spam(cell_ext)
199+
cell_closure, = eggs.__closure__
200+
cell_eggs = eggs()
201+
202+
self.assertIs(cell_eggs, cell_ext)
203+
self.assertIsNot(cell_eggs, cell_closure)
204+
205+
def testCellIsLocalAndEscapes(self):
206+
# We need to be sure that a cell bound to a local still
207+
# gets wrapped in a new cell if the local escapes into an
208+
# inner function (closure).
209+
210+
def external():
211+
value = 42
212+
def inner():
213+
return value
214+
cell, = inner.__closure__
215+
return cell
216+
cell_ext = external()
217+
218+
def spam(arg):
219+
cell = arg
220+
def eggs():
221+
return cell
222+
return eggs
223+
224+
eggs = spam(cell_ext)
225+
cell_closure, = eggs.__closure__
226+
cell_eggs = eggs()
227+
228+
self.assertIs(cell_eggs, cell_ext)
229+
self.assertIsNot(cell_eggs, cell_closure)
230+
180231
def testRecursion(self):
181232

182233
def f(x):
@@ -641,10 +692,7 @@ def dec(self):
641692
self.assertEqual(c.dec(), 1)
642693
self.assertEqual(c.dec(), 0)
643694

644-
# TODO: RUSTPYTHON, figure out how to communicate that `y = 9` should be
645-
# stored as a global rather than a STORE_NAME, even when
646-
# the `global y` is in a nested subscope
647-
@unittest.expectedFailure
695+
@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
648696
def testGlobalInParallelNestedFunctions(self):
649697
# A symbol table bug leaked the global statement from one
650698
# function to other nested functions in the same block.
@@ -763,6 +811,30 @@ def dig(self):
763811
gc_collect() # For PyPy or other GCs.
764812
self.assertIsNone(ref())
765813

814+
def test_multiple_nesting(self):
815+
# Regression test for https://github.com/python/cpython/issues/121863
816+
class MultiplyNested:
817+
def f1(self):
818+
__arg = 1
819+
class D:
820+
def g(self, __arg):
821+
return __arg
822+
return D().g(_MultiplyNested__arg=2)
823+
824+
def f2(self):
825+
__arg = 1
826+
class D:
827+
def g(self, __arg):
828+
return __arg
829+
return D().g
830+
831+
inst = MultiplyNested()
832+
with self.assertRaises(TypeError):
833+
inst.f1()
834+
835+
closure = inst.f2()
836+
with self.assertRaises(TypeError):
837+
closure(_MultiplyNested__arg=2)
766838

767839
if __name__ == '__main__':
768840
unittest.main()

Lib/test/test_slice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ def test_deepcopy(self):
286286
self.assertIsNot(s.stop, c.stop)
287287
self.assertIsNot(s.step, c.step)
288288

289-
# TODO: RUSTPYTHON
290-
@unittest.expectedFailure
289+
@unittest.expectedFailure # TODO: RUSTPYTHON
291290
def test_cycle(self):
292291
class myobj(): pass
293292
o = myobj()

Lib/test/test_string_literals.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def test_eval_str_incomplete(self):
105105
self.assertRaises(SyntaxError, eval, r""" '\U000000' """)
106106
self.assertRaises(SyntaxError, eval, r""" '\U0000000' """)
107107

108-
# TODO: RUSTPYTHON
109-
@unittest.expectedFailure
108+
@unittest.expectedFailure # TODO: RUSTPYTHON
110109
def test_eval_str_invalid_escape(self):
111110
for b in range(1, 128):
112111
if b in b"""\n\r"'01234567NU\\abfnrtuvx""":
@@ -145,8 +144,7 @@ def test_eval_str_invalid_escape(self):
145144
self.assertRegex(str(w[0].message), 'invalid escape sequence')
146145
self.assertEqual(w[0].filename, '<string>')
147146

148-
# TODO: RUSTPYTHON
149-
@unittest.expectedFailure
147+
@unittest.expectedFailure # TODO: RUSTPYTHON
150148
def test_eval_str_invalid_octal_escape(self):
151149
for i in range(0o400, 0o1000):
152150
with self.assertWarns(SyntaxWarning):
@@ -172,8 +170,7 @@ def test_eval_str_invalid_octal_escape(self):
172170
self.assertEqual(exc.lineno, 2)
173171
self.assertEqual(exc.offset, 1)
174172

175-
# TODO: RUSTPYTHON
176-
@unittest.expectedFailure
173+
@unittest.expectedFailure # TODO: RUSTPYTHON
177174
def test_invalid_escape_locations_with_offset(self):
178175
with warnings.catch_warnings(record=True) as w:
179176
warnings.simplefilter('error', category=SyntaxWarning)
@@ -223,8 +220,7 @@ def test_eval_bytes_incomplete(self):
223220
self.assertRaises(SyntaxError, eval, r""" b'\x' """)
224221
self.assertRaises(SyntaxError, eval, r""" b'\x0' """)
225222

226-
# TODO: RUSTPYTHON
227-
@unittest.expectedFailure
223+
@unittest.expectedFailure # TODO: RUSTPYTHON
228224
def test_eval_bytes_invalid_escape(self):
229225
for b in range(1, 128):
230226
if b in b"""\n\r"'01234567\\abfnrtvx""":
@@ -250,8 +246,7 @@ def test_eval_bytes_invalid_escape(self):
250246
self.assertEqual(exc.filename, '<string>')
251247
self.assertEqual(exc.lineno, 2)
252248

253-
# TODO: RUSTPYTHON
254-
@unittest.expectedFailure
249+
@unittest.expectedFailure # TODO: RUSTPYTHON
255250
def test_eval_bytes_invalid_octal_escape(self):
256251
for i in range(0o400, 0o1000):
257252
with self.assertWarns(SyntaxWarning):

Lib/test/test_strtod.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_short_halfway_cases(self):
146146
digits *= 5
147147
exponent -= 1
148148

149-
@unittest.skip("TODO: RUSTPYTHON, fails on debug mode, flaky in release mode")
149+
@unittest.skip('TODO: RUSTPYTHON; fails on debug mode, flaky in release mode')
150150
def test_halfway_cases(self):
151151
# test halfway cases for the round-half-to-even rule
152152
for i in range(100 * TEST_SIZE):
@@ -173,8 +173,7 @@ def test_halfway_cases(self):
173173
s = '{}e{}'.format(digits, exponent)
174174
self.check_strtod(s)
175175

176-
# TODO: RUSTPYTHON
177-
@unittest.expectedFailure
176+
@unittest.expectedFailure # TODO: RUSTPYTHON
178177
def test_boundaries(self):
179178
# boundaries expressed as triples (n, e, u), where
180179
# n*10**e is an approximation to the boundary value and
@@ -195,8 +194,7 @@ def test_boundaries(self):
195194
u *= 10
196195
e -= 1
197196

198-
# TODO: RUSTPYTHON
199-
@unittest.expectedFailure
197+
@unittest.expectedFailure # TODO: RUSTPYTHON
200198
def test_underflow_boundary(self):
201199
# test values close to 2**-1075, the underflow boundary; similar
202200
# to boundary_tests, except that the random error doesn't scale
@@ -208,8 +206,7 @@ def test_underflow_boundary(self):
208206
s = '{}e{}'.format(digits, exponent)
209207
self.check_strtod(s)
210208

211-
# TODO: RUSTPYTHON
212-
@unittest.expectedFailure
209+
@unittest.expectedFailure # TODO: RUSTPYTHON
213210
def test_bigcomp(self):
214211
for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50:
215212
dig10 = 10**ndigs
@@ -219,8 +216,7 @@ def test_bigcomp(self):
219216
s = '{}e{}'.format(digits, exponent)
220217
self.check_strtod(s)
221218

222-
# TODO: RUSTPYTHON, Incorrectly rounded str->float conversion for -07e-321
223-
@unittest.skip("TODO: RUSTPYTHON; flaky test")
219+
@unittest.skip('TODO: RUSTPYTHON; flaky test')
224220
def test_parsing(self):
225221
# make '0' more likely to be chosen than other digits
226222
digits = '000000123456789'
@@ -288,8 +284,7 @@ def negative_exp(n):
288284
self.assertEqual(float(negative_exp(20000)), 1.0)
289285
self.assertEqual(float(negative_exp(30000)), 1.0)
290286

291-
# TODO: RUSTPYTHON
292-
@unittest.expectedFailure
287+
@unittest.expectedFailure # TODO: RUSTPYTHON
293288
def test_particular(self):
294289
# inputs that produced crashes or incorrectly rounded results with
295290
# previous versions of dtoa.c, for various reasons

Lib/test/test_sundry.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
"""Do a minimal test of all the modules that aren't otherwise tested."""
22
import importlib
3-
import platform
4-
import sys
53
from test import support
64
from test.support import import_helper
75
from test.support import warnings_helper
86
import unittest
97

108
class TestUntestedModules(unittest.TestCase):
11-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
129
def test_untested_modules_can_be_imported(self):
1310
untested = ('encodings',)
1411
with warnings_helper.check_warnings(quiet=True):
@@ -21,31 +18,6 @@ def test_untested_modules_can_be_imported(self):
2118
self.fail('{} has tests even though test_sundry claims '
2219
'otherwise'.format(name))
2320

24-
import distutils.bcppcompiler
25-
import distutils.ccompiler
26-
import distutils.cygwinccompiler
27-
import distutils.filelist
28-
import distutils.text_file
29-
import distutils.unixccompiler
30-
31-
import distutils.command.bdist_dumb
32-
if sys.platform.startswith('win') and not platform.win32_is_iot():
33-
import distutils.command.bdist_msi
34-
import distutils.command.bdist
35-
import distutils.command.bdist_rpm
36-
import distutils.command.build_clib
37-
import distutils.command.build_ext
38-
import distutils.command.build
39-
import distutils.command.clean
40-
import distutils.command.config
41-
import distutils.command.install_data
42-
import distutils.command.install_egg_info
43-
import distutils.command.install_headers
44-
import distutils.command.install_lib
45-
import distutils.command.register
46-
import distutils.command.sdist
47-
import distutils.command.upload
48-
4921
import html.entities
5022

5123
try:
@@ -54,5 +26,6 @@ def test_untested_modules_can_be_imported(self):
5426
if support.verbose:
5527
print("skipping tty")
5628

29+
5730
if __name__ == "__main__":
5831
unittest.main()

0 commit comments

Comments
 (0)