Skip to content

Commit

Permalink
tests: remove test that use read_network
Browse files Browse the repository at this point in the history
  • Loading branch information
gtdang committed May 3, 2024
1 parent e67114d commit e63fa32
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 115 deletions.
62 changes: 1 addition & 61 deletions hnn_core/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
# Rajat Partani <[email protected]>

from pathlib import Path
from numpy.testing import assert_allclose
from h5io import write_hdf5, read_hdf5
import pytest
import numpy as np

from hnn_core import (read_network, simulate_dipole, read_params,
from hnn_core import (simulate_dipole, read_params,
jones_2009_model, calcium_model,
)

Expand Down Expand Up @@ -314,43 +312,6 @@ def test_read_configuration_json(jones_2009_network):
assert net == jones_2009_network


def test_read_hdf5_with_simulation(jones_2009_network):
""" Read-in of a hdf5 file with simulation"""
# Test reading a network with simulation
net_sim = read_network(
Path(assets_path, 'jones2009_3x3_drives_simulated.hdf5')
)
assert net_sim.rec_arrays['el1'].voltages.size != 0
assert len(net_sim.external_drives['evdist1']['events']) > 0

# Test reading file without simulation information
net_sim_output_false = read_network(
Path(assets_path, 'jones2009_3x3_drives_simulated.hdf5'),
read_output=False
)
assert net_sim_output_false.rec_arrays['el1'].voltages.size == 0
assert len(net_sim_output_false.external_drives['evdist1']['events']) == 0

# Test reading file with simulation and without drive information
net_sim_drives_false = read_network(
Path(assets_path, 'jones2009_3x3_drives_simulated.hdf5'),
read_output=True,
read_drives=False
)
assert net_sim_drives_false.rec_arrays['el1'].voltages.size != 0
assert not bool(net_sim_drives_false.external_drives)

# Test reading file without simulation and drive information
net_sim_output_false_drives_false = read_network(
Path(assets_path, 'jones2009_3x3_drives_simulated.hdf5'),
read_output=False,
read_drives=False
)
assert (net_sim_output_false_drives_false
.rec_arrays['el1'].voltages.size == 0)
assert not bool(net_sim_output_false_drives_false.external_drives)


def test_read_incorrect_format(tmp_path):
"""Test that error raise when the json do not have a Network label."""

Expand All @@ -365,24 +326,3 @@ def test_read_incorrect_format(tmp_path):
with pytest.raises(ValueError,
match="The json should encode a Network object."):
read_network_configuration(file_path)


def test_simulate_from_read(jones_2009_network):
"""
Tests a simulation from a read-in network creates a similar simulation to
the reference network the input file was created from.
"""
net = jones_2009_network
dpls1 = simulate_dipole(net, tstop=2, n_trials=1, dt=0.5)

net_read = read_network(Path(assets_path, 'jones2009_3x3_drives.hdf5'))
dpls2 = simulate_dipole(net_read, tstop=2, n_trials=1, dt=0.5)

for dpl1, dpl2 in zip(dpls1, dpls2):
assert_allclose(dpl1.times, dpl2.times, rtol=0.00051, atol=0)
for dpl_key in dpl1.data.keys():
assert_allclose(dpl1.data[dpl_key],
dpl2.data[dpl_key], rtol=0.000051, atol=0)

# Smoke test
net_read.plot_cells(show=False)
55 changes: 1 addition & 54 deletions hnn_core/tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

import pytest

from hnn_core import (read_params, Params, jones_2009_model, convert_to_hdf5,
Network)
from hnn_core.hnn_io import read_network
from hnn_core import read_params, Params, jones_2009_model, convert_to_hdf5

hnn_core_root = Path(__file__).parents[1]

Expand Down Expand Up @@ -76,57 +74,6 @@ def test_base_params():
assert params == params_base


def test_convert_to_hdf5(tmp_path):
"""Tests conversion of a json file to hdf5"""
# Download params
param_url = ('https://raw.githubusercontent.com/hnn-core/'
'hnn_core/param/default.json')
params_base_fname = Path(hnn_core_root, 'param', 'default.json')
if not op.exists(params_base_fname):
urlretrieve(param_url, params_base_fname)
net_params = Network(read_params(params_base_fname),
add_drives_from_params=True,
)

# Write hdf5 and check if constructed network is equal
outpath = Path(tmp_path, 'default.hdf5')
convert_to_hdf5(params_base_fname, outpath)
net_hdf5 = read_network(outpath)
assert net_hdf5 == net_params

# Write hdf5 without drives
outpath_no_drives = Path(tmp_path, 'default_no_drives.hdf5')
convert_to_hdf5(params_base_fname, outpath_no_drives, include_drives=False)
net_hdf5_no_drives = read_network(outpath_no_drives)
assert net_hdf5_no_drives != net_hdf5
assert bool(net_hdf5_no_drives.external_drives) is False

# Check that writing with no extension will add one
outpath_no_ext = Path(tmp_path, 'default_no_ext')
convert_to_hdf5(params_base_fname, outpath_no_ext)
assert outpath_no_ext.with_suffix('.hdf5').exists()


def test_convert_to_hdf5_legacy(tmp_path):
"""Tests conversion of a param legacy file to hdf5"""
# Download params
param_url = ('https://raw.githubusercontent.com/hnnsolver/'
'hnn-core/test_data/default.param')
params_base_fname = Path(hnn_core_root, 'param', 'default.param')
if not op.exists(params_base_fname):
urlretrieve(param_url, params_base_fname)
net_params = Network(read_params(params_base_fname),
add_drives_from_params=True,
legacy_mode=True
)

# Write hdf5 and check if constructed network is equal
outpath = Path(tmp_path, 'default.hdf5')
convert_to_hdf5(params_base_fname, outpath)
net_hdf5 = read_network(outpath)
assert net_hdf5 == net_params


def test_convert_to_hdf5_bad_type():
"""Tests type validation in convert_to_hdf5 function"""
good_path = hnn_core_root
Expand Down

0 comments on commit e63fa32

Please sign in to comment.