/ tests / test_jobspec.py
test_jobspec.py
 1  """Test jobspec rehydration, grouping and annotating."""
 2  
 3  from __future__ import annotations
 4  
 5  import pathlib
 6  import typing
 7  from typing import Callable
 8  
 9  import pytest
10  
11  from hpclb.aiida import data
12  from hpclb.aiida.data import jobspec
13  
14  if typing.TYPE_CHECKING:
15      from aiida.orm import Code, InstalledCode
16  
17  
18  def test_minimal_spec(aiida_code_installed: Callable[..., InstalledCode]) -> None:
19      """Make sure no fields are required that shouldn't be."""
20      spec = jobspec.Generic(
21          code=(code := aiida_code_installed()).label,
22          workdir=data.TargetDir("root"),
23          label="testjob",
24          description="Minimal GenericJobCalc spec",
25          queue="default",
26      )
27      assert spec.load_code() == code
28      assert spec.load_computer() == code.computer
29      _ = spec.to_builder()  # make sure no errors thrown
30  
31  
32  def test_missing_comp(aiida_code: Callable[..., Code]) -> None:
33      """Make sure that missing computer raises error."""
34      code = aiida_code(
35          "core.code.portable",
36          filepath_executable="dummy.sh",
37          filepath_files=pathlib.Path(__file__).parent / "data",
38      )
39      spec = jobspec.Generic(
40          code=code.label,
41          workdir=data.TargetDir("root"),
42          label="testjob",
43          description="Minimal GenericJobCalc spec",
44          queue="default",
45      )
46      with pytest.raises(jobspec.ComputerNotFoundError):
47          _ = spec.load_computer()