Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for reading measure scripts generated with FINESSE v2.0.0 #742

Merged
merged 2 commits into from
Dec 13, 2024
Merged
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
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
Loading