Skip to content

Commit

Permalink
Merge pull request #742 from ImperialCollegeLondon/fix-backwards-comp…
Browse files Browse the repository at this point in the history
…atibility-measure-scripts

Allow for reading measure scripts generated with FINESSE v2.0.0
  • Loading branch information
alexdewar authored Dec 13, 2024
2 parents 2348c2e + 4016f56 commit c81996e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion finesse/gui/measure_script/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ def parse_script(script: str | TextIOBase) -> dict[str, Any]:
)

try:
output = schema.validate(yaml.safe_load(script))
output = yaml.safe_load(script)

# v2.0.0 and older didn't have a version field, but the file formats are
# otherwise identical
if "version" not in output:
output["version"] = 1

output = schema.validate(output)
output.pop("version")
return output
except (yaml.YAMLError, SchemaError) as e:
Expand Down
2 changes: 1 addition & 1 deletion finesse/gui/measure_script/script_edit_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _try_save(self) -> bool:

try:
with open(file_path, "w") as f:
yaml.safe_dump(script, f)
yaml.safe_dump(script, f, sort_keys=False)
except Exception as e:
show_error_message(
self, f"Error occurred while saving file {file_path}:\n{e!s}"
Expand Down
4 changes: 2 additions & 2 deletions tests/gui/measure_script/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def get_data(repeats: int, angle: Any, num_attributes: int) -> dict[str, Any]:
{"angle": 4.0, "measurements": 1},
]
data = {
"version": CURRENT_SCRIPT_VERSION,
"repeats": repeats,
"sequence": angles,
"version": CURRENT_SCRIPT_VERSION,
"extra_attribute": "hello",
}

Expand All @@ -59,7 +59,7 @@ def get_data(repeats: int, angle: Any, num_attributes: int) -> dict[str, Any]:
(
get_data(repeats, angle, num_attributes),
does_not_raise()
if repeats > 0 and is_valid_angle(angle) and num_attributes == 3
if repeats > 0 and is_valid_angle(angle) and 2 <= num_attributes <= 3
else pytest.raises(ParseError),
)
for repeats in range(-5, 5)
Expand Down

0 comments on commit c81996e

Please sign in to comment.