Skip to content

Commit 14e5217

Browse files
authored
Merge pull request #1305 from linsword13/allow-edit
Catch scanner error to allow edit upon faulty config
2 parents 22719bb + 4f9a7d2 commit 14e5217

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/ramble/ramble/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def _main(argv=None):
921921
except jsonschema.exceptions.ValidationError as e:
922922
e.print_context()
923923
workspace_format_error = e
924-
except ruamel.yaml.parser.ParserError as e:
924+
except (ruamel.yaml.parser.ParserError, ruamel.yaml.scanner.ScannerError) as e:
925925
workspace_format_error = e
926926

927927
# ------------------------------------------------------------------------

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import ramble.pipeline
2020
import ramble.workspace
2121
from ramble.error import RambleCommandError
22-
from ramble.main import RambleCommand
22+
from ramble.main import RambleCommand, main
2323
from ramble.namespace import namespace
2424
from ramble.test.dry_run_helpers import search_files_for_string
2525
from ramble.util import constants
@@ -1053,6 +1053,40 @@ def test_edit_override_gets_correct_path():
10531053
assert output == config_path
10541054

10551055

1056+
def test_edit_with_faulty_config(workspace_name, capsys):
1057+
"""Tests that `ramble workspace edit` works with a faulty config."""
1058+
bad_config = """
1059+
ramble # Missing colon!
1060+
variables:
1061+
mpi_command: 'mpirun -n {n_ranks} -ppn {processes_per_node}'
1062+
batch_submit: 'batch_submit {execute_experiment}'
1063+
processes_per_node: 1
1064+
n_nodes: 1
1065+
applications:
1066+
basic:
1067+
workloads:
1068+
test_wl:
1069+
experiments:
1070+
test_experiment: {}
1071+
"""
1072+
try:
1073+
ws = ramble.workspace.create(workspace_name)
1074+
ws.write()
1075+
1076+
config_path = os.path.join(ws.config_dir, ramble.workspace.config_file_name)
1077+
with open(config_path, "w") as f:
1078+
f.write(bad_config)
1079+
1080+
argv = ["-w", workspace_name, "workspace", "edit", "-c", "-p"]
1081+
# Use main instead of RambleCommand, as this tests the error handling
1082+
# only in the former.
1083+
main(argv)
1084+
captured = capsys.readouterr()
1085+
assert config_path in captured.out
1086+
finally:
1087+
main(["-w", workspace_name, "workspace", "remove", "-y"])
1088+
1089+
10561090
def test_dryrun_setup(workspace_name):
10571091
test_config = """
10581092
ramble:

0 commit comments

Comments
 (0)