Skip to content

Commit

Permalink
fix: the test was only keep a reference of the array - make a copy so…
Browse files Browse the repository at this point in the history
… that the results are not deleted when the context exits.
  • Loading branch information
provos committed Sep 3, 2024
1 parent ca9ad38 commit a339573
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/planai/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
from planai.task import Task, TaskWorker


def copy_work_buffer(work_buffer):
return [
(worker.model_copy(deep=False), task.model_copy(deep=False))
for worker, task in work_buffer
]


class CopyingMock(Mock):
def __call__(self, *args, **kwargs):
if (
args
and isinstance(args[0], list)
and all(isinstance(item, tuple) for item in args[0])
):
args = (copy_work_buffer(args[0]),) + args[1:]
return super().__call__(*args, **kwargs)


class TestTask(unittest.TestCase):
def setUp(self):
self.task = Task()
Expand Down Expand Up @@ -136,6 +154,13 @@ def test_publish_work(self):
mock_dispatcher = Mock()
graph._dispatcher = mock_dispatcher

# Create a side effect function that copies the input
def copy_input(work_buffer):
return work_buffer.copy()

# Set the side effect on the mock
mock_dispatcher.add_multiple_work = CopyingMock()

input_task = DummyTask()
task = DummyTask()
self.worker.register_consumer(DummyTask, self.worker)
Expand Down

0 comments on commit a339573

Please sign in to comment.