Skip to content

Commit 403baf6

Browse files
Add test for workspace precedence
1 parent b6492f5 commit 403baf6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

lib/ramble/ramble/test/cmd/workspace.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,3 +2055,60 @@ def test_workspace_simplify():
20552055
# ensure apps/pkgs/envs are not merged into workspace config from other config files
20562056
assert search_files_for_string([ws_config_path], "app_not_in_ws_config") is False
20572057
assert search_files_for_string([ws_config_path], "pkg_not_in_ws_config") is False
2058+
2059+
2060+
def write_variables_config_file(file_path, levels, value):
2061+
with open(file_path, "w+") as f:
2062+
f.write("variables:\n")
2063+
for i in range(0, levels):
2064+
f.write(f" scope{i}: {value}\n")
2065+
2066+
2067+
def test_workspace_config_precedence(request, tmpdir):
2068+
workspace_name = request.node.name
2069+
ws = ramble.workspace.create(workspace_name)
2070+
2071+
global_args = ["-w", workspace_name]
2072+
2073+
# Highest precedence, experiment scope
2074+
workspace(
2075+
"manage",
2076+
"experiments",
2077+
"basic",
2078+
"--wf",
2079+
"test_wl",
2080+
"-e",
2081+
"unit-test",
2082+
"-v",
2083+
"n_nodes=1",
2084+
"-v",
2085+
"n_ranks=1",
2086+
"-v",
2087+
"scope0=experiment",
2088+
global_args=global_args,
2089+
)
2090+
2091+
# 2nd highest precedence, included (in an included path)
2092+
included_path = os.path.join(ws.root, "variables.yaml")
2093+
with open(ws.config_file_path, "a") as f:
2094+
f.write(" include:\n")
2095+
f.write(f" - {included_path}\n")
2096+
2097+
write_variables_config_file(included_path, 2, "include_path")
2098+
2099+
# 3rd highest precedence, workspace overrides (in configs/variables.yaml)
2100+
workspace_overrides = os.path.join(ws.config_dir, "variables.yaml")
2101+
write_variables_config_file(workspace_overrides, 3, "workspace_overrides")
2102+
2103+
# 4th highest precedence, workspace (in ramble.yaml)
2104+
config("add", "variables:scope0:workspace", global_args=global_args)
2105+
config("add", "variables:scope1:workspace", global_args=global_args)
2106+
config("add", "variables:scope2:workspace", global_args=global_args)
2107+
config("add", "variables:scope3:workspace", global_args=global_args)
2108+
2109+
output = workspace("info", "-vv", global_args=global_args)
2110+
2111+
assert "scope0 = experiment" in output
2112+
assert "scope1 = include_path" in output
2113+
assert "scope2 = workspace_override" in output
2114+
assert "scope3 = workspace" in output

0 commit comments

Comments
 (0)