Skip to content

Commit

Permalink
test_map_parallel.py: refactor using pytest.mark
Browse files Browse the repository at this point in the history
  • Loading branch information
ickc committed Dec 11, 2020
1 parent 9000dbf commit 2444ea2
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions tests/test_map_parallel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from itertools import starmap
from itertools import product

from pytest import mark

from map_parallel import map_parallel
from map_parallel import starmap_parallel
Expand All @@ -8,25 +10,30 @@
[5, 12, 13],
[1, 2, 3]
]
args = list(map(list, zip(*ARGS)))

# MPI is difficult to test
cases = list(product(('multiprocessing', 'multithreading'), (None, 1, 2)))


def f(x, y, z):
return x * x + y * y == z * z


def test_map_parallel():
args = list(map(list, zip(*ARGS)))
truth = list(map(f, *args))
# MPI is difficult to test
for mode in ('multiprocessing', 'multithreading'):
for processes in (None, 1, 2):
assert map_parallel(f, *args, mode=mode, processes=processes) == truth
truth = list(map(f, *args))


@mark.parametrize(
'mode, processes',
cases,
)
def test_map_parallel(mode, processes):
assert map_parallel(f, *args, mode=mode, processes=processes) == truth


def test_starmap_parallel():
args = ARGS
truth = list(starmap(f, args))
# MPI is difficult to test
for mode in ('multiprocessing', 'multithreading'):
for processes in (None, 1, 2):
assert starmap_parallel(f, args, mode=mode, processes=processes) == truth
@mark.parametrize(
'mode, processes',
cases,
)
def test_starmap_parallel(mode, processes):
assert starmap_parallel(f, ARGS, mode=mode, processes=processes) == truth

0 comments on commit 2444ea2

Please sign in to comment.