Skip to content

Commit 573554c

Browse files
oharboeclaude
andcommitted
test: an issue archive's vars files run on another machine
generate_vars.py writes the archive's vars files, and they have been fixed for running somewhere else: python3 is the default PYTHON_EXE in both the shell and the Tcl vars (#4792), paths under an absolute WORK_HOME are relative to the archive's root while a directory that only starts with WORK_HOME's name keeps its path (#4274), and paths under a docker image's /workspace and /platforms are relative (#3870). PRESERVE_PATHS keeps every path as it is. The tests make an archive and read its vars files. The stub flow moves one level down, so that the stub's WORK_HOME, like a CI workspace, is outside the ORFS root the vars files spell ${FLOW_HOME}/... Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 3b025b2 commit 573554c

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

‎flow/test/test_make_issue.py‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ class StubFlow:
5656
def __init__(self):
5757
self.tmp_dir = tempfile.TemporaryDirectory()
5858
self.tmp = self.tmp_dir.name
59-
self.flow = os.path.join(self.tmp, "flow")
59+
# FLOW_HOME/.. is the ORFS root, which the vars files spell
60+
# ${FLOW_HOME}/..; a WORK_HOME in self.tmp is outside it, as a CI
61+
# workspace is.
62+
self.flow = os.path.join(self.tmp, "orfs", "flow")
6063
self.scripts = os.path.join(self.flow, "scripts")
6164
self.platform_dir = os.path.join(self.flow, "platforms", PLATFORM)
6265
self.design_dir = os.path.join(self.flow, "designs", PLATFORM, NICKNAME)
@@ -448,5 +451,42 @@ def test_a_sibling_of_work_home_keeps_its_path(self):
448451
self.assertIn(f"{STEP}_{TAG}{sibling}", members)
449452

450453

454+
class TestVarsFiles(StubFlowTestCase):
455+
"""The archive's vars files run on another machine: python3 is the
456+
default PYTHON_EXE in both the shell and the Tcl vars (#4792), paths
457+
under an absolute WORK_HOME are relative to the archive's root while
458+
a directory that only starts with WORK_HOME's name keeps its path
459+
(#4274), and paths under a docker image's /workspace and /platforms
460+
are relative too (#3870). PRESERVE_PATHS keeps every path."""
461+
462+
def vars_text(self, work_home, ext, **extra):
463+
root = self.stub.unpack(self.stub.make_issue(work_home, **extra))
464+
with open(self.stub.find(root, f"vars-{FLOW_NAME}.{ext}")) as f:
465+
return f.read()
466+
467+
def test_python_exe_default(self):
468+
self.assertIn(
469+
"export PYTHON_EXE=${PYTHON_EXE:-python3}", self.vars_text(".", "sh")
470+
)
471+
self.assertIn("set env(PYTHON_EXE) python3", self.vars_text(".", "tcl"))
472+
473+
def test_work_home_paths_are_relative(self):
474+
work = os.path.join(self.stub.tmp, "work")
475+
text = self.vars_text(work, "sh", SIBLING=f"{work}_other/x")
476+
self.assertIn(
477+
f'export RESULTS_DIR="./results_dir/{PLATFORM}/{NICKNAME}/{VARIANT}"', text
478+
)
479+
self.assertIn(f'export SIBLING="{work}_other/x"', text)
480+
481+
def test_docker_paths_are_relative(self):
482+
text = self.vars_text(".", "sh", DOCKER_FILE="/workspace/a /platforms/b")
483+
self.assertIn('export DOCKER_FILE="./workspace/a ./platforms/b"', text)
484+
485+
def test_preserve_paths(self):
486+
work = os.path.join(self.stub.tmp, "work")
487+
text = self.vars_text(work, "sh", PRESERVE_PATHS="1")
488+
self.assertIn(f'export RESULTS_DIR="{work}/results_dir/', text)
489+
490+
451491
if __name__ == "__main__":
452492
unittest.main()

0 commit comments

Comments
 (0)