-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6073 from qutech/bugfix/multi_channel_instrument_…
…parameter_setter Accept sequences of values for setting MultiChannelInstrumentParameter
- Loading branch information
Showing
3 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Accept sequences of values for setting `MultiChannelInstrumentParameter` s. Previously, the behavior was inconsistent since `param.set(param.get())` would error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/parameter/test_multi_channel_instrument_parameter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from qcodes.instrument_drivers.mock_instruments import DummyChannelInstrument | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Generator | ||
|
||
|
||
@pytest.fixture | ||
def dummy_channel_instrument() -> "Generator[DummyChannelInstrument, None, None]": | ||
instrument = DummyChannelInstrument(name="testdummy") | ||
try: | ||
yield instrument | ||
finally: | ||
instrument.close() | ||
|
||
|
||
@pytest.fixture | ||
def assert_raises_match() -> str: | ||
if sys.version_info >= (3, 11): | ||
return "Value should either be valid" | ||
else: | ||
return "" | ||
|
||
|
||
def test_set_multi_channel_instrument_parameter( | ||
dummy_channel_instrument: DummyChannelInstrument, assert_raises_match: str | ||
): | ||
"""Tests :class:`MultiChannelInstrumentParameter` set method.""" | ||
for name, param in dummy_channel_instrument.channels[0].parameters.items(): | ||
if not param.settable: | ||
continue | ||
|
||
channel_parameter = getattr(dummy_channel_instrument.channels, name) | ||
|
||
getval = channel_parameter.get() | ||
|
||
channel_parameter.set(getval[0]) | ||
|
||
# Assert channel parameter setters accept what the getter returns (PR #6073) | ||
channel_parameter.set(getval) | ||
|
||
with pytest.raises(TypeError, match=assert_raises_match): | ||
channel_parameter.set(getval[:-1]) | ||
|
||
with pytest.raises(TypeError, match=assert_raises_match): | ||
channel_parameter.set(getval + (getval[-1],)) | ||
|
||
with pytest.raises(TypeError): | ||
channel_parameter.set(object()) |