8000 Merge pull request #6115 from ShaharNaveh/update-some-tests-2 · RustPython/RustPython@d17dcd8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d17dcd8

Browse files
authored
Merge pull request #6115 from ShaharNaveh/update-some-tests-2
Update some tests from 3.13.7
2 parents 1688e74 + de3cb8c commit d17dcd8

15 files changed

+857
-378
lines changed

Lib/test/test_decorators.py

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -291,46 +291,7 @@ def bar(): return 42
291291
self.assertEqual(bar(), 42)
292292
self.assertEqual(actions, expected_actions)
293293

294-
def test_wrapped_descriptor_inside_classmethod(self):
295-
class BoundWrapper:
296-
def __init__(self, wrapped):
297-
self.__wrapped__ = wrapped
298-
299-
def __call__(self, *args, **kwargs):
300-
return self.__wrapped__(*args, **kwargs)
301-
302-
class Wrapper:
303-
def __init__(self, wrapped):
304-
self.__wrapped__ = wrapped
305-
306-
def __get__(self, instance, owner):
307-
bound_function = self.__wrapped__.__get__(instance, owner)
308-
return BoundWrapper(bound_function)
309-
310-
def decorator(wrapped):
311-
return Wrapper(wrapped)
312-
313-
class Class:
314-
@decorator
315-
@classmethod
316-
def inner(cls):
317-
# This should already work.
318-
return 'spam'
319-
320-
@classmethod
321-
@decorator
322-
def outer(cls):
323-
# Raised TypeError with a message saying that the 'Wrapper'
324-
# object is not callable.
325-
return 'eggs'
326-
327-
self.assertEqual(Class.inner(), 'spam')
328-
self.assertEqual(Class.outer(), 'eggs')
329-
self.assertEqual(Class().inner(), 'spam')
330-
self.assertEqual(Class().outer(), 'eggs')
331-
332-
# TODO: RUSTPYTHON
333-
@unittest.expectedFailure
294+
@unittest.expectedFailure # TODO: RUSTPYTHON
334295
def test_bound_function_inside_classmethod(self):
335296
class A:
336297
def foo(self, cls):
@@ -341,91 +302,6 @@ class B:
341302

342303
self.assertEqual(B.bar(), 'spam')
343304

344-
def test_wrapped_classmethod_inside_classmethod(self):
345-
class MyClassMethod1:
346-
def __init__(self, func):
347-
self.func = func
348-
349-
def __call__(self, cls):
350-
if hasattr(self.func, '__get__'):
351-
return self.func.__get__(cls, cls)()
352-
return self.func(cls)
353-
354-
def __get__(self, instance, owner=None):
355-
if owner is None:
356-
owner = type(instance)
357-
return MethodType(self, owner)
358-
359-
class MyClassMethod2:
360-
def __init__(self, func):
361-
if isinstance(func, classmethod):
362-
func = func.__func__
363-
self.func = func
364-
365-
def __call__(self, cls):
366-
return self.func(cls)
367-
368-
def __get__(self, instance, owner=None):
369-
if owner is None:
370-
owner = type(instance)
371-
return MethodType(self, owner)
372-
373-
for myclassmethod in [MyClassMethod1, MyClassMethod2]:
374-
class A:
375-
@myclassmethod
376-
def f1(cls):
377-
return cls
378-
379-
@classmethod
380-
@myclassmethod
381-
def f2(cls):
382-
return cls
383-
384-
@myclassmethod
385-
@classmethod
386-
def f3(cls):
387-
return cls
388-
389-
@classmethod
390-
@classmethod
391-
def f4(cls):
392-
return cls
393-
394-
@myclassmethod
395-
@MyClassMethod1
396-
def f5(cls):
397-
return cls
398-
399-
@myclassmethod
400-
@MyClassMethod2
401-
def f6(cls):
402-
return cls
403-
404-
self.assertIs(A.f1(), A)
405-
self.assertIs(A.f2(), A)
406-
self.assertIs(A.f3(), A)
407-
self.assertIs(A.f4(), A)
408-
self.assertIs(A.f5(), A)
409-
self.assertIs(A.f6(), A)
410-
a = A()
411-
self.assertIs(a.f1(), A)
412-
self.assertIs(a.f2(), A)
413-
self.assertIs(a.f3(), A)
414-
self.assertIs(a.f4(), A)
415-
self.assertIs(a.f5(), A)
416-
self.assertIs(a.f6(), A)
417-
418-
def f(cls):
419-
return cls
420-
421-
self.assertIs(myclassmethod(f).__get__(a)(), A)
422-
self.assertIs(myclassmethod(f).__get__(a, A)(), A)
423-
self.assertIs(myclassmethod(f).__get__(A, A)(), A)
424-
self.assertIs(myclassmethod(f).__get__(A)(), type(A))
425-
self.assertIs(classmethod(f).__get__(a)(), A)
426-
self.assertIs(classmethod(f).__get__(a, A)(), A)
427-
self.assertIs(classmethod(f).__get__(A, A)(), A)
428-
self.assertIs(classmethod(f).__get__(A)(), type(A))
429305

430306
class TestClassDecorators(unittest.TestCase):
431307

Lib/test/test_dynamic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import unittest
66

7-
from test.support import swap_item, swap_attr
7+
from test.support import swap_item, swap_attr, is_wasi, Py_DEBUG
88

99

1010
class RebindBuiltinsTests(unittest.TestCase):
@@ -134,8 +134,8 @@ def test_eval_gives_lambda_custom_globals(self):
134134

135135
self.assertEqual(foo(), 7)
136136

137-
# TODO: RUSTPYTHON
138-
@unittest.expectedFailure
137+
@unittest.expectedFailure # TODO: RUSTPYTHON
138+
@unittest.skipIf(is_wasi and Py_DEBUG, "requires too much stack")
139139
def test_load_global_specialization_failure_keeps_oparg(self):
140140
# https://github.com/python/cpython/issues/91625
141141
class MyGlobals(dict):

Lib/test/test_eof.py

Lines changed: 140 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,177 @@
11
"""test script for a few new invalid token catches"""
22

33
import sys
4-
from test import support
4+
from codecs import BOM_UTF8
5+
from test.support import force_not_colorized
56
from test.support import os_helper
67
from test.support import script_helper
78
from test.support import warnings_helper
89
import unittest
910

1011
class EOFTestCase(unittest.TestCase):
11-
# TODO: RUSTPYTHON
12-
@unittest.expectedFailure
12+
@unittest.expectedFailure # TODO: RUSTPYTHON
1313
def test_EOF_single_quote(self):
1414
expect = "unterminated string literal (detected at line 1) (<string>, line 1)"
1515
for quote in ("'", "\""):
16-
try:
16+
with sel 38BA f.assertRaises(SyntaxError) as cm:
1717
eval(f"""{quote}this is a test\
1818
""")
19-
except SyntaxError as msg:
20-
self.assertEqual(str(msg), expect)
21-
self.assertEqual(msg.offset, 1)
22-
else:
23-
raise support.TestFailed
24-
25-
# TODO: RUSTPYTHON
26-
@unittest.expectedFailure
19+
self.assertEqual(str(cm.exception), expect)
20+
self.assertEqual(cm.exception.offset, 1)
21+
22+
@unittest.expectedFailure # TODO: RUSTPYTHON
2723
def test_EOFS(self):
28-
expect = ("unterminated triple-quoted string literal (detected at line 1) (<string>, line 1)")
29-
try:
30-
eval("""'''this is a test""")
31-
except SyntaxError as msg:
32-
self.assertEqual(str(msg), expect)
33-
self.assertEqual(msg.offset, 1)
34-
else:
35-
raise support.TestFailed
36-
37-
# TODO: RUSTPYTHON
38-
@unittest.expectedFailure
24+
expect = ("unterminated triple-quoted string literal (detected at line 3) (<string>, line 1)")
25+
with self.assertRaises(SyntaxError) as cm:
26+
eval("""ä = '''thîs is \na \ntest""")
27+
self.assertEqual(str(cm.exception), expect)
28+
self.assertEqual(cm.exception.text, "ä = '''thîs is ")
29+
self.assertEqual(cm.exception.offset, 5)
30+
31+
with self.assertRaises(SyntaxError) as cm:
32+
eval("""ä = '''thîs is \na \ntest""".encode())
33+
self.assertEqual(str(cm.exception), expect)
34+
self.assertEqual(cm.exception.text, "ä = '''thîs is ")
35+
self.assertEqual(cm.exception.offset, 5)
36+
37+
with self.assertRaises(SyntaxError) as cm:
38+
eval(BOM_UTF8 + """ä = '''thîs is \na \ntest""".encode())
39+
self.assertEqual(str(cm.exception), expect)
40+
self.assertEqual(cm.exception.text, "ä = '''thîs is ")
41+
self.assertEqual(cm.exception.offset, 5)
42+
43+
with self.assertRaises(SyntaxError) as cm:
44+
eval("""# coding: latin1\nä = '''thîs is \na \ntest""".encode('latin1'))
45+
self.assertEqual(str(cm.exception), "unterminated triple-quoted string literal (detected at line 4) (<string>, line 2)")
46+
self.assertEqual(cm.exception.text, "ä = '''thîs is ")
47+
self.assertEqual(cm.exception.offset, 5)
48+
49+
@unittest.expectedFailure # TODO: RUSTPYTHON
50+
@force_not_colorized
3951
def test_EOFS_with_file(self):
4052
expect = ("(<string>, line 1)")
4153
with os_helper.temp_dir() as temp_dir:
42-
file_name = script_helper.make_script(temp_dir, 'foo', """'''this is \na \ntest""")
43-
rc, out, err = script_helper.assert_python_failure(file_name)
44-
self.assertIn(b'unterminated triple-quoted string literal (detected at line 3)', err)
54+
file_name = script_helper.make_script(temp_dir, 'foo',
55+
"""ä = '''thîs is \na \ntest""")
56+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
57+
err = err.decode().splitlines()
58+
self.assertEqual(err[-3:], [
59+
" ä = '''thîs is ",
60+
' ^',
61+
'SyntaxError: unterminated triple-quoted string literal (detected at line 3)'])
62+
63+
file_name = script_helper.make_script(temp_dir, 'foo',
64+
"""ä = '''thîs is \na \ntest""".encode())
65+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
66+
err = err.decode().splitlines()
67+
self.assertEqual(err[-3:], [
68+
" ä = '''thîs is ",
69+
' ^',
70+
'SyntaxError: unterminated triple-quoted string literal (detected at line 3)'])
71+
72+
file_name = script_helper.make_script(temp_dir, 'foo',
73+
BOM_UTF8 + """ä = '''thîs is \na \ntest""".encode())
74+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
75+
err = err.decode().splitlines()
76+
self.assertEqual(err[-3:], [
77+
" ä = '''thîs is ",
78+
' ^',
79+
'SyntaxError: unterminated triple-quoted string literal (detected at line 3)'])
80+
81+
file_name = script_helper.make_script(temp_dir, 'foo',
82+
"""# coding: latin1\nä = '''thîs is \na \ntest""".encode('latin1'))
83+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
84+
err = err.decode().splitlines()
85+
self.assertEqual(err[-3:], [
86+
" ä = '''thîs is ",
87+
' ^',
88+
'SyntaxError: unterminated triple-quoted string literal (detected at line 4)'])
4589

46-
# TODO: RUSTPYTHON
47-
@unittest.expectedFailure
90+
@unittest.expectedFailure # TODO: RUSTPYTHON
4891
@warnings_helper.ignore_warnings(category=SyntaxWarning)
4992
def test_eof_with_line_continuation(self):
5093
expect = "unexpected EOF while parsing (<string>, line 1)"
51-
try:
94+
with self.assertRaises(SyntaxError) as cm:
5295
compile('"\\Xhh" \\', '<string>', 'exec')
53-
except SyntaxError as msg:
54-
self.assertEqual(str(msg), expect)
55-
else:
56-
raise support.TestFailed
96+
self.assertEqual(str(cm.exception), expect)
5797

58-
# TODO: RUSTPYTHON
59-
@unittest.expectedFailure
98+
@unittest.expectedFailure # TODO: RUSTPYTHON
6099
def test_line_continuation_EOF(self):
61100
"""A continuation at the end of input must be an error; bpo2180."""
62101
expect = 'unexpected EOF while parsing (<string>, line 1)'
63-
with self.assertRaises(SyntaxError) as excinfo:
64-
exec('x = 5\\')
65-
self.assertEqual(str(excinfo.exception), expect)
66-
with self.assertRaises(SyntaxError) as excinfo:
102+
with self.assertRaises(SyntaxError) as cm:
103+
exec('ä = 5\\')
104+
self.assertEqual(str(cm.exception), expect)
105+
self.assertEqual(cm.exception.text, 'ä = 5\\\n')
106+
self.assertEqual(cm.exception.offset, 7)
107+
108+
with self.assertRaises(SyntaxError) as cm:
109+
exec('ä = 5\\'.encode())
110+
self.assertEqual(str(cm.exception), expect)
111+
self.assertEqual(cm.exception.text, 'ä = 5\\\n')
112+
self.assertEqual(cm.exception.offset, 7)
113+
114+
with self.assertRaises(SyntaxError) as cm:
115+
exec('# coding:latin1\nä = 5\\'.encode('latin1'))
116+
self.assertEqual(str(cm.exception),
117+
'unexpected EOF while parsing (<string>, line 2)')
118+
self.assertEqual(cm.exception.text, 'ä = 5\\\n')
119+
self.assertEqual(cm.exception.offset, 7)
120+
121+
with self.assertRaises(SyntaxError) as cm:
122+
exec(BOM_UTF8 + 'ä = 5\\'.encode())
123+
self.assertEqual(str(cm.exception), expect)
124+
self.assertEqual(cm.exception.text, 'ä = 5\\\n')
125+
self.assertEqual(cm.exception.offset, 7)
126+
127+
with self.assertRaises(SyntaxError) as cm:
67128
exec('\\')
68-
self.assertEqual(str(excinfo.exception), expect)
129+
self.assertEqual(str(cm.exception), expect)
69130

131+
@unittest.expectedFailure # TODO: RUSTPYTHON
70132
@unittest.skipIf(not sys.executable, "sys.executable required")
133+
@force_not_colorized
71134
def test_line_continuation_EOF_from_file_bpo2180(self):
72135
"""Ensure tok_nextc() does not add too many ending newlines."""
73136
with os_helper.temp_dir() as temp_dir:
74137
file_name = script_helper.make_script(temp_dir, 'foo', '\\')
75-
rc, out, err = script_helper.assert_python_failure(file_name)
76-
self.assertIn(b'unexpected EOF while parsing', err)
77-
self.assertIn(b'line 1', err)
78-
self.assertIn(b'\\', err)
79-
80-
file_name = script_helper.make_script(temp_dir, 'foo', 'y = 6\\')
81-
rc, out, err = script_helper.assert_python_failure(file_name)
82-
self.assertIn(b'unexpected EOF while parsing', err)
83-
self.assertIn(b'line 1', err)
84-
self.assertIn(b'y = 6\\', err)
138+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
139+
err = err.decode().splitlines()
140+
self.assertEqual(err[-2:], [
141+
' \\',
142+
'SyntaxError: unexpected EOF while parsing'])
143+
self.assertEqual(err[-3][-8:], ', line 1', err)
144+
145+
file_name = script_helper.make_script(temp_dir, 'foo', 'ä = 6\\')
146+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
147+
err = err.decode().splitlines()
148+
self.assertEqual(err[-3:], [
149+
' ä = 6\\',
150+
' ^',
151+
'SyntaxError: unexpected EOF while parsing'])
152+
self.assertEqual(err[-4][-8:], ', line 1', err)
153+
154+
file_name = script_helper.make_script(temp_dir, 'foo',
155+
'# coding:latin1\n'
156+
'ä = 7\\'.encode('latin1'))
157+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
158+
err = err.decode().splitlines()
159+
self.assertEqual(err[-3:], [
160+
' ä = 7\\',
161+
' ^',
162+
'SyntaxError: unexpected EOF while parsing'])
163+
self.assertEqual(err[-4][-8:], ', line 2', err)
164+
165+
file_name = script_helper.make_script(temp_dir, 'foo',
166+
BOM_UTF8 + 'ä = 8\\'.encode())
167+
rc, out, err = script_helper.assert_python_failure('-X', 'utf8', file_name)
168+
err = err.decode().splitlines()
169+
self.assertEqual(err[-3:], [
170+
' ä = 8\\',
171+
5455 ' ^',
172+
'SyntaxError: unexpected EOF while parsing'])
173+
self.assertEqual(err[-4][-8:], ', line 1', err)
174+
85175

86176
if __name__ == "__main__":
87177
unittest.main()

0 commit comments

Comments
 (0)
0