Skip to content
18 changes: 12 additions & 6 deletions generated/nidaqmx/task/_timing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Do not edit this file; it was automatically generated.

from typing import Union
from __future__ import annotations

from typing import NoReturn

from nidaqmx.system.physical_channel import _PhysicalChannelAlternateConstructor
from nidaqmx.system.device import Device
Expand All @@ -19,20 +21,24 @@ class Timing:
"""
__slots__ = ('_handle', '_interpreter', '_active_devs')

def __init__(self, task_handle, interpreter, active_devs: Union[str, Device, None] = None):
def __init__(self, task_handle, interpreter, active_devs: str | Device | None = None):
if isinstance(active_devs, Device):
active_devs = active_devs.name
self._handle = task_handle
self._interpreter = interpreter
self._active_devs = active_devs

def __getitem__(self, dev):
if isinstance (dev, str) or isinstance (dev, Device):
def __getitem__(self, dev: str | Device) -> Timing:
if self._active_devs:
raise DaqError(
f"Cannot set active device '{dev}' because active device '{self._active_devs}' is already set.",
DAQmxErrors.UNKNOWN)
if isinstance(dev, str) or isinstance(dev, Device):
return Timing(self._handle, self._interpreter, active_devs=dev)
else:
else:
raise TypeError(f"Invalid active_devs input: {dev!r} (type: {type(dev).__name__}). Expected str or Device.")

def _raise_device_context_not_supported_error(self):
def _raise_device_context_not_supported_error(self) -> NoReturn:
raise DaqError(
'Operation must be performed on the entire task. It cannot be '
'performed only on specific devices in the task.',
Expand Down
18 changes: 12 additions & 6 deletions src/codegen/templates/task/_timing.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
%>\
# Do not edit this file; it was automatically generated.

from typing import Union
from __future__ import annotations

from typing import NoReturn

from nidaqmx.system.physical_channel import _PhysicalChannelAlternateConstructor
from nidaqmx.system.device import Device
Expand All @@ -31,20 +33,24 @@ class Timing:
"""
__slots__ = ('_handle', '_interpreter', '_active_devs')

def __init__(self, task_handle, interpreter, active_devs: Union[str, Device, None] = None):
def __init__(self, task_handle, interpreter, active_devs: str | Device | None = None):
if isinstance(active_devs, Device):
active_devs = active_devs.name
self._handle = task_handle
self._interpreter = interpreter
self._active_devs = active_devs

def __getitem__(self, dev):
if isinstance (dev, str) or isinstance (dev, Device):
def __getitem__(self, dev: str | Device) -> Timing:
if self._active_devs:
raise DaqError(
f"Cannot set active device '{dev}' because active device '{self._active_devs}' is already set.",
DAQmxErrors.UNKNOWN)
if isinstance(dev, str) or isinstance(dev, Device):
return Timing(self._handle, self._interpreter, active_devs=dev)
else:
else:
raise TypeError(f"Invalid active_devs input: {dev!r} (type: {type(dev).__name__}). Expected str or Device.")

def _raise_device_context_not_supported_error(self):
def _raise_device_context_not_supported_error(self) -> NoReturn:
raise DaqError(
'Operation must be performed on the entire task. It cannot be '
'performed only on specific devices in the task.',
Expand Down
20 changes: 19 additions & 1 deletion tests/component/task/test_timing_properties.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from nidaqmx import DaqError
from nidaqmx.constants import AcquisitionType, SampleTimingType, Edge
from nidaqmx.constants import AcquisitionType, Edge, SampleTimingType
from nidaqmx.error_codes import DAQmxErrors


Expand All @@ -19,6 +19,7 @@ def test___timing___get_boolean_property_with_device_context___throw_daqerror(

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].simultaneous_ao_enable

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -39,6 +40,7 @@ def test___timing___set_boolean_property_with_device_context___throw_daqerror(

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].simultaneous_ao_enable = True

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -61,6 +63,7 @@ def test___timing___reset_boolean_property_with_device_context___throw_daqerror(

with pytest.raises(DaqError) as e:
del task.timing[sim_6363_device].simultaneous_ao_enable

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -77,6 +80,7 @@ def test___timing___get_string_property_with_device_context___throw_daqerror(tas

with pytest.raises(DaqError) as e:
_ = task.timing[sim_6363_device].samp_clk_src

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -95,6 +99,7 @@ def test___timing___set_string_property_with_device_context___throw_daqerror(tas

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].samp_clk_src = "PFI0"

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -115,6 +120,7 @@ def test___timing___reset_string_property_with_device_context___throw_daqerror(

with pytest.raises(DaqError) as e:
del task.timing[sim_6363_device].samp_clk_src

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -147,6 +153,7 @@ def test___timing___get_enum_property_with_device_context___throws_daqerror(task

with pytest.raises(DaqError) as e:
_ = task.timing[sim_6363_device].samp_quant_samp_mode

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -175,6 +182,7 @@ def test___timing___set_enum_property_with_device_context___throw_daqerror(task,

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].samp_quant_samp_mode = AcquisitionType.FINITE

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -207,6 +215,7 @@ def test___timing___reset_enum_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
del task.timing[sim_6363_device].samp_quant_samp_mode

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -231,6 +240,7 @@ def test___timing___get_float64_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
_ = task.timing[sim_6363_device].samp_clk_rate

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -260,6 +270,7 @@ def test___timing___set_float64_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].samp_clk_rate = 2000

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -293,6 +304,7 @@ def test___timing___reset_float64_property_with_device_context___throws_daqerror

with pytest.raises(DaqError) as e:
del task.timing[sim_6363_device].samp_clk_rate

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -317,6 +329,7 @@ def test___timing___get_uint32_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
_ = task.timing[sim_6363_device].samp_clk_timebase_div

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -347,6 +360,7 @@ def test___timing___set_uint32_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].samp_clk_timebase_div = 500

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down Expand Up @@ -382,6 +396,7 @@ def test___timing___reset_uint32_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
del task.timing[sim_6363_device].samp_clk_timebase_div

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -400,6 +415,7 @@ def test___timing___get_uint64_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
_ = task.timing[sim_6363_device].samp_quant_samp_per_chan

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -418,6 +434,7 @@ def test___timing___set_uint64_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
task.timing[sim_6363_device].samp_quant_samp_per_chan = 10000

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand All @@ -439,6 +456,7 @@ def test___timing___reset_uint64_property_with_device_context___throws_daqerror(

with pytest.raises(DaqError) as e:
del task.timing[sim_6363_device].samp_quant_samp_per_chan

assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT


Expand Down