Skip to content

Commit

Permalink
Improve tests for create_shared_memory
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
  • Loading branch information
lebrice committed Nov 4, 2021
1 parent 07517e9 commit 5d49917
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/vector/test_shared_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
@pytest.mark.parametrize(
"ctx", [None, "fork", "spawn"], ids=["default", "fork", "spawn"]
)
@pytest.mark.parametrize("use_all_kwargs", [True, False])
def test_create_shared_memory(space, expected_type, n, ctx, use_all_kwargs: bool):
@pytest.mark.parametrize("n_pos_args", range(4))
def test_create_shared_memory(space, expected_type, n, ctx, n_pos_args: int):
def assert_nested_type(lhs, rhs, n):
assert type(lhs) == type(rhs)
if isinstance(lhs, (list, tuple)):
Expand All @@ -73,10 +73,20 @@ def assert_nested_type(lhs, rhs, n):
raise TypeError("Got unknown type `{0}`.".format(type(lhs)))

ctx = mp if (ctx is None) else mp.get_context(ctx)
if use_all_kwargs:
shared_memory = create_shared_memory(space=space, n=n, ctx=ctx)
else:
shared_memory = create_shared_memory(space, n=n, ctx=ctx)

positional_args = []
keyword_args = OrderedDict(
[
("space", space),
("n", n),
("ctx", ctx),
]
)
# Take the first `n_pos_args` items out of `keyword_args` and into `positional_args`:
for _ in range(n_pos_args):
first_key = next(iter(keyword_args))
positional_args.append(keyword_args.pop(first_key))
shared_memory = create_shared_memory(*positional_args, **keyword_args)
assert_nested_type(shared_memory, expected_type, n=n)


Expand Down

0 comments on commit 5d49917

Please sign in to comment.