Skip to content

Commit

Permalink
#321 tests for mies data set
Browse files Browse the repository at this point in the history
  • Loading branch information
NileGraddis authored and sgratiy committed Feb 27, 2020
1 parent 22f7076 commit 6ee232c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ipfx/mies_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from ipfx import lab_notebook_reader

class MiesDataSet(HBGDataSet):
# TODO as part of issue GH-286, this class should be refactored to no
# longer subclass HBGDataSet, among other changes.

def __init__(self, sweep_info=None, nwb_file=None, ontology=None, api_sweeps=True, validate_stim=True):
self.notebook = lab_notebook_reader.create_lab_notebook_reader(nwb_file)
Expand All @@ -22,7 +24,6 @@ def get_stimulus_code_ext(self, sweep_num):

cnt = self.notebook.get_value("Set Sweep Count", sweep_num, 0)
stim_code_ext = stim_code + "[%d]" % int(cnt)
print(stim_code_ext)
return stim_code_ext

def extract_sweep_record(self, sweep_num: int) -> Dict[str, Any]:
Expand Down
92 changes: 92 additions & 0 deletions tests/test_mies_data_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import pytest

from ipfx.mies_data_set import MiesDataSet


class MiesDs(MiesDataSet):

@property
def nwb_data(self):
return self._nwb_data

@nwb_data.setter
def nwb_data(self, val):
self._nwb_data = val

def __init__(self):
""" This class does work on __init__, so this hack is used to inject
nwb_data & other dependencies.
"""
# TODO: when refactored, this class ought ot have its dependencies
# injected


def test_get_stimulus_code_ext():

class NwbData:
def get_stim_code(self, sweep_num):
return "fizz"

class Notebook:
def get_value(self, key, sweep_num, default):
return {
("Set Sweep Count", 12): "100"
}.get((key, sweep_num), default)

ds = MiesDs()
ds.nwb_data = NwbData()
ds.notebook = Notebook()

assert ds.get_stimulus_code_ext(12) == "fizz[100]"


def test_extract_sweep_record():

class NwbData:

def get_stim_code(self, sweep_num):
return "fizz"

def get_stimulus_unit(self, sweep_num):
return "amperes"

def get_sweep_attrs(self, sweep_num):
return {
"bridge_balance": 100.0,
"bias_current": 200.0,
}

class Notebook:

def get_value(self, key, sweep_num, default):
return {
("Scale Factor", 12): 2,
("Set Sweep Count", 12): "5"
}.get((key, sweep_num), default)

sweep = 12

exp = {
"sweep_number": sweep,
"stimulus_units": "amperes",
"bridge_balance_mohm": 100.0,
"leak_pa": 200.0,
"stimulus_scale_factor": 2,
"stimulus_code": "fizz",
"stimulus_code_ext": "fizz[5]"
}

ds = MiesDs()
ds.nwb_data = NwbData()
ds.notebook = Notebook()
ds.ontology = None

obt = ds.extract_sweep_record(sweep)

misses = []
for key in exp.keys():
obt_val = obt.pop(key)
if not exp[key] == obt_val:
misses.append([exp[key], obt_val])

assert len(obt) == 0 and len(misses) == 0, f"{misses}\n{obt}"

0 comments on commit 6ee232c

Please sign in to comment.