Skip to content

Commit

Permalink
Merge pull request #392 from Limmen/multiprocessing
Browse files Browse the repository at this point in the history
multiprocessing_util unit test
  • Loading branch information
Limmen authored Jul 17, 2024
2 parents 5a86e0b + 03db653 commit 6d3ba6f
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from unittest.mock import patch
from csle_common.util.multiprocessing_util import NoDaemonProcess
from csle_common.util.multiprocessing_util import NoDaemonContext
from csle_common.util.multiprocessing_util import NestablePool


class TestMultiprocessingUtilSuite:
"""
Test suite for multiprocessing util
"""

def test_daemon(self) -> None:
"""
Test the process with daemon property set to false
:return: None
"""
result = NoDaemonProcess(target=lambda: None).daemon
assert not result

def test_no_daemon_context(self) -> None:
"""
Test the NoDaemonContext method
:return: None
"""
context = NoDaemonContext()
process = context.Process(target=lambda: None)
assert isinstance(process, NoDaemonProcess)
assert not process.daemon

@patch("multiprocessing.get_context")
def test_nestable_pool_initialization(self, mock_get_context) -> None:
"""
Test the method that initializes the pool
:param mock_get_context: mock_get_context
:return: None
"""
mock_get_context.return_value = NoDaemonContext()
pool = NestablePool()
assert pool

0 comments on commit 6d3ba6f

Please sign in to comment.