def test_init_default(tmpdir_factory): tmpdir = str(tmpdir_factory.mktemp("test_init_default")) cache = epc.EcephysProjectCache( manifest=os.path.join(tmpdir, "manifest.json")) assert isinstance(cache.fetch_api.rma_engine, HttpEngine) assert cache.stream_writer is cache.fetch_api.rma_engine.write_bytes assert cache.fetch_api.rma_engine.scheme == "http" assert cache.fetch_api.rma_engine.host == "api.brain-map.org"
def test_stream_writer_method_default_correct(tmpdir_factory): """Checks that the stream_writer contained in the rma engine is used when one is not supplied to the __init__ method. """ tmpdir = str(tmpdir_factory.mktemp("test_from_warehouse_default")) manifest = os.path.join(tmpdir, "manifest.json") cache = epc.EcephysProjectCache(stream_writer=None, manifest=manifest) assert cache.stream_writer == cache.fetch_api.rma_engine.write_bytes
def test_get_session_data_continual_failure(tmpdir_factory, mock_api): man_path = os.path.join(tmpdir_factory.mktemp("get_session_data"), "manifest.json") class ContinuallyFailingApi(mock_api): def get_session_data(self, session_id, **kwargs): raise ValueError("bad news!") api = ContinuallyFailingApi() cache = epc.EcephysProjectCache(manifest=man_path, fetch_api=api) sid = 12345 with pytest.raises(ValueError): _ = cache.get_session_data(sid)
def test_get_session_data_eventual_success(tmpdir_factory, mock_api): man_path = os.path.join(tmpdir_factory.mktemp("get_session_data"), "manifest.json") class InitiallyFailingApi(mock_api): def get_session_data(self, session_id, **kwargs): if self.accesses["get_session_data"] < 1: raise ValueError("bad news!") return super(InitiallyFailingApi, self).get_session_data(session_id, **kwargs) api = InitiallyFailingApi() cache = epc.EcephysProjectCache(manifest=man_path, fetch_api=api) sid = 12345 session = cache.get_session_data(sid) assert session.ecephys_session_id == sid
def test_get_probe_lfp_data_continually_failing(tmpdir_factory, mock_api): man_path = os.path.join(tmpdir_factory.mktemp("get_lfp_data"), "manifest.json") class ContinuallyFailingApi(mock_api): def get_probe_lfp_data(self, probe_id, **kwargs): if True: raise ValueError("bad news!") api = ContinuallyFailingApi() cache = epc.EcephysProjectCache(manifest=man_path, fetch_api=api) sid = 3 pid = 11 with pytest.raises(ValueError): session = cache.get_session_data(sid) _ = session.api._probe_nwbfile(pid)
def test_get_probe_lfp_data(tmpdir_factory, mock_api): man_path = os.path.join(tmpdir_factory.mktemp("get_lfp_data"), "manifest.json") class InitiallyFailingApi(mock_api): def get_probe_lfp_data(self, probe_id, **kwargs): if self.accesses["get_probe_data"] < 1: raise ValueError("bad news!") return super(InitiallyFailingApi, self).get_probe_lfp_data(probe_id, **kwargs) api = InitiallyFailingApi() cache = epc.EcephysProjectCache(manifest=man_path, fetch_api=api) sid = 3 pid = 11 session = cache.get_session_data(sid) lfp_file = session.api._probe_nwbfile(pid) assert str(pid) == lfp_file.identifier
def tmpdir_cache(shared_tmpdir, mock_api): man_path = os.path.join(shared_tmpdir, 'manifest.json') return epc.EcephysProjectCache(fetch_api=mock_api(), manifest=man_path)