File: test_basic.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 (48 lines) | stat: -rw-r--r-- 855 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest

from parsl.app.app import python_app


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


@python_app
def import_square(x):
    import math
    return math.pow(x, 2)


@python_app
def custom_exception():
    from globus_sdk import GlobusError
    raise GlobusError('foobar')


def test_simple(n=2):
    x = double(n)
    assert x.result() == n * 2


@pytest.mark.parametrize("n", (-2, -1, 0, 1, 2, 3))
def test_imports(n):
    x = import_square(n)
    assert x.result() == n * n


@pytest.mark.parametrize("n", (0, 1, 2, 3, 5, 8, 13, 21))
def test_parallel_for(n):
    d = {i: double(i) for i in range(n)}
    assert len(d.keys()) == n

    for i in d:
        assert d[i].result() == 2 * i


def test_custom_exception():
    from globus_sdk import GlobusError

    x = custom_exception()
    with pytest.raises(GlobusError):
        x.result()