Skip to content

Commit

Permalink
Using unittest.mock instead of mock
Browse files Browse the repository at this point in the history
Adding types-mock to test-requirements.txt
  • Loading branch information
yadudoc committed Aug 15, 2024
1 parent 2e01e6e commit 3628427
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion parsl/tests/test_htex/test_resource_spec_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import queue
from unittest import mock

import mock
import pytest

from parsl.executors import HighThroughputExecutor
Expand Down
44 changes: 30 additions & 14 deletions parsl/tests/test_mpi_apps/test_bad_mpi_config.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
import pytest

from parsl import Config
from parsl.executors import HighThroughputExecutor
from parsl.executors import MPIExecutor
from parsl.launchers import AprunLauncher, SimpleLauncher, SrunLauncher
from parsl.providers import SlurmProvider


@pytest.mark.local
def test_bad_launcher_with_mpi_mode():
"""AssertionError if a launcher other than SimpleLauncher is supplied"""
def test_bad_launcher():
"""TypeError if a launcher other than SimpleLauncher is supplied"""

for launcher in [SrunLauncher(), AprunLauncher()]:
with pytest.raises(AssertionError):
with pytest.raises(TypeError):
Config(executors=[
HighThroughputExecutor(
enable_mpi_mode=True,
MPIExecutor(
provider=SlurmProvider(launcher=launcher),
)
])


@pytest.mark.local
def test_correct_launcher_with_mpi_mode():
def test_bad_mpi_launcher():
"""ValueError if an unsupported mpi_launcher is specified"""

for launcher in [SrunLauncher(), AprunLauncher()]:
with pytest.raises(TypeError):
Config(executors=[
MPIExecutor(
mpi_launcher="bad_launcher",
provider=SlurmProvider(launcher=launcher),
)
])


@pytest.mark.local
@pytest.mark.parametrize(
"mpi_launcher",
["srun", "aprun", "mpiexec"]
)
def test_correct_launcher_with_mpi_mode(mpi_launcher: str):
"""Confirm that SimpleLauncher works with mpi_mode"""

config = Config(executors=[
HighThroughputExecutor(
enable_mpi_mode=True,
provider=SlurmProvider(launcher=SimpleLauncher()),
)
])
assert isinstance(config.executors[0].provider.launcher, SimpleLauncher)
executor = MPIExecutor(
mpi_launcher=mpi_launcher,
provider=SlurmProvider(launcher=SimpleLauncher()),
)

assert isinstance(executor.provider.launcher, SimpleLauncher)
5 changes: 2 additions & 3 deletions parsl/tests/test_mpi_apps/test_mpiex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest

import parsl
from parsl import Config, HighThroughputExecutor
from parsl.executors.high_throughput.mpi_executor import MPIExecutor
from parsl.launchers import SimpleLauncher
Expand Down Expand Up @@ -42,8 +41,8 @@ def test_docstring():
def test_init():
"""Ensure all relevant kwargs are copied over from HTEx"""

new_kwargs = {'max_workers_per_block'}
excluded_kwargs = {'available_accelerators', 'enable_mpi_mode', 'cores_per_worker', 'max_workers_per_node',
new_kwargs = {'max_workers_per_block', 'mpi_launcher'}
excluded_kwargs = {'available_accelerators', 'cores_per_worker', 'max_workers_per_node',
'mem_per_worker', 'cpu_affinity', 'max_workers', 'manager_selector'}

# Get the kwargs from both HTEx and MPIEx
Expand Down
14 changes: 1 addition & 13 deletions parsl/tests/test_mpi_apps/test_resource_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
import typing
import unittest
from typing import Dict
from unittest import mock

import mock
import pytest

import parsl
from parsl.app.app import python_app
from parsl.executors.high_throughput.executor import HighThroughputExecutor
from parsl.executors.high_throughput.mpi_executor import MPIExecutor
from parsl.executors.high_throughput.mpi_prefix_composer import (
InvalidResourceSpecification,
MissingResourceSpecification,
validate_resource_spec,
)
from parsl.executors.high_throughput.mpi_resource_management import (
get_nodes_in_batchjob,
Expand Down Expand Up @@ -72,16 +70,6 @@ def add_to_path(path: os.PathLike) -> typing.Generator[None, None, None]:
os.environ["PATH"] = old_path


@pytest.mark.local
@pytest.mark.skip
def test_slurm_mpi_fetch():
logging.warning(f"Current pwd : {os.path.dirname(__file__)}")
with add_to_path(os.path.dirname(__file__)):
logging.warning(f"PATH: {os.environ['PATH']}")
nodeinfo = get_slurm_hosts_list()
logging.warning(f"Got : {nodeinfo}")


@contextlib.contextmanager
def mock_pbs_nodefile(nodefile: str = "pbs_nodefile") -> typing.Generator[None, None, None]:
cwd = os.path.abspath(os.path.dirname(__file__))
Expand Down
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ pytest-random-order
nbsphinx
sphinx_rtd_theme
mypy==1.5.1
types-mock
types-python-dateutil
types-requests
types-paramiko
mpi4py


# sqlalchemy is needed for typechecking, so it's here
# as well as at runtime for optional monitoring execution
# (where it's specified in setup.py)
Expand Down

0 comments on commit 3628427

Please sign in to comment.