Update test_code.py code.py from CPython v3.11.

This commit is contained in:
zhangbl authored and Jeong YunWon committed 2023-08-27 02:13:11 +09:00
1 parent d5a62848dd
commit 0fbe57f96b
2 files changed
+40 -18

No files matched your search

Vendored
+3 -2
View File
@@ -7,7 +7,6 @@
import sys
import traceback
import argparse
from codeop import CommandCompiler, compile_command
__all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
@@ -41,7 +40,7 @@ class InteractiveInterpreter:
Arguments are as for compile_command().
One several things can happen:
One of several things can happen:
1) The input is incorrect; compile_command() raised an
exception (SyntaxError or OverflowError). A syntax traceback
@@ -303,6 +302,8 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None):
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-q', action='store_true',
help="don't print version and copyright messages")
+37 -16
View File
@@ -139,13 +139,14 @@ import doctest
import unittest
import textwrap
import weakref
import dis
try:
import ctypes
except ImportError:
ctypes = None
from test.support import (cpython_only,
check_impl_detail,
check_impl_detail, requires_debug_ranges,
gc_collect)
from test.support.script_helper import assert_python_ok
from test.support import threading_helper
@@ -165,9 +166,8 @@ def consts(t):
def dump(co):
"""Print out a text representation of a code object."""
for attr in ["name", "argcount", "posonlyargcount",
"kwonlyargcount", "names", "varnames",]:
# TODO: RUSTPYTHON
# "cellvars","freevars", "nlocals", "flags"]:
"kwonlyargcount", "names", "varnames",
"cellvars", "freevars", "nlocals", "flags"]:
print("%s: %s" % (attr, getattr(co, "co_" + attr)))
print("consts:", tuple(consts(co.co_consts)))
@@ -357,18 +357,6 @@ class CodeTest(unittest.TestCase):
new_code = code = func.__code__.replace(co_linetable=b'')
self.assertEqual(list(new_code.co_lines()), [])
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_invalid_bytecode(self):
def foo(): pass
foo.__code__ = co = foo.__code__.replace(co_code=b'\xee\x00d\x00S\x00')
with self.assertRaises(SystemError) as se:
foo()
self.assertEqual(
f"{co.co_filename}:{co.co_firstlineno}: unknown opcode 238",
str(se.exception))
# TODO: RUSTPYTHON
@unittest.expectedFailure
# @requires_debug_ranges()
@@ -717,6 +705,38 @@ class CodeLocationTest(unittest.TestCase):
self.check_lines(misshappen)
self.check_lines(bug93662)
@cpython_only
def test_code_new_empty(self):
# If this test fails, it means that the construction of PyCode_NewEmpty
# needs to be modified! Please update this test *and* PyCode_NewEmpty,
# so that they both stay in sync.
def f():
pass
PY_CODE_LOCATION_INFO_NO_COLUMNS = 13
f.__code__ = f.__code__.replace(
co_firstlineno=42,
co_code=bytes(
[
dis.opmap["RESUME"], 0,
dis.opmap["LOAD_ASSERTION_ERROR"], 0,
dis.opmap["RAISE_VARARGS"], 1,
]
),
co_linetable=bytes(
[
(1 << 7)
| (PY_CODE_LOCATION_INFO_NO_COLUMNS << 3)
| (3 - 1),
0,
]
),
)
self.assertRaises(AssertionError, f)
self.assertEqual(
list(f.__code__.co_positions()),
3 * [(42, 42, None, None)],
)
if check_impl_detail(cpython=True) and ctypes is not None:
py = ctypes.pythonapi
@@ -811,6 +831,7 @@ if check_impl_detail(cpython=True) and ctypes is not None:
tt.join()
self.assertEqual(LAST_FREED, 500)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests