Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file.

* ### Major Changes
* [zizmor](https://zizmor.sh/) is now used for GitHub Actions static analysis.
* [1000: add clear task method and made close an alias](https://github.com/ni/nidaqmx-python/pull/1000)

* ### Known Issues
* ...
Expand Down
8 changes: 7 additions & 1 deletion generated/nidaqmx/task/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def add_global_channels(self, global_channels):

self._interpreter.add_global_chans_to_task(self._handle, channels)

def close(self):
def clear(self):
"""Clears the task.

Before clearing, this method aborts the task, if necessary,
Expand Down Expand Up @@ -361,6 +361,12 @@ def close(self):
if first_exception:
raise first_exception

close = clear
Comment thread
zhindes marked this conversation as resolved.
"""Clears the task.

:meth:`close` is an alias for :meth:`clear`.
"""

def control(self, action):
"""Alters the state of a task according to the action you specify.

Expand Down
8 changes: 7 additions & 1 deletion src/handwritten/task/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def add_global_channels(self, global_channels):

self._interpreter.add_global_chans_to_task(self._handle, channels)

def close(self):
def clear(self):
"""Clears the task.

Before clearing, this method aborts the task, if necessary,
Expand Down Expand Up @@ -361,6 +361,12 @@ def close(self):
if first_exception:
raise first_exception

close = clear
"""Clears the task.

:meth:`close` is an alias for :meth:`clear`.
"""

def control(self, action):
"""Alters the state of a task according to the action you specify.

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ def test___call_alternate_constructor___create_task_not_called(
assert task._close_on_exit == new_session_initialized


@pytest.mark.parametrize("close_on_exit", [False, True])
def test___varying_close_on_exit___clear___clear_task_called(
interpreter: Mock, close_on_exit: bool
):
expect_create_task(interpreter, "MyTaskHandle", close_on_exit)
expect_get_task_name(interpreter, "MyTask")
task = Task("MyTask")
task_handle = task._handle

task.clear()

interpreter.clear_task.assert_called_with(task_handle)


@pytest.mark.parametrize("close_on_exit", [False, True])
def test___varying_close_on_exit___close___clear_task_called(
interpreter: Mock, close_on_exit: bool
Expand All @@ -119,6 +133,7 @@ def test___varying_close_on_exit___close___clear_task_called(
task = Task("MyTask")
task_handle = task._handle

# close is an alias for clear
task.close()

interpreter.clear_task.assert_called_with(task_handle)
Expand Down