Skip to content

Commit

Permalink
improve codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
fedonman committed Oct 22, 2024
1 parent ce23239 commit 1fe3a14
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 87 deletions.
15 changes: 7 additions & 8 deletions src/qililab/instrument_controllers/instrument_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,20 @@ def set_parameter(
channel_id: ChannelID | None = None,
):
"""Updates the reset settings for the controller."""
if parameter is not Parameter.RESET:
raise ValueError("Reset is the only property that can be set for an Instrument Controller.")
if not isinstance(value, bool):
raise ValueError("Reset value Must be a boolean.")
self.settings.reset = value
if parameter == Parameter.RESET:
self.settings.reset = bool(value)
return
raise ValueError("Reset is the only property that can be set for an Instrument Controller.")

def get_parameter(
self,
parameter: Parameter,
channel_id: ChannelID | None = None,
):
"""Updates the reset settings for the controller."""
if parameter is not Parameter.RESET:
raise ValueError("Reset is the only property that can be set for an Instrument Controller.")
return self.settings.reset
if parameter == Parameter.RESET:
return self.settings.reset
raise ValueError("Reset is the only property that can be set for an Instrument Controller.")

@CheckConnected
def turn_on(self):
Expand Down
7 changes: 1 addition & 6 deletions src/qililab/instruments/qblox/qblox_qrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ def _set_acquisition_mode(self, value: float | str | bool | AcquireTriggerMode,
Raises:
ValueError: when value type is not string
"""
if not isinstance(value, AcquireTriggerMode) and not isinstance(value, str):
raise ValueError(f"value must be a string or AcquireTriggerMode. Current type: {type(value)}")
cast(QbloxADCSequencer, self.get_sequencer(sequencer_id)).scope_acquire_trigger_mode = AcquireTriggerMode(value)
if self.is_device_active():
self._set_device_acquisition_mode(mode=AcquireTriggerMode(value), sequencer_id=sequencer_id)
Expand Down Expand Up @@ -442,10 +440,7 @@ def _set_integration_mode(self, value: float | str | bool | IntegrationMode, seq
Raises:
ValueError: when value type is not string
"""
if isinstance(value, (IntegrationMode, str)):
cast(QbloxADCSequencer, self.get_sequencer(sequencer_id)).integration_mode = IntegrationMode(value)
else:
raise ValueError(f"value must be a string or IntegrationMode. Current type: {type(value)}")
cast(QbloxADCSequencer, self.get_sequencer(sequencer_id)).integration_mode = IntegrationMode(value)

def _set_sequence_timeout(self, value: int | float | str | bool, sequencer_id: int):
"""set sequence_timeout for the specific channel
Expand Down
2 changes: 0 additions & 2 deletions src/qililab/platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ def get_element(self, alias: str):
tuple[object, list | None]: Element class together with the index of the bus where the element is located.
"""
# TODO: fix docstring, bus is not returned in most cases
if alias == "platform":
return self.digital_compilation_settings
regex_match = re.search(GATE_ALIAS_REGEX, alias.split("_")[0])
if regex_match is not None:
name = regex_match["gate"]
Expand Down
11 changes: 11 additions & 0 deletions tests/instrument_controllers/test_instrument_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,14 @@ def test_reset_to_dict(self, platform: Platform):
"""Test that the reset attribute gets reflected when calling the controller to_dict method."""
instr_cont = platform.instrument_controllers
controllers_dict = instr_cont.to_dict()

def test_set_get_reset(self, platform: Platform):
assert platform.get_parameter(alias="rohde_schwarz_controller_0", parameter=Parameter.RESET) == True
platform.set_parameter(alias="rohde_schwarz_controller_0", parameter=Parameter.RESET, value=False)
assert platform.get_parameter(alias="rohde_schwarz_controller_0", parameter=Parameter.RESET) == False

with pytest.raises(ValueError):
_ = platform.get_parameter(alias="rohde_schwarz_controller_0", parameter=Parameter.BUS_FREQUENCY)

with pytest.raises(ValueError):
_ = platform.set_parameter(alias="rohde_schwarz_controller_0", parameter=Parameter.BUS_FREQUENCY, value=1e9)
2 changes: 2 additions & 0 deletions tests/instruments/qblox/test_qblox_qrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_init(self, qrm: QbloxQRM):
(Parameter.ACQUISITION_TIMEOUT, 2),
(Parameter.ACQUISITION_DELAY_TIME, 200),
(Parameter.TIME_OF_FLIGHT, 80),
(Parameter.SCOPE_STORE_ENABLED, True)
]
)
def test_set_parameter(self, qrm: QbloxQRM, parameter, value):
Expand Down Expand Up @@ -255,6 +256,7 @@ def test_set_parameter_raises_error(self, qrm: QbloxQRM, parameter, value):
(Parameter.SEQUENCE_TIMEOUT, 5.0),
(Parameter.ACQUISITION_TIMEOUT, 1.0),
(Parameter.TIME_OF_FLIGHT, 120),
(Parameter.SCOPE_STORE_ENABLED, False)
]
)
def test_get_parameter(self, qrm: QbloxQRM, parameter, expected_value):
Expand Down
153 changes: 82 additions & 71 deletions tests/platform/components/test_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,74 +28,85 @@ def bus(mock_instruments):
}
return Bus(settings=settings, platform_instruments=Instruments(elements=mock_instruments))

def test_bus_alias(bus):
assert bus.alias == "bus1"

def test_bus_instruments(bus):
assert len(bus.instruments) == 2

def test_bus_channels(bus):
assert len(bus.channels) == 2
assert bus.channels == [None, None]

def test_bus_str(bus):
assert isinstance(str(bus), str)

def test_bus_equality(bus):
other_bus = MagicMock(spec=Bus)
other_bus.__str__.return_value = str(bus)
assert bus == other_bus

def test_bus_inequality(bus):
other_bus = MagicMock(spec=Bus)
other_bus.__str__.return_value = "different_bus"
assert bus != other_bus

def test_bus_to_dict(bus):
expected_dict = {
"alias": "bus1",
"instruments": ["qcm", "qrm"],
"channels": [None, None]
}
assert bus.to_dict() == expected_dict

def test_bus_has_awg(bus):
assert bus.has_awg() is True

def test_bus_has_adc(bus):
assert bus.has_adc() is True

def test_bus_set_parameter(bus):
parameter = MagicMock()
value = 5
bus.set_parameter(parameter, value)
bus.instruments[0].set_parameter.assert_called_once()

def test_bus_get_parameter(bus):
parameter = MagicMock()
bus.get_parameter(parameter)
bus.instruments[0].get_parameter.assert_called_once()

def test_bus_upload_qpysequence(bus):
qpysequence = MagicMock()
bus.upload_qpysequence(qpysequence)
bus.instruments[0].upload_qpysequence.assert_called_once()

def test_bus_upload(bus):
bus.upload()
bus.instruments[0].upload.assert_called_once()

def test_bus_run(bus):
bus.run()
bus.instruments[0].run.assert_called_once()

def test_bus_acquire_result(bus):
result = MagicMock(spec=Result)
bus.instruments[1].acquire_result.return_value = result
assert bus.acquire_result() == result

def test_bus_acquire_qprogram_results(bus):
acquisitions = {"acq1": MagicMock(spec=AcquisitionData)}
results = [MagicMock(spec=MeasurementResult)]
bus.instruments[1].acquire_qprogram_results.return_value = results
assert bus.acquire_qprogram_results(acquisitions) == results
class TestBus:

def test_bus_alias(self, bus):
assert bus.alias == "bus1"

def test_bus_instruments(self, bus):
assert len(bus.instruments) == 2

def test_bus_channels(self, bus):
assert len(bus.channels) == 2
assert bus.channels == [None, None]

def test_bus_str(self, bus):
assert isinstance(str(bus), str)

def test_bus_equality(self, bus):
other_bus = MagicMock(spec=Bus)
other_bus.__str__.return_value = str(bus)
assert bus == other_bus

def test_bus_inequality(self, bus):
other_bus = MagicMock(spec=Bus)
other_bus.__str__.return_value = "different_bus"
assert bus != other_bus

def test_bus_to_dict(self, bus):
expected_dict = {
"alias": "bus1",
"instruments": ["qcm", "qrm"],
"channels": [None, None]
}
assert bus.to_dict() == expected_dict

def test_bus_has_awg(self, bus):
assert bus.has_awg() is True

def test_bus_has_adc(self, bus):
assert bus.has_adc() is True

def test_bus_set_parameter(self, bus):
parameter = MagicMock()
value = 5
bus.set_parameter(parameter, value)
bus.instruments[0].set_parameter.assert_called_once()

def test_bus_get_parameter(self, bus):
parameter = MagicMock()
bus.get_parameter(parameter)
bus.instruments[0].get_parameter.assert_called_once()

def test_bus_upload_qpysequence(self, bus):
qpysequence = MagicMock()
bus.upload_qpysequence(qpysequence)
bus.instruments[0].upload_qpysequence.assert_called_once()

def test_bus_upload(self, bus):
bus.upload()
bus.instruments[0].upload.assert_called_once()

def test_bus_run(self, bus):
bus.run()
bus.instruments[0].run.assert_called_once()

def test_bus_acquire_result(self, bus):
result = MagicMock(spec=Result)
bus.instruments[1].acquire_result.return_value = result
assert bus.acquire_result() == result

def test_bus_acquire_qprogram_results(self, bus):
acquisitions = {"acq1": MagicMock(spec=AcquisitionData)}
results = [MagicMock(spec=MeasurementResult)]
bus.instruments[1].acquire_qprogram_results.return_value = results
assert bus.acquire_qprogram_results(acquisitions) == results

def test_bus_with_non_existant_instrument_raises_error(self, mock_instruments):
with pytest.raises(NameError):
settings = {
"alias": "bus1",
"instruments": ["not_in_instruments"],
"channels": [None, None]
}
_ = Bus(settings=settings, platform_instruments=Instruments(elements=mock_instruments))

0 comments on commit 1fe3a14

Please sign in to comment.