File: test_python_checkpoint_2.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 (42 lines) | stat: -rw-r--r-- 1,089 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
import contextlib
import os

import pytest

import parsl
from parsl import python_app
from parsl.tests.configs.local_threads_checkpoint import fresh_config


@contextlib.contextmanager
def parsl_configured(run_dir, **kw):
    c = fresh_config()
    c.run_dir = run_dir
    for config_attr, config_val in kw.items():
        setattr(c, config_attr, config_val)
    dfk = parsl.load(c)
    for ex in dfk.executors.values():
        ex.working_dir = run_dir
    yield dfk

    parsl.dfk().cleanup()


@python_app(cache=True)
def uuid_app():
    import uuid
    return uuid.uuid4()


@pytest.mark.local
def test_loading_checkpoint(tmpd_cwd):
    """Load memoization table from previous checkpoint
    """
    with parsl_configured(tmpd_cwd, checkpoint_mode="task_exit"):
        checkpoint_files = [os.path.join(parsl.dfk().run_dir, "checkpoint")]
        result = uuid_app().result()

    with parsl_configured(tmpd_cwd, checkpoint_files=checkpoint_files):
        relaunched = uuid_app().result()

    assert result == relaunched, "Expected following call to uuid_app to return cached uuid"