Skip to content

Commit

Permalink
Accept measure scripts with missing version field
Browse files Browse the repository at this point in the history
Closes #741.
  • Loading branch information
alexdewar committed Dec 11, 2024
1 parent 49b5a02 commit 4016f56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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
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 4016f56

Please sign in to comment.