Skip to content

Commit 16a9db0

Browse files
committed
Refactor test_wheel
1 parent b63cf46 commit 16a9db0

File tree

9 files changed

+74
-26
lines changed

9 files changed

+74
-26
lines changed

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

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,26 @@
4646
import unittest
4747
from pathlib import Path
4848

49+
from tests.testlib_helper import build_testlib
50+
4951

5052
class TestWheelBuildAndRun(unittest.TestCase):
5153
def test_build_install_and_run(self):
5254
# Build a C library and a wheel that depends on it. Then run it through repair_wheel to vendor the library in and verify that it can be imported
53-
orig_root = (Path(__file__).parent / "example_wheel").resolve()
54-
orig_testwheel = orig_root / "testwheel"
55-
orig_answerlib = orig_root / "answerlib"
55+
orig_root = Path(__file__).parent.resolve()
56+
orig_test_wheel = orig_root / "testwheel"
57+
orig_testlib = orig_root / "testlib"
5658

5759
with tempfile.TemporaryDirectory(prefix="testwheel_tmp_") as tmpdir:
5860
tmpdir = Path(tmpdir)
59-
tmp_testwheel = tmpdir / "testwheel"
60-
tmp_answerlib = tmpdir / "answerlib"
61+
tmp_test_wheel = tmpdir / "testwheel"
6162
venv_dir = tmpdir / "venv"
6263
repair_venv_dir = tmpdir / "repair_venv"
6364
wheel_dir = tmpdir / "wheels"
6465
repaired_dir = tmpdir / "repaired"
6566

66-
shutil.copytree(orig_testwheel, tmp_testwheel)
67-
shutil.copytree(orig_answerlib, tmp_answerlib)
68-
69-
answerlib_build = tmp_answerlib / "build"
70-
if answerlib_build.exists():
71-
shutil.rmtree(answerlib_build)
72-
answerlib_build.mkdir(parents=True, exist_ok=True)
73-
74-
cmd = ["cmake", "-DCMAKE_BUILD_TYPE=Release", ".."]
75-
print("Running:", shlex.join(cmd))
76-
subprocess.check_call(cmd, cwd=str(answerlib_build))
77-
cmd = ["cmake", "--build", ".", "--config", "Release"]
78-
print("Running:", shlex.join(cmd))
79-
subprocess.check_call(cmd, cwd=str(answerlib_build))
67+
shutil.copytree(orig_test_wheel, tmp_test_wheel)
68+
testlib_build = build_testlib(tmpdir, orig_testlib)
8069

8170
cmd = [sys.executable, "-m", "venv", str(venv_dir)]
8271
print("Running:", shlex.join(cmd))
@@ -96,7 +85,7 @@ def test_build_install_and_run(self):
9685
wheel_dir.mkdir(parents=True, exist_ok=True)
9786
cmd = [str(python), "-m", "build", "--wheel", "--outdir", str(wheel_dir)]
9887
print("Running:", shlex.join(cmd))
99-
subprocess.check_call(cmd, cwd=str(tmp_testwheel))
88+
subprocess.check_call(cmd, cwd=str(tmp_test_wheel))
10089

10190
built_wheels = list(wheel_dir.glob("testwheel-*.whl"))
10291
self.assertTrue(built_wheels, "Wheel was not built!")
@@ -117,11 +106,11 @@ def test_build_install_and_run(self):
117106

118107
repair_env = os.environ.copy()
119108
if sys.platform.startswith("linux"):
120-
repair_env["LD_LIBRARY_PATH"] = str(answerlib_build)
109+
repair_env["LD_LIBRARY_PATH"] = str(testlib_build)
121110
elif sys.platform == "darwin":
122-
repair_env["DYLD_LIBRARY_PATH"] = str(answerlib_build)
111+
repair_env["DYLD_LIBRARY_PATH"] = str(testlib_build)
123112
elif sys.platform == "win32":
124-
repair_env["PATH"] = str(answerlib_build) + os.pathsep + repair_env.get("PATH", "")
113+
repair_env["PATH"] = str(testlib_build) + os.pathsep + repair_env.get("PATH", "")
125114
cmd = [
126115
str(python_repair),
127116
str((Path(

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/answerlib/CMakeLists.txt renamed to graalpython/com.oracle.graal.python.test/src/tests/testlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cmake_minimum_required(VERSION 3.5)
2-
project(answerlib C)
2+
project(testlib C)
33
add_library(answer SHARED answer.c)
44
set_target_properties(answer PROPERTIES PUBLIC_HEADER "answer.h")

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/answerlib/answer.c renamed to graalpython/com.oracle.graal.python.test/src/tests/testlib/answer.c

File renamed without changes.

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/answerlib/answer.h renamed to graalpython/com.oracle.graal.python.test/src/tests/testlib/answer.h

File renamed without changes.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import shlex
41+
import shutil
42+
import subprocess
43+
44+
45+
def build_testlib(tmpdir, orig_testlib):
46+
tmp_testlib = tmpdir / "testlib"
47+
shutil.copytree(orig_testlib, tmp_testlib)
48+
testlib_build = tmp_testlib / "build"
49+
if testlib_build.exists():
50+
shutil.rmtree(testlib_build)
51+
testlib_build.mkdir(parents=True, exist_ok=True)
52+
53+
cmd = ["cmake", "-DCMAKE_BUILD_TYPE=Release", ".."]
54+
print("Running:", shlex.join(cmd))
55+
subprocess.check_call(cmd, cwd=str(testlib_build))
56+
cmd = ["cmake", "--build", ".", "--config", "Release"]
57+
print("Running:", shlex.join(cmd))
58+
subprocess.check_call(cmd, cwd=str(testlib_build))
59+
return testlib_build

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/testwheel/pyproject.toml renamed to graalpython/com.oracle.graal.python.test/src/tests/testwheel/pyproject.toml

File renamed without changes.

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/testwheel/setup.py renamed to graalpython/com.oracle.graal.python.test/src/tests/testwheel/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
Extension(
4444
"testwheel.answer",
4545
sources=["testwheel/module.c"],
46-
include_dirs=["../answerlib"],
46+
include_dirs=["../testlib"],
4747
libraries=["answer"],
48-
library_dirs=["../answerlib/build"],
48+
library_dirs=["../testlib/build"],
4949
)
5050
]
5151

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/testwheel/testwheel/__init__.py renamed to graalpython/com.oracle.graal.python.test/src/tests/testwheel/testwheel/__init__.py

File renamed without changes.

graalpython/com.oracle.graal.python.test/src/tests/example_wheel/testwheel/testwheel/module.c renamed to graalpython/com.oracle.graal.python.test/src/tests/testwheel/testwheel/module.c

File renamed without changes.

0 commit comments

Comments
 (0)