File: test_memoize_exception.py

package info (click to toggle)
python-parsl 2025.12.01%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,112 kB
  • sloc: python: 24,369; makefile: 352; sh: 252; ansic: 45
file content (41 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (2)
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
import parsl
from parsl.app.app import python_app


@python_app(cache=True)
def raise_exception_cache(x, cache=True):
    raise RuntimeError("exception from raise_exception_cache")


@python_app(cache=False)
def raise_exception_nocache(x, cache=True):
    raise RuntimeError("exception from raise_exception_nocache")


def test_python_memoization(n=2):
    """Test Python memoization of exceptions, with cache=True"""
    x = raise_exception_cache(0)

    # wait for x to be done
    x.exception()

    for i in range(0, n):
        fut = raise_exception_cache(0)

        # check that we get back the same exception object, rather than
        # a new one from a second invocation of raise_exception().
        assert fut.exception() is x.exception(), "Memoized exception should have been memoized"


def test_python_no_memoization(n=2):
    """Test Python non-memoization of exceptions, with cache=False"""
    x = raise_exception_nocache(0)

    # wait for x to be done
    x.exception()

    for i in range(0, n):
        fut = raise_exception_nocache(0)

        # check that we get back a different exception object each time
        assert fut.exception() is not x.exception(), "Memoized exception should have been memoized"