Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion merlin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ def needs_merlin_expansion(cmd: str, restart_cmd: str, labels: List[str], includ
"""
sample_keywords = ["MERLIN_SAMPLE_ID", "MERLIN_SAMPLE_PATH", "merlin_sample_id", "merlin_sample_path"]
if include_sample_keywords:
labels += sample_keywords
# Not `labels +=`, which extends the caller's list in place.
labels = labels + sample_keywords

for label in labels:
if f"$({label})" in cmd:
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/utils/test_needs_merlin_expansion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
##############################################################################
# Copyright (c) Lawrence Livermore National Security, LLC and other Merlin
# Project developers. See top-level LICENSE and COPYRIGHT files for dates and
# other details. No copyright assignment is required to contribute to Merlin.
##############################################################################

from merlin.utils import needs_merlin_expansion


def test_does_not_modify_the_labels_it_was_given() -> None:
"""The caller's list is read, not extended with the sample keywords."""
labels = ["X", "Y"]

needs_merlin_expansion("echo $(X)", "", labels)

assert labels == ["X", "Y"]


def test_sample_keywords_are_still_matched() -> None:
assert needs_merlin_expansion("echo $(MERLIN_SAMPLE_ID)", "", ["X"])
assert not needs_merlin_expansion("echo $(MERLIN_SAMPLE_ID)", "", ["X"], include_sample_keywords=False)


def test_repeated_calls_keep_the_same_answer() -> None:
labels = ["X"]

for _ in range(3):
assert not needs_merlin_expansion("echo $(Z)", "", labels)

assert labels == ["X"]
Loading