Skip to content

Commit 9bd0cc9

Browse files
committed
add tests against different executors
1 parent 54c5c48 commit 9bd0cc9

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

adaptive/tests/test_runner.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import pytest
66

77
from ..learner import Learner1D, Learner2D
8-
from ..runner import simple, BlockingRunner, AsyncRunner, SequentialExecutor
8+
from ..runner import (simple, BlockingRunner, AsyncRunner, SequentialExecutor,
9+
with_ipyparallel, with_distributed)
910

1011

1112
def blocking_runner(learner, goal):
@@ -19,15 +20,18 @@ def async_runner(learner, goal):
1920

2021
runners = [simple, blocking_runner, async_runner]
2122

23+
2224
def trivial_goal(learner):
2325
return learner.npoints > 10
2426

27+
2528
@pytest.mark.parametrize('runner', runners)
2629
def test_simple(runner):
2730
"""Test that the runners actually run."""
2831

2932
def f(x):
3033
return x
34+
3135
learner = Learner1D(f, (-1, 1))
3236
runner(learner, lambda l: l.npoints > 10)
3337
assert len(learner.data) > 10
@@ -54,3 +58,52 @@ async def f(x):
5458
learner = Learner1D(f, (-1, 1))
5559
runner = AsyncRunner(learner, trivial_goal)
5660
asyncio.get_event_loop().run_until_complete(runner.task)
61+
62+
63+
### Test with different executors
64+
65+
@pytest.fixture(scope="session")
66+
def ipyparallel_executor():
67+
from ipyparallel import Client
68+
import pexpect
69+
70+
child = pexpect.spawn('ipcluster start -n 1')
71+
child.expect('Engines appear to have started successfully', timeout=35)
72+
yield Client()
73+
if not child.terminate(force=True):
74+
raise RuntimeError('Could not stop ipcluster')
75+
76+
77+
@pytest.fixture(scope="session")
78+
def dask_executor():
79+
from distributed import LocalCluster, Client
80+
81+
client = Client(n_workers=1)
82+
yield client
83+
client.close()
84+
85+
86+
def linear(x):
87+
return x
88+
89+
90+
def test_concurrent_futures_executor():
91+
from concurrent.futures import ProcessPoolExecutor
92+
BlockingRunner(Learner1D(linear, (-1, 1)), trivial_goal,
93+
executor=ProcessPoolExecutor(max_workers=1))
94+
95+
96+
@pytest.mark.skipif(not with_ipyparallel, reason='IPyparallel is not installed')
97+
def test_ipyparallel_executor(ipyparallel_executor):
98+
learner = Learner1D(linear, (-1, 1))
99+
BlockingRunner(learner, trivial_goal,
100+
executor=ipyparallel_executor)
101+
assert learner.npoints > 0
102+
103+
104+
@pytest.mark.skipif(not with_distributed, reason='dask.distributed is not installed')
105+
def test_distributed_executor(dask_executor):
106+
learner = Learner1D(linear, (-1, 1))
107+
BlockingRunner(learner, trivial_goal,
108+
executor=dask_executor)
109+
assert learner.npoints > 0

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest
22
pytest-randomly
33
pytest-cov
4+
pexpect

0 commit comments

Comments
 (0)