-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from Limmen/multiprocessing
multiprocessing_util unit test
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
simulation-system/libs/csle-common/tests/test_multiprocessing_util.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |