diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e212436..1fa2326a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 * ... diff --git a/generated/nidaqmx/task/_task.py b/generated/nidaqmx/task/_task.py index daa372c3c..9aa770812 100644 --- a/generated/nidaqmx/task/_task.py +++ b/generated/nidaqmx/task/_task.py @@ -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, @@ -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. diff --git a/src/handwritten/task/_task.py b/src/handwritten/task/_task.py index daa372c3c..9aa770812 100644 --- a/src/handwritten/task/_task.py +++ b/src/handwritten/task/_task.py @@ -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, @@ -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. diff --git a/tests/unit/test_task.py b/tests/unit/test_task.py index 3a6d0c0ba..9ac3e1c3c 100644 --- a/tests/unit/test_task.py +++ b/tests/unit/test_task.py @@ -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 @@ -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)