Skip to content

Commit 3a990c6

Browse files
authored
Add tests for DAQmxConfigureLogging and DAQmxStartNewFile (#616)
* Add tests for DAQmxConfigureLogging and DAQmxStartNewFile * Make styleguide happy * Remove non-localized strings * Add logging function tests * Set new tests to xFail for gRPC
1 parent baeb0d4 commit 3a990c6

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

tests/acceptance/test_internationalization.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,52 @@ def test___supported_encoding___logging_file_path___returns_assigned_value(
6969
ai_task.in_stream.logging_file_path = file_path # type: ignore[assignment] # https://github.com/ni/nidaqmx-python/issues/613
7070

7171
assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path)
72+
73+
74+
@pytest.mark.grpc_xfail(
75+
reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.",
76+
raises=DaqError,
77+
)
78+
@pytest.mark.parametrize(
79+
"file_path, supported_encodings",
80+
[
81+
("Zu prüfende Daten.tdms", ["1252", "iso-8859-1", "utf-8"]),
82+
("Données de test.tdms", ["1252", "iso-8859-1", "utf-8"]),
83+
("テストデータ.tdms", ["932", "shift-jis", "utf-8"]),
84+
("테스트 데이터.tdms", ["utf-8", "euc-kr"]),
85+
("测试数据.tdms", ["utf-8", "gbk"]),
86+
],
87+
)
88+
def test___supported_encoding___configure_logging___returns_assigned_values(
89+
ai_task: Task, file_path: str, supported_encodings: List[str]
90+
):
91+
if _get_encoding(ai_task) not in supported_encodings:
92+
pytest.skip("requires compatible encoding")
93+
94+
ai_task.in_stream.configure_logging(file_path)
95+
96+
assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path)
97+
98+
99+
@pytest.mark.grpc_xfail(
100+
reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.",
101+
raises=DaqError,
102+
)
103+
@pytest.mark.parametrize(
104+
"file_path, supported_encodings",
105+
[
106+
("Zu prüfende Daten.tdms", ["1252", "iso-8859-1", "utf-8"]),
107+
("Données de test.tdms", ["1252", "iso-8859-1", "utf-8"]),
108+
("テストデータ.tdms", ["932", "shift-jis", "utf-8"]),
109+
("테스트 데이터.tdms", ["utf-8", "euc-kr"]),
110+
("测试数据.tdms", ["utf-8", "gbk"]),
111+
],
112+
)
113+
def test___supported_encoding___start_new_file___returns_assigned_value(
114+
ai_task: Task, file_path: str, supported_encodings: List[str]
115+
):
116+
if _get_encoding(ai_task) not in supported_encodings:
117+
pytest.skip("requires compatible encoding")
118+
ai_task.in_stream.start_new_file(file_path)
119+
120+
assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path)

tests/component/task/test_in_stream.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import pathlib
12
import time
23

34
import numpy
45
import pytest
56

67
import nidaqmx
78
import nidaqmx.system
8-
from nidaqmx.constants import AcquisitionType
9+
from nidaqmx.constants import AcquisitionType, LoggingMode, LoggingOperation
10+
from nidaqmx.errors import DaqError
911

1012
# With a simulated X Series, setting ai_max/min to +/-2.5 V coerces the hardware range
1113
# to +/-5 V and generates a noisy sine wave with range +/-2.5 V (raw: about +/-16383).
@@ -18,6 +20,12 @@
1820
FULLSCALE_RAW_MIN = -36768
1921

2022

23+
@pytest.fixture()
24+
def ai_task(task, sim_6363_device):
25+
task.ai_channels.add_ai_voltage_chan(sim_6363_device.ai_physical_chans[0].name)
26+
return task
27+
28+
2129
@pytest.fixture(params=[1, 2, 3])
2230
def ai_sine_task(
2331
task: nidaqmx.Task, sim_6363_device: nidaqmx.system.Device, request: pytest.FixtureRequest
@@ -186,3 +194,37 @@ def test___odd_sized_array___read_into___returns_whole_samples_and_clears_paddin
186194
assert samples_read == 9
187195
assert (SINE_RAW_MIN <= data[:-1]).all() and (data[:-1] <= SINE_RAW_MAX).all()
188196
assert data[-1] == 0 # not FULLSCALE_RAW_MIN
197+
198+
199+
@pytest.mark.grpc_xfail(
200+
reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.",
201+
raises=DaqError,
202+
)
203+
def test___valid_path___configure_logging___returns_assigned_values(ai_task: nidaqmx.Task):
204+
expected_file_path = "Testing File.tdms"
205+
expected_group_name = "Task"
206+
expected_logging_mode = LoggingMode.LOG_AND_READ
207+
expected_logging_operation = LoggingOperation.CREATE_OR_REPLACE
208+
209+
ai_task.in_stream.configure_logging(
210+
expected_file_path,
211+
logging_mode=expected_logging_mode,
212+
group_name=expected_group_name,
213+
operation=expected_logging_operation,
214+
)
215+
216+
assert ai_task.in_stream.logging_file_path == pathlib.Path(expected_file_path)
217+
assert ai_task.in_stream.logging_mode == expected_logging_mode
218+
assert ai_task.in_stream.logging_tdms_group_name == expected_group_name
219+
assert ai_task.in_stream.logging_tdms_operation == expected_logging_operation
220+
221+
222+
@pytest.mark.grpc_xfail(
223+
reason="AB#2393811: DAQmxGetLoggingFilePath returns kErrorNULLPtr (-200604) when called from grpc-device.",
224+
raises=DaqError,
225+
)
226+
def test___valid_path___start_new_file___returns_assigned_value(ai_task: nidaqmx.Task):
227+
expected_file_path = "Testing File.tdms"
228+
ai_task.in_stream.start_new_file(expected_file_path)
229+
230+
assert ai_task.in_stream.logging_file_path == pathlib.Path(expected_file_path)

0 commit comments

Comments
 (0)