From db47d8b6ab542098c04dafa27be8869f1f1feb53 Mon Sep 17 00:00:00 2001 From: Mark Silva Date: Tue, 16 Jul 2024 15:12:58 -0400 Subject: [PATCH 1/5] Add tests for DAQmxConfigureLogging and DAQmxStartNewFile --- tests/acceptance/test_internationalization.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/acceptance/test_internationalization.py b/tests/acceptance/test_internationalization.py index 08838d29..2110f597 100644 --- a/tests/acceptance/test_internationalization.py +++ b/tests/acceptance/test_internationalization.py @@ -9,6 +9,7 @@ from nidaqmx.errors import DaqError from nidaqmx.system import Device from nidaqmx.task import Task +from nidaqmx.constants import LoggingMode, LoggingOperation @pytest.fixture() @@ -69,3 +70,58 @@ def test___supported_encoding___logging_file_path___returns_assigned_value( ai_task.in_stream.logging_file_path = file_path # type: ignore[assignment] # https://github.com/ni/nidaqmx-python/issues/613 assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path) + + +@pytest.mark.grpc_xfail( + reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.", + raises=DaqError, +) +@pytest.mark.parametrize( + "file_path, supported_encodings", + [ + ("Zu prüfende Daten.tdms", ["1252", "iso-8859-1", "utf-8"]), + ("Données de test.tdms", ["1252", "iso-8859-1", "utf-8"]), + ("テストデータ.tdms", ["932", "shift-jis", "utf-8"]), + ("테스트 데이터.tdms", ["utf-8", "euc-kr"]), + ("测试数据.tdms", ["utf-8", "gbk"]), + ], +) +def test___supported_encoding___configure_logging___returns_assigned_values( + ai_task: Task, file_path: str, supported_encodings: List[str] +): + if _get_encoding(ai_task) not in supported_encodings: + pytest.skip("requires compatible encoding") + expected_group_name = "Task" + expected_logging_mode = LoggingMode.LOG_AND_READ + expected_logging_operation = LoggingOperation.CREATE_OR_REPLACE + + ai_task.in_stream.configure_logging(file_path, logging_mode=expected_logging_mode, group_name=expected_group_name, operation=expected_logging_operation) + + assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path) + assert ai_task.in_stream.logging_mode == expected_logging_mode + assert ai_task.in_stream.logging_tdms_group_name == expected_group_name + assert ai_task.in_stream.logging_tdms_operation == expected_logging_operation + + +@pytest.mark.grpc_xfail( + reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.", + raises=DaqError, +) +@pytest.mark.parametrize( + "file_path, supported_encodings", + [ + ("Zu prüfende Daten.tdms", ["1252", "iso-8859-1", "utf-8"]), + ("Données de test.tdms", ["1252", "iso-8859-1", "utf-8"]), + ("テストデータ.tdms", ["932", "shift-jis", "utf-8"]), + ("테스트 데이터.tdms", ["utf-8", "euc-kr"]), + ("测试数据.tdms", ["utf-8", "gbk"]), + ], +) +def test___supported_encoding___start_new_file___returns_assigned_value( + ai_task: Task, file_path: str, supported_encodings: List[str] +): + if _get_encoding(ai_task) not in supported_encodings: + pytest.skip("requires compatible encoding") + ai_task.in_stream.start_new_file(file_path) + + assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path) From 53706e95d225bfe8db30177cb511be04478516e5 Mon Sep 17 00:00:00 2001 From: Mark Silva Date: Tue, 16 Jul 2024 15:24:00 -0400 Subject: [PATCH 2/5] Make styleguide happy --- tests/acceptance/test_internationalization.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/test_internationalization.py b/tests/acceptance/test_internationalization.py index 2110f597..0c5e748c 100644 --- a/tests/acceptance/test_internationalization.py +++ b/tests/acceptance/test_internationalization.py @@ -5,11 +5,11 @@ import pytest from nidaqmx._lib import lib_importer +from nidaqmx.constants import LoggingMode, LoggingOperation from nidaqmx.error_codes import DAQmxErrors from nidaqmx.errors import DaqError from nidaqmx.system import Device from nidaqmx.task import Task -from nidaqmx.constants import LoggingMode, LoggingOperation @pytest.fixture() @@ -95,7 +95,12 @@ def test___supported_encoding___configure_logging___returns_assigned_values( expected_logging_mode = LoggingMode.LOG_AND_READ expected_logging_operation = LoggingOperation.CREATE_OR_REPLACE - ai_task.in_stream.configure_logging(file_path, logging_mode=expected_logging_mode, group_name=expected_group_name, operation=expected_logging_operation) + ai_task.in_stream.configure_logging( + file_path, + logging_mode=expected_logging_mode, + group_name=expected_group_name, + operation=expected_logging_operation, + ) assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path) assert ai_task.in_stream.logging_mode == expected_logging_mode From 4e8157254e216ac532d9397c184504cd38f97412 Mon Sep 17 00:00:00 2001 From: Mark Silva Date: Tue, 16 Jul 2024 17:40:44 -0400 Subject: [PATCH 3/5] Remove non-localized strings --- tests/acceptance/test_internationalization.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/acceptance/test_internationalization.py b/tests/acceptance/test_internationalization.py index 0c5e748c..c62c52b4 100644 --- a/tests/acceptance/test_internationalization.py +++ b/tests/acceptance/test_internationalization.py @@ -5,7 +5,6 @@ import pytest from nidaqmx._lib import lib_importer -from nidaqmx.constants import LoggingMode, LoggingOperation from nidaqmx.error_codes import DAQmxErrors from nidaqmx.errors import DaqError from nidaqmx.system import Device @@ -91,21 +90,10 @@ def test___supported_encoding___configure_logging___returns_assigned_values( ): if _get_encoding(ai_task) not in supported_encodings: pytest.skip("requires compatible encoding") - expected_group_name = "Task" - expected_logging_mode = LoggingMode.LOG_AND_READ - expected_logging_operation = LoggingOperation.CREATE_OR_REPLACE - ai_task.in_stream.configure_logging( - file_path, - logging_mode=expected_logging_mode, - group_name=expected_group_name, - operation=expected_logging_operation, - ) + ai_task.in_stream.configure_logging(file_path) assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path) - assert ai_task.in_stream.logging_mode == expected_logging_mode - assert ai_task.in_stream.logging_tdms_group_name == expected_group_name - assert ai_task.in_stream.logging_tdms_operation == expected_logging_operation @pytest.mark.grpc_xfail( From a6f18152a3186d7057e396bd7e74c5188de86b05 Mon Sep 17 00:00:00 2001 From: Mark Silva Date: Tue, 16 Jul 2024 17:41:02 -0400 Subject: [PATCH 4/5] Add logging function tests --- tests/component/task/test_in_stream.py | 35 +++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/component/task/test_in_stream.py b/tests/component/task/test_in_stream.py index 9d3ae210..5df95241 100644 --- a/tests/component/task/test_in_stream.py +++ b/tests/component/task/test_in_stream.py @@ -1,3 +1,4 @@ +import pathlib import time import numpy @@ -5,7 +6,7 @@ import nidaqmx import nidaqmx.system -from nidaqmx.constants import AcquisitionType +from nidaqmx.constants import AcquisitionType, LoggingMode, LoggingOperation # With a simulated X Series, setting ai_max/min to +/-2.5 V coerces the hardware range # to +/-5 V and generates a noisy sine wave with range +/-2.5 V (raw: about +/-16383). @@ -18,6 +19,12 @@ FULLSCALE_RAW_MIN = -36768 +@pytest.fixture() +def ai_task(task, sim_6363_device): + task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name) + return task + + @pytest.fixture(params=[1, 2, 3]) def ai_sine_task( task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device, request: pytest.FixtureRequest @@ -186,3 +193,29 @@ def test___odd_sized_array___read_into___returns_whole_samples_and_clears_paddin assert samples_read == 9 assert (SINE_RAW_MIN <= data[:-1]).all() and (data[:-1] <= SINE_RAW_MAX).all() assert data[-1] == 0 # not FULLSCALE_RAW_MIN + + +def test___valid_path___configure_logging___returns_assigned_values(ai_task: nidaqmx.Task): + expected_file_path = "Testing File.tdms" + expected_group_name = "Task" + expected_logging_mode = LoggingMode.LOG_AND_READ + expected_logging_operation = LoggingOperation.CREATE_OR_REPLACE + + ai_task.in_stream.configure_logging( + expected_file_path, + logging_mode=expected_logging_mode, + group_name=expected_group_name, + operation=expected_logging_operation, + ) + + assert ai_task.in_stream.logging_file_path == pathlib.Path(expected_file_path) + assert ai_task.in_stream.logging_mode == expected_logging_mode + assert ai_task.in_stream.logging_tdms_group_name == expected_group_name + assert ai_task.in_stream.logging_tdms_operation == expected_logging_operation + + +def test___valid_path___start_new_file___returns_assigned_value(ai_task: nidaqmx.Task): + expected_file_path = "Testing File.tdms" + ai_task.in_stream.start_new_file(expected_file_path) + + assert ai_task.in_stream.logging_file_path == pathlib.Path(expected_file_path) From 15ae007166acf4e5e16b78871fb4ded3974521ea Mon Sep 17 00:00:00 2001 From: Mark Silva Date: Wed, 17 Jul 2024 10:58:40 -0400 Subject: [PATCH 5/5] Set new tests to xFail for gRPC --- tests/component/task/test_in_stream.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/component/task/test_in_stream.py b/tests/component/task/test_in_stream.py index 5df95241..9d4bcaf7 100644 --- a/tests/component/task/test_in_stream.py +++ b/tests/component/task/test_in_stream.py @@ -7,6 +7,7 @@ import nidaqmx import nidaqmx.system from nidaqmx.constants import AcquisitionType, LoggingMode, LoggingOperation +from nidaqmx.errors import DaqError # With a simulated X Series, setting ai_max/min to +/-2.5 V coerces the hardware range # to +/-5 V and generates a noisy sine wave with range +/-2.5 V (raw: about +/-16383). @@ -195,6 +196,10 @@ def test___odd_sized_array___read_into___returns_whole_samples_and_clears_paddin assert data[-1] == 0 # not FULLSCALE_RAW_MIN +@pytest.mark.grpc_xfail( + reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.", + raises=DaqError, +) def test___valid_path___configure_logging___returns_assigned_values(ai_task: nidaqmx.Task): expected_file_path = "Testing File.tdms" expected_group_name = "Task" @@ -214,6 +219,10 @@ def test___valid_path___configure_logging___returns_assigned_values(ai_task: nid assert ai_task.in_stream.logging_tdms_operation == expected_logging_operation +@pytest.mark.grpc_xfail( + reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.", + raises=DaqError, +) def test___valid_path___start_new_file___returns_assigned_value(ai_task: nidaqmx.Task): expected_file_path = "Testing File.tdms" ai_task.in_stream.start_new_file(expected_file_path)