From e63fa329ccd2ae4ae4bf72de7b9a3011ef2a8717 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:47:40 -0400 Subject: [PATCH] tests: remove test that use read_network --- hnn_core/tests/test_io.py | 62 +---------------------------------- hnn_core/tests/test_params.py | 55 +------------------------------ 2 files changed, 2 insertions(+), 115 deletions(-) diff --git a/hnn_core/tests/test_io.py b/hnn_core/tests/test_io.py index b03bc64b99..0f8c625728 100644 --- a/hnn_core/tests/test_io.py +++ b/hnn_core/tests/test_io.py @@ -3,12 +3,10 @@ # Rajat Partani 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, ) @@ -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.""" @@ -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) diff --git a/hnn_core/tests/test_params.py b/hnn_core/tests/test_params.py index 3581907a09..8b767ebffc 100644 --- a/hnn_core/tests/test_params.py +++ b/hnn_core/tests/test_params.py @@ -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] @@ -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