Skip to content

Commit

Permalink
TST: get MPISimulation coverage by removing context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Caldwell committed Oct 20, 2020
1 parent c40ebcd commit 5804e96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion hnn_core/__init__.py
Expand Up @@ -4,4 +4,4 @@
from .network import Network, Spikes, read_spikes
from .pyramidal import L2Pyr, L5Pyr
from .basket import L2Basket, L5Basket
from .parallel_backends import MPIBackend, JoblibBackend
from .parallel_backends import MPIBackend, JoblibBackend
31 changes: 16 additions & 15 deletions hnn_core/tests/test_mpi_child.py
Expand Up @@ -26,23 +26,24 @@ def test_child_run():
't_evprox_2': 20,
'N_trials': 2})

with MPISimulation(skip_mpi_import=True) as mpi_sim:
with io.StringIO() as buf, redirect_stdout(buf):
sim_data = mpi_sim.run(params_reduced)
stdout = buf.getvalue()
assert "end_of_sim" in stdout
mpi_sim = MPISimulation(skip_mpi_import=True)

with io.StringIO() as buf_err, redirect_stderr(buf_err):
with io.StringIO() as buf_out, redirect_stdout(buf_out):
mpi_sim._write_data_stderr(sim_data)
stdout = buf_out.getvalue()
stderr = buf_err.getvalue()
assert "end_of_data:" in stdout
with io.StringIO() as buf, redirect_stdout(buf):
sim_data = mpi_sim.run(params_reduced)
stdout = buf.getvalue()
assert "end_of_sim" in stdout

data = stderr.encode()
expected_len = len(data)
backend = MPIBackend()
sim_data = backend._process_child_data(data, expected_len)
with io.StringIO() as buf_err, redirect_stderr(buf_err):
with io.StringIO() as buf_out, redirect_stdout(buf_out):
mpi_sim._write_data_stderr(sim_data)
stdout = buf_out.getvalue()
stderr = buf_err.getvalue()
assert "end_of_data:" in stdout

data = stderr.encode()
expected_len = len(data)
backend = MPIBackend()
sim_data = backend._process_child_data(data, expected_len)


def test_empty_data():
Expand Down

0 comments on commit 5804e96

Please sign in to comment.