Skip to content

Commit 7c20b30

Browse files
committed
[GR-58523] Improve and refactor test_standalone.
PullRequest: graalpython/3546
2 parents 37d145d + 87ba7a4 commit 7c20b30

File tree

7 files changed

+1034
-939
lines changed

7 files changed

+1034
-939
lines changed

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py

Lines changed: 550 additions & 0 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
import subprocess
4545
import tempfile
4646
import unittest
47-
import pathlib
48-
import util
4947
import time
48+
from tests.standalone import util
5049

5150
is_enabled = 'ENABLE_JBANG_INTEGRATION_UNITTESTS' in os.environ and os.environ['ENABLE_JBANG_INTEGRATION_UNITTESTS'] == "true"
5251
MAVEN_REPO_LOCAL_URL = os.environ.get('org.graalvm.maven.downloader.repository')

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py

Lines changed: 358 additions & 0 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_standalone.py

Lines changed: 5 additions & 917 deletions
Large diffs are not rendered by default.

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

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,95 @@
3838
# SOFTWARE.
3939

4040
import os
41-
import shutil
4241
import subprocess
4342
import sys
43+
import unittest
44+
import urllib.parse
45+
import shutil
4446

4547
MAVEN_VERSION = "3.9.8"
48+
GLOBAL_MVN_CMD = [shutil.which('mvn'), "--batch-mode"]
49+
4650
GRADLE_VERSION = "8.9"
4751

52+
VFS_PREFIX = "org.graalvm.python.vfs"
53+
54+
is_maven_plugin_test_enabled = 'ENABLE_MAVEN_PLUGIN_UNITTESTS' in os.environ and os.environ['ENABLE_MAVEN_PLUGIN_UNITTESTS'] == "true"
55+
is_gradle_plugin_test_enabled = 'ENABLE_GRADLE_PLUGIN_UNITTESTS' in os.environ and os.environ['ENABLE_GRADLE_PLUGIN_UNITTESTS'] == "true"
56+
57+
class PolyglotAppTestBase(unittest.TestCase):
58+
def setUpClass(self):
59+
if not is_maven_plugin_test_enabled and not is_gradle_plugin_test_enabled:
60+
return
61+
62+
self.env = os.environ.copy()
63+
self.env["PYLAUNCHER_DEBUG"] = "1"
64+
65+
self.archetypeGroupId = "org.graalvm.python"
66+
self.archetypeArtifactId = "graalpy-archetype-polyglot-app"
67+
self.pluginArtifactId = "graalpy-maven-plugin"
68+
self.graalvmVersion = get_graalvm_version()
69+
70+
for custom_repo in os.environ.get("MAVEN_REPO_OVERRIDE", "").split(","):
71+
url = urllib.parse.urlparse(custom_repo)
72+
if url.scheme == "file":
73+
jar = os.path.join(
74+
url.path,
75+
self.archetypeGroupId.replace(".", os.path.sep),
76+
self.archetypeArtifactId,
77+
self.graalvmVersion,
78+
f"{self.archetypeArtifactId}-{self.graalvmVersion}.jar",
79+
)
80+
pom = os.path.join(
81+
url.path,
82+
self.archetypeGroupId.replace(".", os.path.sep),
83+
self.archetypeArtifactId,
84+
self.graalvmVersion,
85+
f"{self.archetypeArtifactId}-{self.graalvmVersion}.pom",
86+
)
87+
cmd = GLOBAL_MVN_CMD + [
88+
"install:install-file",
89+
f"-Dfile={jar}",
90+
f"-DgroupId={self.archetypeGroupId}",
91+
f"-DartifactId={self.archetypeArtifactId}",
92+
f"-Dversion={self.graalvmVersion}",
93+
"-Dpackaging=jar",
94+
f"-DpomFile={pom}",
95+
"-DcreateChecksum=true",
96+
]
97+
out, return_code = run_cmd(cmd, self.env)
98+
assert return_code == 0
99+
100+
jar = os.path.join(
101+
url.path,
102+
self.archetypeGroupId.replace(".", os.path.sep),
103+
self.pluginArtifactId,
104+
self.graalvmVersion,
105+
f"{self.pluginArtifactId}-{self.graalvmVersion}.jar",
106+
)
107+
108+
pom = os.path.join(
109+
url.path,
110+
self.archetypeGroupId.replace(".", os.path.sep),
111+
self.pluginArtifactId,
112+
self.graalvmVersion,
113+
f"{self.pluginArtifactId}-{self.graalvmVersion}.pom",
114+
)
115+
116+
cmd = GLOBAL_MVN_CMD + [
117+
"install:install-file",
118+
f"-Dfile={jar}",
119+
f"-DgroupId={self.archetypeGroupId}",
120+
f"-DartifactId={self.pluginArtifactId}",
121+
f"-Dversion={self.graalvmVersion}",
122+
"-Dpackaging=jar",
123+
f"-DpomFile={pom}",
124+
"-DcreateChecksum=true",
125+
]
126+
out, return_code = run_cmd(cmd, self.env)
127+
assert return_code == 0
128+
break
129+
48130
def run_cmd(cmd, env, cwd=None, print_out=False, gradle=False):
49131
out = []
50132
out.append(f"Executing:\n {cmd=}\n")
@@ -190,4 +272,17 @@ def replace_in_file(file, str, replace_str):
190272
contents = f.read()
191273
assert str in contents
192274
with open(file, "w") as f:
193-
f.write(contents.replace(str, replace_str))
275+
f.write(contents.replace(str, replace_str))
276+
277+
def patch_properties_file(properties_file, distribution_url_override):
278+
if distribution_url_override:
279+
new_lines = []
280+
with(open(properties_file)) as f:
281+
while line := f.readline():
282+
line.strip()
283+
if not line.startswith("#") and "distributionUrl" in line:
284+
new_lines.append(f"distributionUrl={distribution_url_override}\n")
285+
else:
286+
new_lines.append(line)
287+
with(open(properties_file, "w")) as f:
288+
f.writelines(new_lines)

graalpython/org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs/VFSUtils.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -405,24 +405,26 @@ public static void createVenv(Path venvDirectory, List<String> packages, Path la
405405
trim(packages);
406406
}
407407

408-
checkLauncher(venvDirectory, launcherPath, log);
409-
410-
var tag = venvDirectory.resolve("contents");
411408
List<String> installedPackages = new ArrayList<>();
409+
var tag = venvDirectory.resolve("contents");
412410

413-
if (Files.isReadable(tag)) {
414-
List<String> lines = null;
415-
try {
416-
lines = Files.readAllLines(tag);
417-
} catch (IOException e) {
418-
throw new IOException(String.format("failed to read tag file %s", tag), e);
419-
}
420-
if (lines.isEmpty() || !graalPyVersion.equals(lines.get(0))) {
421-
log.info(String.format("Stale GraalPy venv, updating to %s", graalPyVersion));
422-
delete(venvDirectory);
423-
} else {
424-
for (int i = 1; i < lines.size(); i++) {
425-
installedPackages.add(lines.get(i));
411+
if (Files.exists(venvDirectory)) {
412+
checkLauncher(venvDirectory, launcherPath, log);
413+
414+
if (Files.isReadable(tag)) {
415+
List<String> lines = null;
416+
try {
417+
lines = Files.readAllLines(tag);
418+
} catch (IOException e) {
419+
throw new IOException(String.format("failed to read tag file %s", tag), e);
420+
}
421+
if (lines.isEmpty() || !graalPyVersion.equals(lines.get(0))) {
422+
log.info(String.format("Stale GraalPy venv, updating to %s", graalPyVersion));
423+
delete(venvDirectory);
424+
} else {
425+
for (int i = 1; i < lines.size(); i++) {
426+
installedPackages.add(lines.get(i));
427+
}
426428
}
427429
}
428430
}

mx.graalpython/mx_graalpython.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,8 @@ def graalpython_gate_runner(args, tasks):
15391539
env['GRADLE_JAVA_HOME'] = env.get('JAVA_HOME')
15401540

15411541
env['ENABLE_STANDALONE_UNITTESTS'] = 'true'
1542-
env['ENABLE_GRADLE_STANDALONE_UNITTESTS'] = 'true'
1542+
env['ENABLE_GRADLE_PLUGIN_UNITTESTS'] = 'true'
1543+
env['ENABLE_MAVEN_PLUGIN_UNITTESTS'] = 'true'
15431544
env['ENABLE_JBANG_INTEGRATION_UNITTESTS'] ='true'
15441545
env['JAVA_HOME'] = gvm_jdk
15451546
env['PYTHON_STANDALONE_HOME'] = standalone_home
@@ -1571,7 +1572,9 @@ def graalpython_gate_runner(args, tasks):
15711572
mx.logv(f"running with os.environ extended with: {env=}")
15721573
mx.run([sys.executable, _graalpytest_driver(), "-v",
15731574
"graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py",
1574-
"graalpython/com.oracle.graal.python.test/src/tests/standalone/test_standalone.py"], env=env)
1575+
"graalpython/com.oracle.graal.python.test/src/tests/standalone/test_standalone.py",
1576+
"graalpython/com.oracle.graal.python.test/src/tests/standalone/test_maven_plugin.py",
1577+
"graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py"], env=env)
15751578

15761579
with Task('GraalPython Python tests', tasks, tags=[GraalPythonTags.tagged]) as task:
15771580
if task:

0 commit comments

Comments
 (0)