Skip to content

Commit c283650

Browse files
committed
more tests for python home config in test_standalone
1 parent e12140d commit c283650

File tree

2 files changed

+79
-17
lines changed

2 files changed

+79
-17
lines changed

graalpython/com.oracle.graal.python.test/src/tests/standalone/check_home_pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,7 @@ SOFTWARE.
7373
<executions>
7474
<execution>
7575
<configuration>
76-
<pythonHome>
77-
<includes>
78-
<include>.*__init__\.py</include>
79-
</includes>
80-
<excludes>
81-
<exclude>.*html/__init__\.py</exclude>
82-
</excludes>
83-
</pythonHome>
76+
8477
</configuration>
8578
<goals>
8679
<goal>process-graalpy-resources</goal>

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

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,7 @@ def test_gen_launcher_and_venv(self):
265265
util.check_ouput("termcolor", out, False)
266266

267267
# remove ujson pkg from plugin config and check if unistalled
268-
with open(os.path.join(target_dir, "pom.xml"), "r") as f:
269-
contents = f.read()
270-
271-
with open(os.path.join(target_dir, "pom.xml"), "w") as f:
272-
f.write(contents.replace("<package>ujson</package>", ""))
268+
replace_in_file(os.path.join(target_dir, "pom.xml"), "<package>ujson</package>", "")
273269

274270
cmd = mvnw_cmd + ["process-resources"]
275271
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
@@ -278,6 +274,11 @@ def test_gen_launcher_and_venv(self):
278274
util.check_ouput("Uninstalling ujson", out)
279275
util.check_ouput("termcolor", out, False)
280276

277+
def check_tagfile(self, target_dir, expected):
278+
with open(os.path.join(target_dir, "target", "classes", VFS_PREFIX, "home", "tagfile")) as f:
279+
lines = f.readlines()
280+
assert lines == expected, "expected tagfile " + str(expected) + ", but got " + str(lines)
281+
281282
@unittest.skipUnless(is_enabled, "ENABLE_STANDALONE_UNITTESTS is not true")
282283
def test_check_home(self):
283284
with tempfile.TemporaryDirectory() as tmpdir:
@@ -288,17 +289,85 @@ def test_check_home(self):
288289

289290
mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
290291

291-
cmd = mvnw_cmd + ["process-resources"]
292-
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
292+
# 1. process-resources with no pythonHome config
293+
process_resources_cmd = mvnw_cmd + ["process-resources"]
294+
out, return_code = util.run_cmd(process_resources_cmd, self.env, cwd=target_dir)
295+
util.check_ouput("BUILD SUCCESS", out)
296+
util.check_ouput("Copying std lib to ", out)
297+
298+
home_dir = os.path.join(target_dir, "target", "classes", VFS_PREFIX, "home")
299+
assert os.path.exists(home_dir)
300+
assert os.path.exists(os.path.join(home_dir, "lib-graalpython"))
301+
assert os.path.isdir(os.path.join(home_dir, "lib-graalpython"))
302+
assert os.path.exists(os.path.join(home_dir, "lib-python"))
303+
assert os.path.isdir(os.path.join(home_dir, "lib-python"))
304+
assert os.path.exists(os.path.join(home_dir, "tagfile"))
305+
assert os.path.isfile(os.path.join(home_dir, "tagfile"))
306+
self.check_tagfile(target_dir, [f'{self.graalvmVersion}\n', 'include:.*\n'])
307+
308+
# 2. process-resources with empty pythonHome includes and excludes
309+
shutil.copyfile(pom_template, os.path.join(target_dir, "pom.xml"))
310+
util.patch_pom_repositories(os.path.join(target_dir, "pom.xml"))
311+
replace_in_file(os.path.join(target_dir, "pom.xml"), "</configuration>", "<pythonHome></pythonHome></configuration>")
312+
out, return_code = util.run_cmd(process_resources_cmd, self.env, cwd=target_dir)
313+
util.check_ouput("BUILD SUCCESS", out)
314+
util.check_ouput("Copying std lib to ", out, False)
315+
self.check_tagfile(target_dir, [f'{self.graalvmVersion}\n', 'include:.*\n'])
293316

294-
# check fileslist.txt
317+
shutil.copyfile(pom_template, os.path.join(target_dir, "pom.xml"))
318+
util.patch_pom_repositories(os.path.join(target_dir, "pom.xml"))
319+
replace_in_file(os.path.join(target_dir, "pom.xml"), "</configuration>", "<pythonHome><includes></includes><excludes></excludes></pythonHome></configuration>")
320+
out, return_code = util.run_cmd(process_resources_cmd, self.env, cwd=target_dir)
321+
util.check_ouput("BUILD SUCCESS", out)
322+
util.check_ouput("Copying std lib to ", out, False)
323+
self.check_tagfile(target_dir, [f'{self.graalvmVersion}\n', 'include:.*\n'])
324+
325+
shutil.copyfile(pom_template, os.path.join(target_dir, "pom.xml"))
326+
util.patch_pom_repositories(os.path.join(target_dir, "pom.xml"))
327+
home_tag = """
328+
<pythonHome>
329+
<includes>
330+
<include></include>
331+
<include> </include>
332+
</includes>
333+
<excludes>
334+
<exclude></exclude>
335+
<exclude> </exclude>
336+
</excludes>
337+
</pythonHome>
338+
"""
339+
replace_in_file(os.path.join(target_dir, "pom.xml"), "</configuration>", home_tag + "</configuration>")
340+
out, return_code = util.run_cmd(process_resources_cmd, self.env, cwd=target_dir)
341+
util.check_ouput("BUILD SUCCESS", out)
342+
util.check_ouput("Copying std lib to ", out, False)
343+
self.check_tagfile(target_dir, [f'{self.graalvmVersion}\n', 'include:.*\n'])
344+
345+
# 3. process-resources with pythonHome includes and excludes
346+
home_tag = """
347+
<pythonHome>
348+
<includes>
349+
<include>.*__init__\.py</include>
350+
</includes>
351+
<excludes>
352+
<exclude>.*html/__init__\.py</exclude>
353+
</excludes>
354+
</pythonHome>
355+
"""
356+
replace_in_file(os.path.join(target_dir, "pom.xml"), "</configuration>", home_tag + "</configuration>")
357+
out, return_code = util.run_cmd(process_resources_cmd, self.env, cwd=target_dir)
358+
util.check_ouput("BUILD SUCCESS", out)
359+
util.check_ouput("Deleting GraalPy home due to changed includes or excludes", out)
360+
util.check_ouput("Copying std lib to ", out)
361+
self.check_tagfile(target_dir, [f'{self.graalvmVersion}\n', 'include:.*__init__\\.py\n', 'exclude:.*html/__init__\\.py\n'])
362+
363+
# 4. check fileslist.txt
295364
fl_path = os.path.join(target_dir, "target", "classes", VFS_PREFIX, "fileslist.txt")
296365
with open(fl_path) as f:
297366
for line in f:
298367
line = f.readline()
299368
# string \n
300369
line = line[:len(line)-1]
301-
if line.endswith("/") or line == "/" + VFS_PREFIX + "/home/tagfile" or line == "/" + VFS_PREFIX + "/proj/hello.py":
370+
if not line.startswith("/" + VFS_PREFIX + "/home/") or line.endswith("/"):
302371
continue
303372
assert line.endswith("/__init__.py")
304373
assert not line.endswith("html/__init__.py")

0 commit comments

Comments
 (0)