Skip to content

Commit

Permalink
Add tests for DAQmxConfigureLogging and DAQmxStartNewFile (#616)
Browse files Browse the repository at this point in the history
* Add tests for DAQmxConfigureLogging and DAQmxStartNewFile

* Make styleguide happy

* Remove non-localized strings

* Add logging function tests

* Set new tests to xFail for gRPC
  • Loading branch information
texasaggie97 authored Jul 17, 2024
1 parent baeb0d4 commit 3a990c6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
49 changes: 49 additions & 0 deletions tests/acceptance/test_internationalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,52 @@ 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")

ai_task.in_stream.configure_logging(file_path)

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___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)
44 changes: 43 additions & 1 deletion tests/component/task/test_in_stream.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pathlib
import time

import numpy
import pytest

import nidaqmx
import nidaqmx.system
from nidaqmx.constants import AcquisitionType
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).
Expand All @@ -18,6 +20,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
Expand Down Expand Up @@ -186,3 +194,37 @@ 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


@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"
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


@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)

assert ai_task.in_stream.logging_file_path == pathlib.Path(expected_file_path)

0 comments on commit 3a990c6

Please sign in to comment.