File: test_mapred.py

package info (click to toggle)
python-parsl 2025.01.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,072 kB
  • sloc: python: 23,817; makefile: 349; sh: 276; ansic: 45
file content (34 lines) | stat: -rw-r--r-- 786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest

from parsl.app.app import python_app


@python_app
def times_two(x):
    return x * 2


@python_app
def accumulate(inputs=()):
    return sum(inputs)


@python_app
def accumulate_t(*args):
    return sum(args)


@pytest.mark.parametrize("width", (2, 3, 5))
def test_mapred_type1(width):
    """MapReduce test with the reduce stage taking futures in inputs=[]"""
    futs = [times_two(i) for i in range(width)]
    red = accumulate(inputs=futs)
    assert red.result() == 2 * sum(range(width))


@pytest.mark.parametrize("width", (2, 3, 5))
def test_mapred_type2(width):
    """MapReduce test with the reduce stage taking futures on the args"""
    futs = [times_two(i) for i in range(width)]
    red = accumulate_t(*futs)
    assert red.result() == 2 * sum(range(width))