Skip to content

Commit

Permalink
Be more precise with X series device fixtures (#501)
Browse files Browse the repository at this point in the history
* Be more precise with X series device fixtures
  • Loading branch information
zhindes authored Feb 19, 2024
1 parent 0e87936 commit ac3f5e0
Show file tree
Hide file tree
Showing 30 changed files with 263 additions and 285 deletions.
20 changes: 10 additions & 10 deletions tests/component/_task_modules/channels/test_channel_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@


@pytest.fixture(scope="function")
def ai_voltage_chan_with_excit(task, any_x_series_device):
def ai_voltage_chan_with_excit(task, sim_6363_device):
"""Creates AI Channel object to measure voltage."""
ai_channel = task.ai_channels.add_ai_voltage_chan_with_excit(
any_x_series_device.ai_physical_chans[0].name,
sim_6363_device.ai_physical_chans[0].name,
voltage_excit_source=ExcitationSource.EXTERNAL,
voltage_excit_val=0.1,
)
yield ai_channel


@pytest.fixture(scope="function")
def ai_voltage_chan_with_scale(task, any_x_series_device):
def ai_voltage_chan_with_scale(task, sim_6363_device):
"""Creates AI Channel object to measure voltage with a custom scale."""
ai_channel = task.ai_channels.add_ai_voltage_chan(
any_x_series_device.ai_physical_chans[0].name,
sim_6363_device.ai_physical_chans[0].name,
units=VoltageUnits.FROM_CUSTOM_SCALE,
custom_scale_name="double_gain_scale",
)
Expand All @@ -47,29 +47,29 @@ def ai_power_chan(task, sim_ts_power_device):


@pytest.fixture(scope="function")
def ai_rtd_chan(task, any_x_series_device):
def ai_rtd_chan(task, sim_6363_device):
"""Creates AI Channel object that use an RTD to measure temperature."""
ai_channel = task.ai_channels.add_ai_rtd_chan(
any_x_series_device.ai_physical_chans[0].name,
sim_6363_device.ai_physical_chans[0].name,
rtd_type=RTDType.PT_3750,
)
yield ai_channel


@pytest.fixture(scope="function")
def ci_pulse_width_chan(task, any_x_series_device):
def ci_pulse_width_chan(task, sim_6363_device):
"""Creates CI Channel object to measure the width of a digital pulse."""
ci_channel = task.ci_channels.add_ci_pulse_width_chan(
any_x_series_device.ci_physical_chans[0].name,
sim_6363_device.ci_physical_chans[0].name,
)
yield ci_channel


@pytest.fixture(scope="function")
def ci_count_edges_chan(task, any_x_series_device):
def ci_count_edges_chan(task, sim_6363_device):
"""Creates CI Channel object to count edges."""
ci_channel = task.ci_channels.add_ci_count_edges_chan(
any_x_series_device.ci_physical_chans[0].name,
sim_6363_device.ci_physical_chans[0].name,
)
yield ci_channel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@


@pytest.fixture()
def ai_voltage_task(task, any_x_series_device):
def ai_voltage_task(task, sim_6363_device):
"""Gets AI voltage task."""
task.ai_channels.add_ai_voltage_chan(any_x_series_device.ai_physical_chans[0].name)
task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name)
yield task


@pytest.fixture()
def ao_voltage_task(task, any_x_series_device):
def ao_voltage_task(task, sim_6363_device):
"""Gets AO voltage task."""
task.ao_channels.add_ao_voltage_chan(any_x_series_device.ao_physical_chans[0].name)
task.ao_channels.add_ao_voltage_chan(sim_6363_device.ao_physical_chans[0].name)
yield task


Expand Down
12 changes: 6 additions & 6 deletions tests/component/_task_modules/test_in_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

@pytest.fixture(params=[1, 2, 3])
def ai_sine_task(
task: nidaqmx.Task, sim_x_series_device: nidaqmx.system.Device, request: pytest.FixtureRequest
task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device, request: pytest.FixtureRequest
) -> nidaqmx.Task:
"""Returns an analog input task with varying number of channels and a simulated sine wave."""
_create_ai_sine_channels(task, sim_x_series_device, number_of_channels=request.param)
_create_ai_sine_channels(task, sim_6363_device, number_of_channels=request.param)
return task


Expand Down Expand Up @@ -110,9 +110,9 @@ def test___valid_array___readinto___returns_valid_samples(


def test___odd_sized_array___readinto___returns_whole_samples_and_clears_padding(
task: nidaqmx.Task, sim_x_series_device: nidaqmx.system.Device
task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device
) -> None:
_create_ai_sine_channels(task, sim_x_series_device, number_of_channels=2)
_create_ai_sine_channels(task, sim_6363_device, number_of_channels=2)
# Initialize the array to full-scale readings to ensure it is overwritten.
data = numpy.full(19, FULLSCALE_RAW_MIN, dtype=numpy.int16)

Expand Down Expand Up @@ -174,9 +174,9 @@ def test___valid_array___read_into___returns_valid_samples(


def test___odd_sized_array___read_into___returns_whole_samples_and_clears_padding(
task: nidaqmx.Task, sim_x_series_device: nidaqmx.system.Device
task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device
) -> None:
_create_ai_sine_channels(task, sim_x_series_device, number_of_channels=2)
_create_ai_sine_channels(task, sim_6363_device, number_of_channels=2)
# Initialize the array to full-scale readings to ensure it is overwritten.
data = numpy.full(19, FULLSCALE_RAW_MIN, dtype=numpy.int16)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nidaqmx.constants import SampleTimingType


def test___ai_task___set_int32_property___value_is_set(task, any_x_series_device):
task.ai_channels.add_ai_voltage_chan(any_x_series_device.ai_physical_chans[0].name)
def test___ai_task___set_int32_property___value_is_set(task, sim_6363_device):
task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name)
task.timing.samp_timing_type = SampleTimingType.SAMPLE_CLOCK

# Setting a valid input buffer size of type int32
Expand All @@ -11,8 +11,8 @@ def test___ai_task___set_int32_property___value_is_set(task, any_x_series_device
assert task.in_stream.input_buf_size == 2000000000


def test___ai_task___reset_int32_property___value_is_set_to_default(task, any_x_series_device):
task.ai_channels.add_ai_voltage_chan(any_x_series_device.ai_physical_chans[0].name)
def test___ai_task___reset_int32_property___value_is_set_to_default(task, sim_6363_device):
task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name)
task.timing.samp_timing_type = SampleTimingType.SAMPLE_CLOCK
default_buffer_size = task.in_stream.input_buf_size
task.in_stream.input_buf_size = 2000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


@pytest.fixture()
def ai_task(task, any_x_series_device):
def ai_task(task, sim_6363_device):
"""Gets AI voltage task."""
task.ai_channels.add_ai_voltage_chan(any_x_series_device.ai_physical_chans[0].name)
task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name)
yield task


Expand Down
8 changes: 4 additions & 4 deletions tests/component/_task_modules/test_out_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

@pytest.fixture(params=[1, 2])
def ao_task(
task: nidaqmx.Task, any_x_series_device: nidaqmx.system.Device, request: pytest.FixtureRequest
task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device, request: pytest.FixtureRequest
) -> nidaqmx.Task:
"""Returns an analog output task with a varying number of channels."""
_create_ao_channels(task, any_x_series_device, number_of_channels=request.param)
_create_ao_channels(task, sim_6363_device, number_of_channels=request.param)
return task


Expand Down Expand Up @@ -37,9 +37,9 @@ def test___valid_array___write___returns_samples_written(


def test___odd_sized_array___write___returns_whole_samples(
task: nidaqmx.Task, any_x_series_device: nidaqmx.system.Device
task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device
) -> None:
_create_ao_channels(task, any_x_series_device, number_of_channels=2)
_create_ao_channels(task, sim_6363_device, number_of_channels=2)
task.out_stream.auto_start = True
data = numpy.full(19, 0x1234, dtype=numpy.int16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

def test___ai_task___set_valid_value_to_unsupported_property___unsupported_error_raised(
task,
any_x_series_device,
sim_6363_device,
):
task.ai_channels.add_ai_voltage_chan(any_x_series_device.ai_physical_chans[0].name)
task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name)
task.timing.samp_timing_type = SampleTimingType.SAMPLE_CLOCK

with pytest.raises(DaqError) as exc_info:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


@pytest.fixture()
def ao_task(task, any_x_series_device):
def ao_task(task, sim_6363_device):
"""Gets AO voltage task."""
task.ao_channels.add_ao_voltage_chan(any_x_series_device.ao_physical_chans[0].name)
task.ao_channels.add_ao_voltage_chan(sim_6363_device.ao_physical_chans[0].name)
yield task


Expand Down
Loading

0 comments on commit ac3f5e0

Please sign in to comment.