Skip to content

Commit cb6b37b

Browse files
committed
[GR-38700] GraalPy Python unit tests: dedicated helpers to ignore Bytecode DSL/Manual interpreter tests.
PullRequest: graalpython/4140
2 parents f131453 + d9e96e3 commit cb6b37b

File tree

9 files changed

+95
-78
lines changed

9 files changed

+95
-78
lines changed

graalpython/com.oracle.graal.python.test/src/tests/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ def get_setuptools(setuptools='setuptools==67.6.1'):
7777
py_executable = setuptools_path / 'Scripts' / 'python.exe'
7878
else:
7979
py_executable = setuptools_path / 'bin' / 'python3'
80-
extra_args = []
81-
if sys.implementation.name == "graalpy" and not system_python and __graalpython__.is_bytecode_dsl_interpreter:
82-
extra_args = ['--vm.Dpython.EnableBytecodeDSLInterpreter=true']
83-
subprocess.run([py_executable, *extra_args, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True)
80+
subprocess.run([py_executable, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True)
8481
print('setuptools is installed in %s' % setuptools_path)
8582

8683
pyvenv_site = str(setuptools_path)

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -51,8 +51,8 @@
5151
ARGS = []
5252
if sys.implementation.name == 'graalpy':
5353
ARGS = ['--experimental-options', '--python.EnableDebuggingBuiltins']
54-
if not __graalpython__.is_native and __graalpython__.is_bytecode_dsl_interpreter:
55-
ARGS += ['--vm.Dpython.EnableBytecodeDSLInterpreter=true']
54+
if not __graalpython__.is_native:
55+
ARGS += [f'--vm.Dpython.EnableBytecodeDSLInterpreter={str(__graalpython__.is_bytecode_dsl_interpreter).lower()}']
5656
COMMAND = [sys.executable, *ARGS, str(MODULE_PATH)]
5757

5858

graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
# SOFTWARE.
3939
import os
4040
import sys
41-
41+
from tests import util
4242

4343
# IMPORTANT: DO NOT MOVE!
4444
# This test checks that lineno works on frames,
4545
# it MUST stay on this line!
4646
def test_lineno():
4747
assert sys._getframe(0).f_lineno == 47
4848

49-
if not os.environ.get('BYTECODE_DSL_INTERPRETER'): # Blocked by GR-61955
49+
if not util.IS_BYTECODE_DSL: # Blocked by GR-61955
5050
# IMPORTANT: DO NOT MOVE!
5151
def test_nested_lineno():
5252
def test_nested():

graalpython/com.oracle.graal.python.test/src/tests/test_generators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import os
88
import unittest
9+
from tests import util
910

1011

1112
class ExceptionTest(unittest.TestCase):
@@ -557,7 +558,7 @@ def gen():
557558
assert f.f_globals is globals()
558559
assert f.f_locals == {'a': 1, 'b': 2, 'c': 3}
559560
# TODO GR-61955
560-
if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter:
561+
if not util.IS_BYTECODE_DSL:
561562
assert f.f_lineno == gen.__code__.co_firstlineno + 5
562563
assert not g.gi_frame
563564

@@ -591,7 +592,7 @@ def gen():
591592
assert f.f_globals is globals()
592593
assert f.f_locals == {'a': 1, 'b': 2}
593594
# TODO GR-61955
594-
if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter:
595+
if not util.IS_BYTECODE_DSL:
595596
assert f.f_lineno == gen.__code__.co_firstlineno + 3
596597

597598

graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import doctest
4242
import sys
4343
import unittest
44+
from tests import util
4445

4546

4647
# Copied from test_doctest
@@ -69,8 +70,6 @@ def __exit__(self, *exc):
6970
if self.orig_trace:
7071
sys.settrace(self.orig_trace)
7172

72-
73-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing")
7473
def doctest_pdb_locals():
7574
"""
7675
Test that locals get synced after breakpoint
@@ -101,63 +100,61 @@ def doctest_pdb_locals():
101100
"""
102101

103102

104-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing")
105-
def doctest_pdb_locals_generator():
106-
"""
107-
Test that locals get synced after breakpoint in a generator
108-
109-
>>> def test_function():
110-
... a = 1
111-
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
112-
... a = 2
113-
... yield
114-
115-
>>> with PdbTestInput([
116-
... 'p a',
117-
... 'next',
118-
... 'p a',
119-
... 'continue',
120-
... ]):
121-
... next(test_function())
122-
> <doctest tests.test_pdb.doctest_pdb_locals_generator[0]>(4)test_function()
123-
-> a = 2
124-
(Pdb) p a
125-
1
126-
(Pdb) next
127-
> <doctest tests.test_pdb.doctest_pdb_locals_generator[0]>(5)test_function()
128-
-> yield
129-
(Pdb) p a
130-
2
131-
(Pdb) continue
132-
"""
133-
134-
135-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing")
136-
def doctest_pdb_locals_sync_back():
137-
"""
138-
Test that locals set by debugger get propagated back into the frame.
139-
140-
>>> def test_function():
141-
... foo = 1
142-
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
143-
... return foo
144-
145-
>>> with PdbTestInput([
146-
... 'p foo',
147-
... 'foo = 5',
148-
... 'continue',
149-
... ]):
150-
... print(test_function())
151-
> <doctest tests.test_pdb.doctest_pdb_locals_sync_back[0]>(4)test_function()
152-
-> return foo
153-
(Pdb) p foo
154-
1
155-
(Pdb) foo = 5
156-
(Pdb) continue
157-
5
158-
"""
103+
if not util.IS_BYTECODE_DSL:
104+
def doctest_pdb_locals_generator():
105+
"""
106+
Test that locals get synced after breakpoint in a generator
107+
108+
>>> def test_function():
109+
... a = 1
110+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
111+
... a = 2
112+
... yield
113+
114+
>>> with PdbTestInput([
115+
... 'p a',
116+
... 'next',
117+
... 'p a',
118+
... 'continue',
119+
... ]):
120+
... next(test_function())
121+
> <doctest tests.test_pdb.doctest_pdb_locals_generator[0]>(4)test_function()
122+
-> a = 2
123+
(Pdb) p a
124+
1
125+
(Pdb) next
126+
> <doctest tests.test_pdb.doctest_pdb_locals_generator[0]>(5)test_function()
127+
-> yield
128+
(Pdb) p a
129+
2
130+
(Pdb) continue
131+
"""
132+
133+
134+
def doctest_pdb_locals_sync_back():
135+
"""
136+
Test that locals set by debugger get propagated back into the frame.
137+
138+
>>> def test_function():
139+
... foo = 1
140+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
141+
... return foo
142+
143+
>>> with PdbTestInput([
144+
... 'p foo',
145+
... 'foo = 5',
146+
... 'continue',
147+
... ]):
148+
... print(test_function())
149+
> <doctest tests.test_pdb.doctest_pdb_locals_sync_back[0]>(4)test_function()
150+
-> return foo
151+
(Pdb) p foo
152+
1
153+
(Pdb) foo = 5
154+
(Pdb) continue
155+
5
156+
"""
159157

160158

161-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing")
162159
def test_run_doctests():
163160
doctest.testmod(sys.modules[__name__], raise_on_error=True)

graalpython/com.oracle.graal.python.test/src/tests/test_repl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import sys
4646
import tempfile
4747
import unittest
48+
from tests import util
4849
from dataclasses import dataclass
4950
from textwrap import dedent
5051

@@ -191,7 +192,7 @@ def test_continuation():
191192
'''))
192193

193194

194-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: <interactive> vs <module> in traceback")
195+
@util.skipIfBytecodeDSL("TODO: <interactive> vs <module> in traceback")
195196
def test_exceptions():
196197
validate_repl(dedent("""\
197198
>>> 1 / 0

graalpython/com.oracle.graal.python.test/src/tests/test_venv.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ def test_venv_launcher(self):
8383
assert f"Hello {tmpfile}" in out, out
8484
assert f'Original "{sys.executable}"' in out, out
8585

86-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: issue with passing Bytecode DSL flag to subprocesses")
8786
def test_create_and_use_basic_venv(self):
8887
run = None
8988
run_output = ''
9089
try:
91-
subprocess.check_output([sys.executable, "-m", "venv", self.env_dir, "--without-pip"], stderr=subprocess.STDOUT)
90+
extra_args = []
91+
if sys.implementation.name == "graalpy":
92+
extra_args = [f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}']
93+
subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", self.env_dir, "--without-pip"], stderr=subprocess.STDOUT)
9294
run = subprocess.getoutput(f"{self.env_dir}/{BINDIR}/python{EXESUF} -m site")
9395
except subprocess.CalledProcessError as err:
9496
if err.output:
@@ -98,12 +100,14 @@ def test_create_and_use_basic_venv(self):
98100
if sys.platform != 'win32':
99101
assert self.env_dir in run, run
100102

101-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: issue with passing Bytecode DSL flag to subprocesses")
102103
def test_create_and_use_venv_with_pip(self):
103104
run = None
104105
msg = ''
105106
try:
106-
subprocess.check_output([sys.executable, "-m", "venv", self.env_dir2], stderr=subprocess.STDOUT)
107+
extra_args = []
108+
if sys.implementation.name == "graalpy":
109+
extra_args = [f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}']
110+
subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", self.env_dir2], stderr=subprocess.STDOUT)
107111
run = subprocess.getoutput(f"{self.env_dir2}/{BINDIR}/python{EXESUF} -m pip list")
108112
except subprocess.CalledProcessError as err:
109113
if err.output:

graalpython/com.oracle.graal.python.test/src/tests/util.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -37,6 +37,24 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939
import sys
40+
import unittest
41+
42+
IS_BYTECODE_DSL = sys.implementation.name == 'graalpy' and __graalpython__.is_bytecode_dsl_interpreter
43+
44+
def skipIfBytecodeDSL(reason=''):
45+
def wrapper(test):
46+
if IS_BYTECODE_DSL:
47+
return unittest.skip(f"Skipped on Bytecode DSL interpreter. {reason}")(test)
48+
return test
49+
return wrapper
50+
51+
52+
def skipUnlessBytecodeDSL(reason=''):
53+
def wrapper(test):
54+
if sys.implementation.name == 'graalpy' and not __graalpython__.is_bytecode_dsl_interpreter:
55+
return unittest.skip(f"Skipped on manual interpreter. {reason}")(test)
56+
return test
57+
return wrapper
4058

4159

4260
def storage_to_native(s):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,11 +3607,10 @@ public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int in
36073607
@Specialization(replaces = "doObject")
36083608
public static Object doObjectOrUnbound(VirtualFrame frame, LocalAccessor accessor, int index,
36093609
@Bind BytecodeNode bytecodeNode) {
3610-
try {
3611-
return accessor.getObject(bytecodeNode, frame);
3612-
} catch (FrameSlotTypeException e) {
3610+
if (accessor.isCleared(bytecodeNode, frame)) {
36133611
throw raiseUnbound(bytecodeNode, index);
36143612
}
3613+
return accessor.getObject(bytecodeNode, frame);
36153614
}
36163615
}
36173616

0 commit comments

Comments
 (0)