-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
196 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pytest | ||
from numpy import array_equal | ||
from pandas import DataFrame | ||
|
||
|
||
def test_invalid_interval(pos_src): | ||
"""Test invalid interval""" | ||
with pytest.raises(ValueError): | ||
pos_src.get_pos_interval_name("invalid_interval") | ||
|
||
|
||
def test_invalid_epoch_num(common): | ||
"""Test invalid epoch num""" | ||
with pytest.raises(ValueError): | ||
common.PositionSource.get_epoch_num("invalid_epoch_num") | ||
|
||
|
||
def test_raw_position_fetchnwb(common, mini_pos, mini_pos_interval_dict): | ||
"""Test RawPosition fetch nwb""" | ||
fetched = DataFrame( | ||
(common.RawPosition & mini_pos_interval_dict) | ||
.fetch_nwb()[0]["raw_position"] | ||
.data | ||
) | ||
raw = DataFrame(mini_pos["led_0_series_0"].data) | ||
# compare with mini_pos | ||
assert fetched.equals(raw), "RawPosition fetch_nwb failed" | ||
|
||
|
||
@pytest.mark.skip(reason="No video files in mini") | ||
def test_videofile_no_transaction(common, mini_restr): | ||
"""Test no transaction""" | ||
common.VideoFile()._no_transaction_make(mini_restr) | ||
|
||
|
||
@pytest.mark.skip(reason="No video files in mini") | ||
def test_videofile_update_entries(common): | ||
"""Test update entries""" | ||
common.VideoFile().update_entries() | ||
|
||
|
||
@pytest.mark.skip(reason="No video files in mini") | ||
def test_videofile_getabspath(common, mini_restr): | ||
"""Test get absolute path""" | ||
common.VideoFile().getabspath(mini_restr) | ||
|
||
|
||
def test_posinterval_no_transaction(verbose_context, common, mini_restr): | ||
"""Test no transaction""" | ||
before = common.PositionIntervalMap().fetch() | ||
with verbose_context: | ||
common.PositionIntervalMap()._no_transaction_make(mini_restr) | ||
after = common.PositionIntervalMap().fetch() | ||
assert array_equal( | ||
before, after | ||
), "PositionIntervalMap no_transaction had unexpected effect" | ||
|
||
|
||
def test_get_pos_interval_name(pos_src, mini_copy_name, pos_interval_01): | ||
"""Test get pos interval name""" | ||
names = [f"pos {x} valid times" for x in range(1)] | ||
assert pos_interval_01 == names, "get_pos_interval_name failed" | ||
|
||
|
||
def test_convert_epoch(common, pos_interval_01): | ||
this_key = (common.IntervalList & {"interval_list_name": "01_s1"}).fetch1() | ||
ret = common.common_behav.convert_epoch_interval_name_to_position_interval_name( | ||
this_key | ||
) | ||
assert ( | ||
ret == pos_interval_01[0] | ||
), "convert_epoch_interval_name_to_position_interval_name failed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from numpy import array_equal | ||
|
||
|
||
def test_invalid_device(common, populate_exception): | ||
device_dict = common.DataAcquisitionDevice.fetch(as_dict=True)[0] | ||
device_dict["other"] = "invalid" | ||
with pytest.raises(populate_exception): | ||
common.DataAcquisitionDevice._add_device(device_dict) | ||
|
||
|
||
def test_spikegadets_system_alias(mini_insert, common): | ||
assert ( | ||
common.DataAcquisitionDevice()._add_system("MCU") == "SpikeGadgets" | ||
), "SpikeGadgets MCU alias not found" | ||
|
||
|
||
def test_invalid_probe(common, populate_exception): | ||
probe_dict = common.ProbeType.fetch(as_dict=True)[0] | ||
probe_dict["other"] = "invalid" | ||
with pytest.raises(populate_exception): | ||
common.Probe._add_probe_type(probe_dict) | ||
|
||
|
||
def test_create_probe(common, mini_devices, mini_path, mini_copy_name): | ||
probe_id = common.Probe.fetch("KEY", as_dict=True)[0] | ||
probe_type = common.ProbeType.fetch("KEY", as_dict=True)[0] | ||
before = common.Probe.fetch() | ||
common.Probe.create_from_nwbfile( | ||
nwb_file_name=mini_copy_name.split("/")[-1], | ||
nwb_device_name="probe 0", | ||
contact_side_numbering=False, | ||
**probe_id, | ||
**probe_type, | ||
) | ||
after = common.Probe.fetch() | ||
# Because already inserted, expect no change | ||
assert array_equal( | ||
before, after | ||
), "Probe create_from_nwbfile had unexpected effect" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
from numpy import allclose, array | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def dio_events(common): | ||
yield common.common_dio.DIOEvents | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def dio_fig(mini_insert, dio_events, mini_restr): | ||
yield (dio_events & mini_restr).plot_all_dio_events(return_fig=True) | ||
|
||
|
||
def test_plot_dio_axes(dio_fig, dio_events): | ||
"""Check that all events are plotted.""" | ||
events_fig = set(x.yaxis.get_label().get_text() for x in dio_fig.get_axes()) | ||
events_fetch = set(dio_events.fetch("dio_event_name")) | ||
assert events_fig == events_fetch, "Mismatch in events plotted." | ||
|
||
|
||
def test_plot_dio_data(common, dio_fig): | ||
"""Hash summary of figure object.""" | ||
data_fig = dio_fig.get_axes()[0].lines[0].get_xdata() | ||
data_block = ( | ||
common.IntervalList & 'interval_list_name LIKE "raw%"' | ||
).fetch1("valid_times") | ||
data_fetch = array((data_block[0][0], data_block[-1][1])) | ||
assert allclose( | ||
data_fig, data_fetch, atol=1e-8 | ||
), "Mismatch in data plotted." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters