Skip to content

Commit cea885c

Browse files
committed
correct implem for mpi4py and medcoupling type hints
1 parent 99db5f9 commit cea885c

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

.pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,5 +550,5 @@ preferred-modules=
550550

551551
# Exceptions that will emit a warning when being caught. Defaults to
552552
# "BaseException, Exception".
553-
overgeneral-exceptions=BaseException,
554-
Exception
553+
overgeneral-exceptions=builtins.BaseException,
554+
builtins.Exception

src/icoco/problem.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@
1010
1111
This module contains the API for ICoCo specifications
1212
"""
13-
13+
from __future__ import annotations
1414
from abc import ABC, abstractmethod
1515
from enum import Enum
16-
from typing import List, Tuple
16+
from typing import TYPE_CHECKING, List, Tuple
1717

18-
# from .utils import MPIComm, medcoupling # type: ignore
19-
from .utils import medcoupling # type: ignore
2018
from .exception import NotImplementedMethod
2119
from .version import get_icoco_version, get_version_int
2220

2321

22+
if TYPE_CHECKING: # pragma: no cover
23+
class medcoupling: # pylint: disable=too-few-public-methods, invalid-name
24+
"""dummy class for type hinting"""
25+
class MEDCouplingFieldDouble: # pylint: disable=too-few-public-methods
26+
"""dummy class for MEDCouplingFieldDouble type hinting"""
27+
class MEDCouplingFieldInt: # pylint: disable=too-few-public-methods
28+
"""dummy class for MEDCouplingFieldInt type hinting"""
29+
class MEDCouplingField: # pylint: disable=too-few-public-methods
30+
"""dummy class for MEDCouplingField type hinting"""
31+
from mpi4py.MPI import Intracomm as MPIComm # type: ignore # pylint: disable=unused-import
32+
33+
2434
ICOCO_VERSION = get_icoco_version()
2535
"""ICoCo version as 'X.Y'."""
2636
ICOCO_MAJOR_VERSION = int(get_version_int()[0])
@@ -115,7 +125,7 @@ def setDataFile(self, datafile: str) -> None:
115125
raise NotImplementedMethod(prob=f"{self.__class__.__module__}.{self.__class__.__name__}",
116126
method="setDataFile")
117127

118-
def setMPIComm(self, mpicomm: 'MPIComm') -> None: # noqa: F821
128+
def setMPIComm(self, mpicomm: MPIComm) -> None: # noqa: F821
119129
"""(Optional) Provide the MPI communicator to be used by the code for parallel computations.
120130
121131
This method must be called before initialize(). The communicator should include all the

src/icoco/utils.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@
99
"""
1010

1111

12-
try:
13-
import medcoupling # pylint: disable=unused-import
14-
except ImportError: # pragma: no cover
15-
import warnings
16-
warnings.warn(message="medcoupling module not found",
17-
category=ImportWarning)
18-
19-
class medcoupling: # pylint: disable=too-few-public-methods, invalid-name
20-
"""dummy class for type hinting"""
21-
class MEDCouplingFieldDouble: # pylint: disable=too-few-public-methods
22-
"""dummy class for MEDCouplingFieldDouble type hinting"""
23-
class MEDCouplingFieldInt: # pylint: disable=too-few-public-methods
24-
"""dummy class for MEDCouplingFieldInt type hinting"""
25-
class MEDCouplingField: # pylint: disable=too-few-public-methods
26-
"""dummy class for MEDCouplingField type hinting"""
27-
28-
29-
# try:
30-
# from mpi4py.MPI import Intracomm as MPIComm # type: ignore # pylint: disable=unused-import
31-
# except ModuleNotFoundError: # pragma: no cover
32-
# class MPIComm: # pylint: disable=too-few-public-methods
33-
# """Basic class for type hinting when mi4py is not available"""
34-
35-
3612
class ICoCoMethods: # pylint: disable=too-few-public-methods
3713
"""Namespace to list all ICoCo methods."""
3814

tests/test_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""test icoco.utils module"""
2+
import icoco.utils
3+
4+
5+
def test_utils_icoco_methods():
6+
"""Tests ICoCoMethods"""
7+
8+
assert len(icoco.utils.ICoCoMethods.PROBLEM) == 4
9+
assert len(icoco.utils.ICoCoMethods.TIME_STEP) == 11
10+
assert len(icoco.utils.ICoCoMethods.RESTORE) == 3
11+
assert len(icoco.utils.ICoCoMethods.IO_FIELD) == 19
12+
assert len(icoco.utils.ICoCoMethods.IO_VALUE) == 10
13+
assert len(icoco.utils.ICoCoMethods.ALL) == 48
14+
15+
16+
def test_utils_icoco_method_context():
17+
"""Tests ICoCoMethodContext"""
18+
19+
assert len(icoco.utils.ICoCoMethodContext.ONLY_BEFORE_INITIALIZE) == 3
20+
assert len(icoco.utils.ICoCoMethodContext.ONLY_AFTER_INITIALIZE ) == (
21+
len(icoco.utils.ICoCoMethods.ALL) - 6)
22+
assert len(icoco.utils.ICoCoMethodContext.ONLY_INSIDE_TIME_STEP_DEFINED) == 4
23+
assert len(icoco.utils.ICoCoMethodContext.ONLY_OUTSIDE_TIME_STEP_DEFINED) == 8

0 commit comments

Comments
 (0)