Skip to content

Commit 9cf7f01

Browse files
martinruefenachtMartin Ruefenacht
andauthored
Initial integration tests (#16)
Co-authored-by: Martin Ruefenacht <martin.ruefenacht@lrz.de>
1 parent 2e66a12 commit 9cf7f01

File tree

3 files changed

+77
-12
lines changed

3 files changed

+77
-12
lines changed

src/pympistandard/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import importlib.resources
1414
import json
1515
from enum import Enum
16-
from typing import Union, Tuple
16+
from typing import Union, Tuple, Optional
1717
import logging
1818
import os
1919

@@ -56,7 +56,9 @@ def unload() -> None:
5656
# TODO rename to load(api_version, mpi_version, path)
5757
@export
5858
def use_api_version(
59-
version: Union[int, str] = "LATEST", given_path: Union[str, Path] = None
59+
version: Union[int, str] = "LATEST",
60+
given_path: Optional[Union[str, Path]] = None,
61+
force_bundled: bool = False,
6062
) -> None:
6163
"""Sets the Python API interface which the user expects to use."""
6264

@@ -66,7 +68,7 @@ def use_api_version(
6668
if version in (1, "LATEST"):
6769
_register_kinds_v1()
6870

69-
path = _resolve_path(given_path)
71+
path = _resolve_path(given_path, force_bundled)
7072
_load_database_v1(path)
7173

7274
else:
@@ -127,15 +129,21 @@ def _register_kinds_v1() -> None:
127129
KINDS[key.lower()] = item
128130

129131

130-
def _resolve_path(given_path: Union[str, Path] = None) -> Path:
132+
def _resolve_path(
133+
given_path: Optional[Union[str, Path]] = None, force_bundled: bool = False
134+
) -> Path:
131135
"""Find correct path to load apis.json from."""
132136

137+
if force_bundled:
138+
with importlib.resources.path("pympistandard.data", "apis.json") as datapath:
139+
path = datapath
140+
133141
# convert str path to Path
134-
if isinstance(given_path, str):
142+
elif isinstance(given_path, str):
135143
given_path = Path(given_path)
136144

137145
# use given path
138-
if given_path is not None:
146+
elif isinstance(given_path, Path):
139147
path = given_path / "apis.json"
140148

141149
# use environment variable paths

tests/conftest.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88

99
# import pytest
10-
#
11-
#
10+
#
11+
#
1212
# from pympistandard.storage import KINDS, PROCEDURES
1313
# from pympistandard.procedure import Procedure
1414
# from pympistandard.kind import Kind
15-
#
16-
#
15+
#
16+
#
1717
# @pytest.fixture(scope="session", autouse=True)
1818
# def dataset() -> None:
1919
# """Creates the test parsesets required for all tests."""
20-
#
20+
#
2121
# KINDS["return"] = Kind("RETURN", "LIS_RETURN", "ISO_C_RETURN", "F90_RETURN", "F08_RETURN")
22-
#
22+
#
2323
# PROCEDURES["mpi_procedure_name"] = Procedure(
2424
# "MPI_Procedure_name",
2525
# {
@@ -29,3 +29,16 @@
2929
# "attributes": {"c_expressible": True},
3030
# },
3131
# )
32+
33+
34+
import pytest
35+
36+
37+
import pympistandard
38+
39+
40+
@pytest.fixture(scope="session")
41+
def bundled_dataset():
42+
pympistandard.use_api_version(1, force_bundled=True)
43+
44+
return pympistandard

tests/test_integration.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
This module contains tests which test the overall behaviour of pympistandard.
3+
"""
4+
5+
6+
def test_mpi_send_iso_c(bundled_dataset):
7+
assert str(bundled_dataset.PROCEDURES.mpi_send.express.iso_c) == (
8+
"int MPI_Send("
9+
"const void* buf, "
10+
"int count, "
11+
"MPI_Datatype datatype, "
12+
"int dest, "
13+
"int tag, "
14+
"MPI_Comm comm)"
15+
)
16+
17+
18+
def test_mpi_comm_spawn_multiple(bundled_dataset):
19+
assert str(bundled_dataset.PROCEDURES.mpi_comm_spawn_multiple.express.iso_c) == (
20+
"int MPI_Comm_spawn_multiple("
21+
"int count, char* array_of_commands[], "
22+
"char** array_of_argv[], "
23+
"const int array_of_maxprocs[], "
24+
"const MPI_Info array_of_info[], "
25+
"int root, "
26+
"MPI_Comm comm, MPI_Comm* intercomm, "
27+
"int array_of_errcodes[])"
28+
)
29+
30+
31+
def test_mpi_allgatherv_init(bundled_dataset):
32+
assert str(bundled_dataset.PROCEDURES.mpi_allgatherv_init.express.iso_c) == (
33+
"int MPI_Allgatherv_init("
34+
"const void* sendbuf, "
35+
"int sendcount, "
36+
"MPI_Datatype sendtype, "
37+
"void* recvbuf, "
38+
"const int recvcounts[], "
39+
"const int displs[], "
40+
"MPI_Datatype recvtype, "
41+
"MPI_Comm comm, "
42+
"MPI_Info info, "
43+
"MPI_Request* request)"
44+
)

0 commit comments

Comments
 (0)