Skip to content

Commit 5ae02b2

Browse files
committed
fix(tests/manifests): enhance run_shell_function to support script and function arguments, update test coverage to reflect changes (#2499)
1 parent 11c437e commit 5ae02b2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/manifests.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,16 @@ def run_shell_function(
276276
self,
277277
shell_script_path: Path,
278278
shell_function_name: str,
279-
args: Iterable[str] = (),
279+
script_args: Iterable[str] = (),
280+
function_args: Iterable[str] = (),
280281
env: dict[str, str] | None = None,
281282
) -> str:
282283
env = env or {}
284+
script_args_str = " ".join(shlex.quote(arg) for arg in script_args)
285+
function_args_str = " ".join(shlex.quote(arg) for arg in function_args)
283286
shell_notebook_id = subprocess.run(
284-
f"""source {shell_script_path} && {shell_function_name} {" ".join(shlex.quote(arg) for arg in args)}""",
287+
# set temporary positional parameters for the `source`ing
288+
f"""set -- {script_args_str} && source {shell_script_path} && set -- && {shell_function_name} {function_args_str}""",
285289
shell=True,
286290
executable="/bin/bash",
287291
env=env,
@@ -300,6 +304,7 @@ def get_targets() -> Generator[tuple[str, Path], None, None]:
300304
python_311 = gen_gha_matrix_jobs.extract_image_targets(ROOT_DIR, env={"RELEASE_PYTHON_VERSION": "3.11"})
301305
python_312 = gen_gha_matrix_jobs.extract_image_targets(ROOT_DIR, env={"RELEASE_PYTHON_VERSION": "3.12"})
302306
targets = python_311 + python_312
307+
# TODO(jdanek): this is again duplicating knowledge, but, what can I do?
303308
expected_manifest_paths = {
304309
"jupyter-minimal-ubi9-python-3.12": ROOT_DIR / "manifests/base/jupyter-minimal-notebook-imagestream.yaml",
305310
"runtime-minimal-ubi9-python-3.12": ROOT_DIR / "manifests/base/jupyter-minimal-notebook-imagestream.yaml",
@@ -354,13 +359,15 @@ def test_compare_with_shell_implementation(self, target: str, expected_manifest_
354359
notebook_id = self.run_shell_function(
355360
shell_script_path,
356361
"_get_notebook_id",
362+
script_args=[target],
357363
env={"notebook_workload_name": target},
358364
)
359365
assert notebook_id
360366

361367
source_of_truth_filepath = self.run_shell_function(
362368
shell_script_path,
363369
"_get_source_of_truth_filepath",
364-
[notebook_id],
370+
script_args=[target],
371+
function_args=[notebook_id],
365372
)
366373
assert source_of_truth_filepath == str(expected_manifest_path)

0 commit comments

Comments
 (0)