File: test_resource_spec_validation.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 (45 lines) | stat: -rw-r--r-- 1,102 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
import queue
from unittest import mock

import pytest

from parsl.executors import HighThroughputExecutor
from parsl.executors.errors import InvalidResourceSpecification


def double(x):
    return x * 2


@pytest.mark.local
def test_submit_calls_validate():

    htex = HighThroughputExecutor()
    htex.outgoing_q = mock.Mock(spec=queue.Queue)
    htex.validate_resource_spec = mock.Mock(spec=htex.validate_resource_spec)

    res_spec = {}
    htex.submit(double, res_spec, (5,), {})
    htex.validate_resource_spec.assert_called()


@pytest.mark.local
def test_resource_spec_validation():
    htex = HighThroughputExecutor()
    ret_val = htex.validate_resource_spec({})
    assert ret_val is None


@pytest.mark.local
def test_resource_spec_validation_one_key():
    htex = HighThroughputExecutor()
    ret_val = htex.validate_resource_spec({"priority": 2})
    assert ret_val is None


@pytest.mark.local
def test_resource_spec_validation_bad_keys():
    htex = HighThroughputExecutor()

    with pytest.raises(InvalidResourceSpecification):
        htex.validate_resource_spec({"num_nodes": 2})