Skip to content

Commit 2f7218c

Browse files
committed
Fix cpyext test compiles for fixture files
1 parent 5aa136d commit 2f7218c

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ def compile_module_from_string(c_source: str, name: str):
9696
return compile_module_from_file(name)
9797

9898

99-
def compile_module_from_file(module_name: str):
100-
install_dir = ccompile(None, module_name)
99+
def compile_module_from_file(module_name: str, sibling_to=None):
100+
if sibling_to:
101+
compile_name = str(Path(sibling_to).absolute().parent / module_name)
102+
else:
103+
compile_name = module_name
104+
install_dir = ccompile(None, compile_name)
101105
sys.path.insert(0, install_dir)
102106
try:
103107
cmodule = __import__(module_name)
@@ -113,6 +117,7 @@ def ccompile(self, name, check_duplicate_name=True):
113117
EXT_SUFFIX = sysconfig.get_config_var("EXT_SUFFIX")
114118

115119
source_file = DIR / f'{name}.c'
120+
filename = Path(name).name
116121
file_not_empty(source_file)
117122

118123
# compute checksum of source file
@@ -123,18 +128,18 @@ def ccompile(self, name, check_duplicate_name=True):
123128
m.update(block)
124129
cur_checksum = m.hexdigest()
125130

126-
build_dir = DIR / 'build' / name
131+
build_dir = DIR / 'build' / filename
127132

128133
# see if there is already a checksum file
129-
checksum_file = build_dir / f'{name}{EXT_SUFFIX}.sha256'
134+
checksum_file = build_dir / f'{filename}{EXT_SUFFIX}.sha256'
130135
available_checksum = ""
131136
if checksum_file.exists():
132137
# read checksum file
133138
with open(checksum_file, "r") as f:
134139
available_checksum = f.readline()
135140

136141
# note, the suffix is already a string like '.so'
137-
lib_file = build_dir / f'{name}{EXT_SUFFIX}'
142+
lib_file = build_dir / f'{filename}{EXT_SUFFIX}'
138143

139144
if check_duplicate_name and available_checksum != cur_checksum and name in compiled_registry:
140145
raise RuntimeError(f"\n\nModule with name '{name}' was already compiled, but with different source code. "
@@ -154,7 +159,7 @@ def ccompile(self, name, check_duplicate_name=True):
154159
os.chdir(build_dir)
155160
try:
156161
shutil.copy(source_file, '.')
157-
module = Extension(name, sources=[source_file.name])
162+
module = Extension(filename, sources=[source_file.name])
158163
args = [
159164
'--verbose' if sys.flags.verbose else '--quiet',
160165
'build', '--build-temp=t', '--build-base=b', '--build-purelib=l', '--build-platlib=l',
@@ -163,7 +168,7 @@ def ccompile(self, name, check_duplicate_name=True):
163168
setup(
164169
script_name='setup',
165170
script_args=args,
166-
name=name,
171+
name=filename,
167172
version='1.0',
168173
description='',
169174
ext_modules=[module]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 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
@@ -42,10 +42,10 @@
4242

4343
class TestSimple(CPyExtTestCase):
4444
def test_demo(self):
45-
demo = compile_module_from_file('demo')
45+
demo = compile_module_from_file('demo', __file__)
4646
assert demo.system("echo 1") == 0
4747
assert demo.system("arrrr") != 0
4848

4949
def test_demo2(self):
50-
demo2 = compile_module_from_file('demo2')
50+
demo2 = compile_module_from_file('demo2', __file__)
5151
assert demo2.system("Hello World") == "Hello World from C", demo2.system("Hello World")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ class ManagedDummy(NbAddSqConcatStaticType):
917917
assert SlotsGetter.get_nb_add(ManagedDummy()) == SlotsGetter.get_nb_add(NbAddSqConcatStaticType())
918918

919919
def test_sq_repeat_mul_without_rmul_inheritance():
920-
mod = compile_module_from_file("fuzzer_test10")
920+
mod = compile_module_from_file("fuzzer_test10", __file__)
921921
Native0 = mod.create_Native0((object, ))
922922
class Managed1(Native0):
923923
def __add__(self): return self

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 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
@@ -43,13 +43,13 @@
4343
class TestWiki(CPyExtTestCase):
4444

4545
def test_noddy(self):
46-
noddy = compile_module_from_file('noddy')
46+
noddy = compile_module_from_file('noddy', __file__)
4747
assert type(noddy.Noddy) is type
4848
assert type(noddy.Noddy()) is noddy.Noddy, str(type(noddy.Noddy()))
4949
assert str(noddy.Noddy()).startswith("<noddy.Noddy object at"), str(noddy.Noddy())
5050

5151
def test_noddy2(self):
52-
noddy2 = compile_module_from_file('noddy2')
52+
noddy2 = compile_module_from_file('noddy2', __file__)
5353
nd = noddy2.Noddy2("First", "Last", 42)
5454
assert nd.name() == "'First' 'Last' '42'"
5555
assert nd.first == "First", ("%s != First" % nd.first)
@@ -85,7 +85,7 @@ def test_noddy2(self):
8585
assert nd.n_ulong == 0xffffffffffffffff, ("%s != 0xffffffffffffffff" % nd.n_ulong)
8686

8787
def test_noddy3(self):
88-
noddy3 = compile_module_from_file('noddy3')
88+
noddy3 = compile_module_from_file('noddy3', __file__)
8989
nd = noddy3.Noddy(b"First", b"Last", 42)
9090
assert nd.name() == "b'First' b'Last'", nd.name()
9191
assert nd.first == b"First", ("%s != First" % nd.first)

0 commit comments

Comments
 (0)