-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #831 from douglasjacobsen/variable-modification-un…
…ique Allow repeated variable modifications
- Loading branch information
Showing
5 changed files
with
149 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
lib/ramble/ramble/test/modifier_functionality/mock_repeated_modifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2022-2025 The Ramble Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
import os | ||
|
||
from ramble.test.dry_run_helpers import dry_run_config, SCOPES | ||
import ramble.test.modifier_functionality.modifier_helpers as modifier_helpers | ||
|
||
import ramble.workspace | ||
from ramble.main import RambleCommand | ||
|
||
workspace = RambleCommand("workspace") | ||
|
||
|
||
def test_repeated_variable_modifications( | ||
mutable_mock_workspace_path, mutable_applications, mock_modifiers, request | ||
): | ||
workspace_name = request.node.name | ||
|
||
test_modifiers = [ | ||
(SCOPES.experiment, modifier_helpers.named_modifier("repeat-var-mod")), | ||
] | ||
|
||
with ramble.workspace.create(workspace_name) as ws1: | ||
ws1.write() | ||
|
||
config_path = os.path.join(ws1.config_dir, ramble.workspace.config_file_name) | ||
|
||
dry_run_config("modifiers", test_modifiers, config_path, "gromacs", "water_bare") | ||
|
||
ws1._re_read() | ||
|
||
workspace("concretize", global_args=["-D", ws1.root]) | ||
workspace("setup", "--dry-run", global_args=["-D", ws1.root]) | ||
|
||
rendered_template = os.path.join( | ||
ws1.experiment_dir, "gromacs", "water_bare", "test_exp", "execute_experiment" | ||
) | ||
assert os.path.exists(rendered_template) | ||
|
||
with open(rendered_template) as f: | ||
data = f.read() | ||
assert "prefix_mpi_command" in data | ||
assert "suffix_mpi_command" in data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
var/ramble/repos/builtin.mock/modifiers/repeat-var-mod/modifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2022-2025 The Ramble Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
from ramble.modkit import * # noqa: F403 | ||
|
||
|
||
class RepeatVarMod(BasicModifier): | ||
"""Define a test modifier with repeat variable modifications""" | ||
|
||
name = "repeat-var-mod" | ||
|
||
tags("test") | ||
|
||
mode("test", description="This is a test mode") | ||
default_mode("test") | ||
|
||
variable_modification( | ||
"mpi_command", | ||
'echo "prefix_mpi_command" >> {log_file};', | ||
method="prepend", | ||
modes=["test"], | ||
) | ||
|
||
variable_modification( | ||
"mpi_command", | ||
'echo "suffix_mpi_command" >> {log_file};', | ||
method="append", | ||
modes=["test"], | ||
) |