Skip to content

Commit 946f52a

Browse files
committed
Add types to tests
1 parent 49cb1b6 commit 946f52a

1 file changed

Lines changed: 45 additions & 20 deletions

File tree

tests/dataset/measurement/test_inferred_parameters_fix.py

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
from typing import TYPE_CHECKING
1010

1111
import numpy as np
12+
import pytest
1213

1314
from qcodes.dataset import Measurement
1415
from qcodes.dataset.descriptions.detect_shapes import detect_shape_of_measurement
16+
from qcodes.dataset.experiment_container import Experiment
17+
from qcodes.instrument_drivers.mock_instruments import DummyInstrument
1518
from qcodes.parameters import DelegateParameter, ManualParameter, Parameter
1619

1720
if TYPE_CHECKING:
@@ -21,7 +24,9 @@
2124
from qcodes.instrument_drivers.mock_instruments import DummyInstrument
2225

2326

24-
def test_inferred_parameters_transitively_collected(experiment, DAC):
27+
def test_inferred_parameters_transitively_collected(
28+
experiment: "Experiment", DAC: "DummyInstrument"
29+
) -> None:
2530
"""
2631
Test that parameters inferred from dependencies are properly collected
2732
when enqueuing results.
@@ -80,7 +85,9 @@ def test_inferred_parameters_transitively_collected(experiment, DAC):
8085
)
8186

8287

83-
def test_inferred_parameters_in_actual_measurement_0d(experiment, DAC):
88+
def test_inferred_parameters_in_actual_measurement_0d(
89+
experiment: "Experiment", DAC: "DummyInstrument"
90+
) -> None:
8491
"""
8592
Test the full measurement flow to ensure inferred parameters are saved correctly.
8693
"""
@@ -136,7 +143,9 @@ def test_inferred_parameters_in_actual_measurement_0d(experiment, DAC):
136143
assert len(param_data["del_param_1"]["dummy_dac_ch1"]) == 1
137144

138145

139-
def test_inferred_parameters_in_actual_measurement_1d(experiment, DAC):
146+
def test_inferred_parameters_in_actual_measurement_1d(
147+
experiment: "Experiment", DAC: "DummyInstrument"
148+
) -> None:
140149
"""
141150
Test the full measurement flow to ensure inferred parameters are saved correctly.
142151
"""
@@ -223,8 +232,12 @@ def test_inferred_parameters_in_actual_measurement_1d(experiment, DAC):
223232
assert len(df) == num_points
224233

225234

235+
@pytest.mark.parametrize("set_shape", [True, False])
226236
def test_inferred_parameters_in_actual_measurement_2d(
227-
experiment: "Experiment", DAC: "DummyInstrument", caplog: "LogCaptureFixture"
237+
experiment: "Experiment",
238+
DAC: "DummyInstrument",
239+
caplog: "LogCaptureFixture",
240+
set_shape: bool,
228241
) -> None:
229242
"""
230243
2D version: both axes are DelegateParameters inferred from DAC channels.
@@ -252,9 +265,10 @@ def test_inferred_parameters_in_actual_measurement_2d(
252265

253266
# Register measurement parameter with 2D setpoints
254267
meas.register_parameter(meas_parameter, setpoints=(del_param_1, del_param_2))
255-
meas.set_shapes(
256-
detect_shape_of_measurement([meas_parameter], (num_points_x, num_points_y))
257-
)
268+
if set_shape:
269+
meas.set_shapes(
270+
detect_shape_of_measurement([meas_parameter], (num_points_x, num_points_y))
271+
)
258272

259273
with meas.run() as datasaver:
260274
for x in np.linspace(0, 1, num_points_x):
@@ -299,10 +313,16 @@ def test_inferred_parameters_in_actual_measurement_2d(
299313
xarr = dataset.to_xarray_dataset()
300314

301315
assert len(caplog.records) == 1
302-
assert (
303-
caplog.records[0].message
304-
== "Exporting meas_parameter to xarray using direct method"
305-
)
316+
if set_shape:
317+
assert (
318+
caplog.records[0].message
319+
== "Exporting meas_parameter to xarray using direct method"
320+
)
321+
else:
322+
assert (
323+
caplog.records[0].message
324+
== "Exporting meas_parameter to xarray via pandas index"
325+
)
306326

307327
assert "meas_parameter" in xarr.data_vars
308328

@@ -314,14 +334,17 @@ def test_inferred_parameters_in_actual_measurement_2d(
314334
assert xarr.coords["del_param_2"].shape == (num_points_y,)
315335
assert xarr.coords["del_param_2"].dims == ("del_param_2",)
316336

317-
assert "dummy_dac_ch1" in xarr.coords
318-
assert xarr.coords["dummy_dac_ch1"].shape == (num_points_x,)
319-
assert xarr.coords["dummy_dac_ch1"].dims == ("del_param_1",)
320-
321-
assert "dummy_dac_ch2" in xarr.coords
322-
assert xarr.coords["dummy_dac_ch2"].shape == (num_points_y,)
323-
assert xarr.coords["dummy_dac_ch2"].dims == ("del_param_2",)
324-
337+
if set_shape:
338+
assert "dummy_dac_ch1" in xarr.coords
339+
assert xarr.coords["dummy_dac_ch1"].shape == (num_points_x,)
340+
assert xarr.coords["dummy_dac_ch1"].dims == ("del_param_1",)
341+
342+
assert "dummy_dac_ch2" in xarr.coords
343+
assert xarr.coords["dummy_dac_ch2"].shape == (num_points_y,)
344+
assert xarr.coords["dummy_dac_ch2"].dims == ("del_param_2",)
345+
else:
346+
assert "dummy_dac_ch1" not in xarr.coords
347+
assert "dummy_dac_ch2" not in xarr.coords
325348
assert xarr["meas_parameter"].dims == ("del_param_1", "del_param_2")
326349
assert xarr["meas_parameter"].shape == (num_points_x, num_points_y)
327350

@@ -334,7 +357,9 @@ def test_inferred_parameters_in_actual_measurement_2d(
334357
assert len(df) == total_points
335358

336359

337-
def test_multiple_dependent_parameters_no_cross_contamination(experiment):
360+
def test_multiple_dependent_parameters_no_cross_contamination(
361+
experiment: "Experiment",
362+
) -> None:
338363
"""
339364
Test that multiple dependent parameters that depend on the same independent
340365
parameter don't get mixed into each other's trees.

0 commit comments

Comments
 (0)