/ tests / test_aiida / test_calcjob.py
test_calcjob.py
 1  """Test the generic calcjob without running it."""
 2  
 3  from __future__ import annotations
 4  
 5  import pathlib
 6  import typing
 7  
 8  import aiida
 9  import aiida.common.folders
10  import aiida.orm
11  
12  import hpclb
13  
14  
15  def test_example_generic_presubmit(
16      example_code: aiida.orm.Code,
17      example_targetdir: aiida.orm.JsonableData,
18      tmp_path: pathlib.Path,
19  ) -> None:
20      """
21      Test presubmitting a properly set up GenericCalculation.
22  
23      When presubmitting a GenericCalculation, the staging dir should mirror the input
24      TargetDir hierarchy. So should the copy and symlink lists.
25      """
26      staging = tmp_path
27      builder: typing.Any = hpclb.aiida.calcjob.GenericCalculation.get_builder()
28      builder.code = example_code
29      builder.workdir = example_targetdir
30      config_file = aiida.orm.SinglefileData(
31          builder.workdir.obj.subdirs[0].upload[0].source
32      )
33      builder.uploaded.config_file = config_file
34      builder.metadata.options.resources = {
35          "num_machines": 1,
36          "num_mpiprocs_per_machine": 1,
37          "num_cores_per_mpiproc": 1,
38      }
39      calc = hpclb.aiida.calcjob.GenericCalculation(dict(builder))
40      sandbox_folder = aiida.common.folders.SandboxFolder(staging.absolute())
41      sandbox = pathlib.Path(sandbox_folder.abspath)
42      calcinfo = calc.presubmit(sandbox_folder)
43  
44      assert sandbox.is_dir()
45      assert (sandbox / "config").is_dir()
46      assert (sandbox / "out-files").is_dir()
47  
48      assert example_code.computer
49  
50      assert calcinfo.local_copy_list == [
51          (config_file.uuid, "foo.config", "config/input.config")
52      ]
53      assert calcinfo.remote_copy_list == [
54          (example_code.computer.uuid, "/some/absolute/path/somefile.xml", "data.xml")
55      ]
56      assert calcinfo.remote_symlink_list == [
57          (example_code.computer.uuid, "/some/path/to/dir", "datadir")
58      ]