-
Notifications
You must be signed in to change notification settings - Fork 317
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
[WIP] Adding model to metadata and snapshot #6119
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from enum import StrEnum | ||
Check failure on line 1 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)
Check failure on line 1 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (windows-latest, 3.9, false)
|
||
|
||
from typing_extensions import assert_type | ||
|
||
from qcodes.metadatable.metadatable_base import EmptyMetaDataModel | ||
Check failure on line 5 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)
Check failure on line 5 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.11, false)
Check failure on line 5 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)
Check failure on line 5 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (windows-latest, 3.9, false)
|
||
from qcodes.parameters import Parameter | ||
from qcodes.parameters.parameter import ParameterSnapshot | ||
|
||
|
||
def test_parameter_typed_metadata_basic(): | ||
|
||
class ParamType(StrEnum): | ||
|
||
voltage = "voltage" | ||
current = "current" | ||
|
||
class MyParameterMetadata(EmptyMetaDataModel): | ||
param_type: ParamType | ||
|
||
a = Parameter( | ||
name="myparam", | ||
set_cmd=None, | ||
get_cmd=None, | ||
model=ParameterSnapshot, | ||
metadata_model=MyParameterMetadata, | ||
) | ||
a.metadata["param_type"] = ( | ||
ParamType.voltage | ||
) # TODO setting metadata should validate against the model | ||
value = 123 | ||
a.set(value) | ||
|
||
assert isinstance(a.typed_snapshot(), ParameterSnapshot) | ||
assert isinstance(a.typed_metadata(), MyParameterMetadata) | ||
|
||
assert a.typed_metadata().param_type == ParamType.voltage | ||
assert a.typed_snapshot().value == value | ||
Check failure on line 37 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)
Check failure on line 37 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.11, false)
Check failure on line 37 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)
Check failure on line 37 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (windows-latest, 3.9, false)
|
||
assert a.typed_snapshot().name == "myparam" | ||
Check failure on line 38 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)
Check failure on line 38 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.11, false)
Check failure on line 38 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)
Check failure on line 38 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (windows-latest, 3.9, false)
|
||
|
||
assert_type( | ||
a.typed_metadata(), MyParameterMetadata | ||
) # TODO this is only checked if the type checker runs agains the test | ||
assert_type(a.typed_snapshot(), ParameterSnapshot) | ||
Check failure on line 43 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)
Check failure on line 43 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.11, false)
Check failure on line 43 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)
Check failure on line 43 in tests/parameter/test_parameter_typed_metadata.py GitHub Actions / pytestmypy (windows-latest, 3.9, false)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need 3.10 support