From 979985e34639529b2f62d00c5dea57ff08316371 Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Mon, 9 Jun 2025 16:34:55 +0800 Subject: [PATCH 1/8] Update tests to require X Series device with 32 DIO lines Tests and fixtures now require a real X Series device with at least 32 digital I/O lines, using the new real_x_series_device_32dio fixture. The _x_series_device helper accepts a line_number parameter for flexible device selection. Minor formatting and assertion changes included. --- tests/component/test_stream_writers_do.py | 18 +++++++++--------- tests/conftest.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/component/test_stream_writers_do.py b/tests/component/test_stream_writers_do.py index 37d013c2a..e9b184dfd 100644 --- a/tests/component/test_stream_writers_do.py +++ b/tests/component/test_stream_writers_do.py @@ -149,11 +149,11 @@ def di_multi_line_loopback_task( @pytest.fixture def di_port0_loopback_task( - generate_task: Callable[[], nidaqmx.Task], real_x_series_device: nidaqmx.system.Device + generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device ) -> nidaqmx.Task: task = generate_task() task.di_channels.add_di_chan( - real_x_series_device.di_ports[0].name, + real_x_series_device_32dio.di_ports[0].name, line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, ) _start_di_task(task) @@ -162,11 +162,11 @@ def di_port0_loopback_task( @pytest.fixture def di_port1_loopback_task( - generate_task: Callable[[], nidaqmx.Task], real_x_series_device: nidaqmx.system.Device + generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device ) -> nidaqmx.Task: task = generate_task() task.di_channels.add_di_chan( - real_x_series_device.di_ports[1].name, + real_x_series_device_32dio.di_ports[1].name, line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, ) _start_di_task(task) @@ -175,11 +175,11 @@ def di_port1_loopback_task( @pytest.fixture def di_port2_loopback_task( - generate_task: Callable[[], nidaqmx.Task], real_x_series_device: nidaqmx.system.Device + generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device ) -> nidaqmx.Task: task = generate_task() task.di_channels.add_di_chan( - real_x_series_device.di_ports[2].name, + real_x_series_device_32dio.di_ports[2].name, line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, ) _start_di_task(task) @@ -451,10 +451,10 @@ def test___digital_multi_channel_writer___write_one_sample_multi_line_jagged___u di_port1_loopback_task: nidaqmx.Task, di_port2_loopback_task: nidaqmx.Task, generate_task: Callable[[], nidaqmx.Task], - real_x_series_device: nidaqmx.system.Device, + real_x_series_device_32dio: nidaqmx.system.Device, ) -> None: task = generate_task() - for port in real_x_series_device.do_ports: + for port in real_x_series_device_32dio.do_ports: task.do_channels.add_do_chan( port.name, line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, @@ -655,4 +655,4 @@ def test___digital_multi_channel_writer___write_many_sample_port_uint32_with_wro with pytest.raises((ctypes.ArgumentError, TypeError)) as exc_info: writer.write_many_sample_port_uint32(data) - assert "uint32" in exc_info.value.args[0] + assert "uint32" in exc_info.value.args[0] \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index d295d9328..519c1ee5b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Callable, Generator import pytest - import nidaqmx.system from nidaqmx._base_interpreter import BaseInterpreter from nidaqmx.constants import ProductCategory, UsageTypeAI @@ -104,6 +103,7 @@ def _x_series_device( device_type: DeviceType, system: nidaqmx.system.System, sampling_type: SamplingType = SamplingType.ANY, + line_number: int = 8, ) -> nidaqmx.system.Device: for device in system.devices: device_type_match = ( @@ -127,7 +127,7 @@ def _x_series_device( and device.product_category == ProductCategory.X_SERIES_DAQ and len(device.ao_physical_chans) >= 2 and len(device.ai_physical_chans) >= 4 - and len(device.do_lines) >= 8 + and len(device.do_lines) >= line_number and len(device.di_lines) == len(device.do_lines) and len(device.ci_physical_chans) >= 4 ): @@ -180,6 +180,12 @@ def real_x_series_device(system: nidaqmx.system.System) -> nidaqmx.system.Device return _x_series_device(DeviceType.REAL, system) +@pytest.fixture(scope="function") +def real_x_series_device_32dio(system: nidaqmx.system.System) -> nidaqmx.system.Device: + """Gets real 32 DIO X Series device information.""" + return _x_series_device(DeviceType.REAL, system, 32) + + @pytest.fixture(scope="function") def real_x_series_multiplexed_device(system: nidaqmx.system.System) -> nidaqmx.system.Device: """Gets device information for a real X Series device with multiplexed sampling.""" @@ -699,4 +705,4 @@ def thermistor_iex_teds_file_path(teds_assets_directory: pathlib.Path) -> pathli @pytest.fixture def thermistor_vex_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path: """Returns a TEDS file path.""" - return teds_assets_directory / "ThermistorVex.ted" + return teds_assets_directory / "ThermistorVex.ted" \ No newline at end of file From 48687a4709016389947ec71c1d1bb31c41319cde Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Tue, 10 Jun 2025 11:13:57 +0800 Subject: [PATCH 2/8] ni-python-styleguide fix and black src --- tests/component/test_stream_writers_do.py | 2 +- tests/conftest.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/component/test_stream_writers_do.py b/tests/component/test_stream_writers_do.py index e9b184dfd..2b8c95fe3 100644 --- a/tests/component/test_stream_writers_do.py +++ b/tests/component/test_stream_writers_do.py @@ -655,4 +655,4 @@ def test___digital_multi_channel_writer___write_many_sample_port_uint32_with_wro with pytest.raises((ctypes.ArgumentError, TypeError)) as exc_info: writer.write_many_sample_port_uint32(data) - assert "uint32" in exc_info.value.args[0] \ No newline at end of file + assert "uint32" in exc_info.value.args[0] diff --git a/tests/conftest.py b/tests/conftest.py index 519c1ee5b..506fd4250 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Callable, Generator import pytest + import nidaqmx.system from nidaqmx._base_interpreter import BaseInterpreter from nidaqmx.constants import ProductCategory, UsageTypeAI @@ -705,4 +706,4 @@ def thermistor_iex_teds_file_path(teds_assets_directory: pathlib.Path) -> pathli @pytest.fixture def thermistor_vex_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path: """Returns a TEDS file path.""" - return teds_assets_directory / "ThermistorVex.ted" \ No newline at end of file + return teds_assets_directory / "ThermistorVex.ted" From acb24bf22b7156236d2d60b2a232ad6947b797a0 Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Tue, 10 Jun 2025 11:32:59 +0800 Subject: [PATCH 3/8] fix argument incompatible --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 506fd4250..8c6a4ab0b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -184,7 +184,7 @@ def real_x_series_device(system: nidaqmx.system.System) -> nidaqmx.system.Device @pytest.fixture(scope="function") def real_x_series_device_32dio(system: nidaqmx.system.System) -> nidaqmx.system.Device: """Gets real 32 DIO X Series device information.""" - return _x_series_device(DeviceType.REAL, system, 32) + return _x_series_device(DeviceType.REAL, system, sampling_type=SamplingType.ANY, 32) @pytest.fixture(scope="function") From 9a39d8a3b9060a35ea9bbf1d885b917c6e807f66 Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Tue, 10 Jun 2025 11:36:37 +0800 Subject: [PATCH 4/8] fix based on ni-python-styleguide --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8c6a4ab0b..7e88f8050 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -184,7 +184,7 @@ def real_x_series_device(system: nidaqmx.system.System) -> nidaqmx.system.Device @pytest.fixture(scope="function") def real_x_series_device_32dio(system: nidaqmx.system.System) -> nidaqmx.system.Device: """Gets real 32 DIO X Series device information.""" - return _x_series_device(DeviceType.REAL, system, sampling_type=SamplingType.ANY, 32) + return _x_series_device(DeviceType.REAL, system, sampling_type=SamplingType.ANY, line_number=32) @pytest.fixture(scope="function") From 201544bae78275487cb83652f227e23f61145bad Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Tue, 10 Jun 2025 15:50:39 +0800 Subject: [PATCH 5/8] Add 32 DIO device DI loopback fixtures and update test Introduce new pytest fixtures for DI loopback tasks on ports 0, 1, and 2 for both standard and 32 DIO devices. Update the test function to use the 32 DIO-specific fixtures and assertions. Refactor test code to ensure correct fixture usage for each device type. --- tests/component/test_stream_writers_do.py | 51 ++++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/tests/component/test_stream_writers_do.py b/tests/component/test_stream_writers_do.py index 2b8c95fe3..10f5c46c3 100644 --- a/tests/component/test_stream_writers_do.py +++ b/tests/component/test_stream_writers_do.py @@ -149,6 +149,19 @@ def di_multi_line_loopback_task( @pytest.fixture def di_port0_loopback_task( + generate_task: Callable[[], nidaqmx.Task], real_x_series_device: nidaqmx.system.Device +) -> nidaqmx.Task: + task = generate_task() + task.di_channels.add_di_chan( + real_x_series_device.di_ports[0].name, + line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, + ) + _start_di_task(task) + return task + + +@pytest.fixture +def di_port0_loopback_task_32dio( generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device ) -> nidaqmx.Task: task = generate_task() @@ -162,6 +175,19 @@ def di_port0_loopback_task( @pytest.fixture def di_port1_loopback_task( + generate_task: Callable[[], nidaqmx.Task], real_x_series_device: nidaqmx.system.Device +) -> nidaqmx.Task: + task = generate_task() + task.di_channels.add_di_chan( + real_x_series_device.di_ports[1].name, + line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, + ) + _start_di_task(task) + return task + + +@pytest.fixture +def di_port1_loopback_task_32dio( generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device ) -> nidaqmx.Task: task = generate_task() @@ -175,6 +201,19 @@ def di_port1_loopback_task( @pytest.fixture def di_port2_loopback_task( + generate_task: Callable[[], nidaqmx.Task], real_x_series_device: nidaqmx.system.Device +) -> nidaqmx.Task: + task = generate_task() + task.di_channels.add_di_chan( + real_x_series_device.di_ports[2].name, + line_grouping=LineGrouping.CHAN_FOR_ALL_LINES, + ) + _start_di_task(task) + return task + + +@pytest.fixture +def di_port2_loopback_task_32dio( generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device ) -> nidaqmx.Task: task = generate_task() @@ -447,9 +486,9 @@ def test___digital_multi_channel_writer___write_one_sample_multi_line___updates_ def test___digital_multi_channel_writer___write_one_sample_multi_line_jagged___updates_output( - di_port0_loopback_task: nidaqmx.Task, - di_port1_loopback_task: nidaqmx.Task, - di_port2_loopback_task: nidaqmx.Task, + di_port0_loopback_task_32dio: nidaqmx.Task, + di_port1_loopback_task_32dio: nidaqmx.Task, + di_port2_loopback_task_32dio: nidaqmx.Task, generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device, ) -> None: @@ -469,9 +508,9 @@ def test___digital_multi_channel_writer___write_one_sample_multi_line_jagged___u data_to_write = _int_to_bool_array(num_channels * 32, datum).reshape((num_channels, 32)) writer.write_one_sample_multi_line(data_to_write) - assert di_port0_loopback_task.read() == datum & 0xFFFFFFFF - assert di_port1_loopback_task.read() == (datum >> 32) & 0xFF - assert di_port2_loopback_task.read() == (datum >> 64) & 0xFF + assert di_port0_loopback_task_32dio.read() == datum & 0xFFFFFFFF + assert di_port1_loopback_task_32dio.read() == (datum >> 32) & 0xFF + assert di_port2_loopback_task_32dio.read() == (datum >> 64) & 0xFF def test___digital_multi_channel_writer___write_one_sample_multi_line_with_wrong_dtype___raises_error_with_correct_dtype( From a3d5f90c246a3eb80d8533b6e9f7d5cdfc93ce3c Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Tue, 10 Jun 2025 15:55:37 +0800 Subject: [PATCH 6/8] fix based on ni-python-styleguide --- tests/component/test_stream_writers_do.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/component/test_stream_writers_do.py b/tests/component/test_stream_writers_do.py index 10f5c46c3..c68740439 100644 --- a/tests/component/test_stream_writers_do.py +++ b/tests/component/test_stream_writers_do.py @@ -158,8 +158,8 @@ def di_port0_loopback_task( ) _start_di_task(task) return task - - + + @pytest.fixture def di_port0_loopback_task_32dio( generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device @@ -184,8 +184,8 @@ def di_port1_loopback_task( ) _start_di_task(task) return task - - + + @pytest.fixture def di_port1_loopback_task_32dio( generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device @@ -210,8 +210,8 @@ def di_port2_loopback_task( ) _start_di_task(task) return task - - + + @pytest.fixture def di_port2_loopback_task_32dio( generate_task: Callable[[], nidaqmx.Task], real_x_series_device_32dio: nidaqmx.system.Device From b5e42bac02b2d3d633ad4164011220974f18735c Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Wed, 11 Jun 2025 07:52:35 +0800 Subject: [PATCH 7/8] Rename line_number to min_num_lines for clarity The parameter line_number in _x_series_device and its usages has been renamed to min_num_lines to better reflect its purpose as the minimum number of digital lines required. This change affects both the function definition and its call in the real_x_series_device_32dio fixture. No logic was altered. --- tests/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7e88f8050..5b5b75ee9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -104,7 +104,7 @@ def _x_series_device( device_type: DeviceType, system: nidaqmx.system.System, sampling_type: SamplingType = SamplingType.ANY, - line_number: int = 8, + min_num_lines: int = 8, ) -> nidaqmx.system.Device: for device in system.devices: device_type_match = ( @@ -128,7 +128,7 @@ def _x_series_device( and device.product_category == ProductCategory.X_SERIES_DAQ and len(device.ao_physical_chans) >= 2 and len(device.ai_physical_chans) >= 4 - and len(device.do_lines) >= line_number + and len(device.do_lines) >= min_num_lines and len(device.di_lines) == len(device.do_lines) and len(device.ci_physical_chans) >= 4 ): @@ -184,7 +184,7 @@ def real_x_series_device(system: nidaqmx.system.System) -> nidaqmx.system.Device @pytest.fixture(scope="function") def real_x_series_device_32dio(system: nidaqmx.system.System) -> nidaqmx.system.Device: """Gets real 32 DIO X Series device information.""" - return _x_series_device(DeviceType.REAL, system, sampling_type=SamplingType.ANY, line_number=32) + return _x_series_device(DeviceType.REAL, system, sampling_type=SamplingType.ANY, min_num_lines=32) @pytest.fixture(scope="function") From 730e1e26ada87ab272a979db08ec0cc019f31bf2 Mon Sep 17 00:00:00 2001 From: TanYiQing Date: Wed, 11 Jun 2025 07:52:57 +0800 Subject: [PATCH 8/8] fix based on ni-python-styleguide --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5b5b75ee9..8162cd26f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -184,7 +184,9 @@ def real_x_series_device(system: nidaqmx.system.System) -> nidaqmx.system.Device @pytest.fixture(scope="function") def real_x_series_device_32dio(system: nidaqmx.system.System) -> nidaqmx.system.Device: """Gets real 32 DIO X Series device information.""" - return _x_series_device(DeviceType.REAL, system, sampling_type=SamplingType.ANY, min_num_lines=32) + return _x_series_device( + DeviceType.REAL, system, sampling_type=SamplingType.ANY, min_num_lines=32 + ) @pytest.fixture(scope="function")