def test__get_fake_values(self): self.annotations['seed'] = 0 file_datetime = get_fake_value('file_datetime', datetime, seed=0) rec_datetime = get_fake_value('rec_datetime', datetime, seed=1) index = get_fake_value('index', int, seed=2) name = get_fake_value('name', str, seed=3, obj=Segment) description = get_fake_value('description', str, seed=4, obj='Segment') file_origin = get_fake_value('file_origin', str) attrs1 = { 'file_datetime': file_datetime, 'rec_datetime': rec_datetime, 'index': index, 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Segment, annotate=False, seed=0) res12 = get_fake_values('Segment', annotate=False, seed=0) res21 = get_fake_values(Segment, annotate=True, seed=0) res22 = get_fake_values('Segment', annotate=True, seed=0) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 channel_indexes = get_fake_value('channel_indexes', np.ndarray, seed=0, dim=1, dtype='i') name = get_fake_value('name', str, seed=1, obj=Unit) description = get_fake_value('description', str, seed=2, obj='Unit') file_origin = get_fake_value('file_origin', str) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Unit, annotate=False, seed=0) res12 = get_fake_values('Unit', annotate=False, seed=0) res21 = get_fake_values(Unit, annotate=True, seed=0) res22 = get_fake_values('Unit', annotate=True, seed=0) assert_arrays_equal(res11.pop('channel_indexes'), channel_indexes) assert_arrays_equal(res12.pop('channel_indexes'), channel_indexes) assert_arrays_equal(res21.pop('channel_indexes'), channel_indexes) assert_arrays_equal(res22.pop('channel_indexes'), channel_indexes) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 index = get_fake_value('index', int, seed=0) coordinate = get_fake_value('coordinate', pq.Quantity, seed=1, dim=1) name = get_fake_value('name', str, seed=2, obj=RecordingChannel) description = get_fake_value('description', str, seed=3, obj='RecordingChannel') file_origin = get_fake_value('file_origin', str) attrs1 = { 'index': index, 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(RecordingChannel, annotate=False, seed=0) res12 = get_fake_values('RecordingChannel', annotate=False, seed=0) res21 = get_fake_values(RecordingChannel, annotate=True, seed=0) res22 = get_fake_values('RecordingChannel', annotate=True, seed=0) assert_arrays_equal(res11.pop('coordinate'), coordinate) assert_arrays_equal(res12.pop('coordinate'), coordinate) assert_arrays_equal(res21.pop('coordinate'), coordinate) assert_arrays_equal(res22.pop('coordinate'), coordinate) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) labels = get_fake_value('labels', np.ndarray, seed=1, dim=1, dtype='S') name = get_fake_value('name', str, seed=2, obj=Event) description = get_fake_value('description', str, seed=3, obj='Event') file_origin = get_fake_value('file_origin', str) attrs1 = { 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Event, annotate=False, seed=0) res12 = get_fake_values('Event', annotate=False, seed=0) res21 = get_fake_values(Event, annotate=True, seed=0) res22 = get_fake_values('Event', annotate=True, seed=0) assert_arrays_equal(res11.pop('times'), times) assert_arrays_equal(res12.pop('times'), times) assert_arrays_equal(res21.pop('times'), times) assert_arrays_equal(res22.pop('times'), times) assert_arrays_equal(res11.pop('labels'), labels) assert_arrays_equal(res12.pop('labels'), labels) assert_arrays_equal(res21.pop('labels'), labels) assert_arrays_equal(res22.pop('labels'), labels) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) labels = get_fake_value('labels', np.ndarray, seed=1, dim=1, dtype='S') name = get_fake_value('name', str, seed=2, obj=Event) description = get_fake_value('description', str, seed=3, obj='Event') file_origin = get_fake_value('file_origin', str) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Event, annotate=False, seed=0) res12 = get_fake_values('Event', annotate=False, seed=0) res21 = get_fake_values(Event, annotate=True, seed=0) res22 = get_fake_values('Event', annotate=True, seed=0) assert_arrays_equal(res11.pop('times'), times) assert_arrays_equal(res12.pop('times'), times) assert_arrays_equal(res21.pop('times'), times) assert_arrays_equal(res22.pop('times'), times) assert_arrays_equal(res11.pop('labels'), labels) assert_arrays_equal(res12.pop('labels'), labels) assert_arrays_equal(res21.pop('labels'), labels) assert_arrays_equal(res22.pop('labels'), labels) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations["seed"] = 0 time = get_fake_value("time", pq.Quantity, seed=0, dim=0) label = get_fake_value("label", str, seed=1) name = get_fake_value("name", str, seed=2, obj=Event) description = get_fake_value("description", str, seed=3, obj="Event") file_origin = get_fake_value("file_origin", str) attrs1 = {"label": label, "name": name, "description": description, "file_origin": file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Event, annotate=False, seed=0) res12 = get_fake_values("Event", annotate=False, seed=0) res21 = get_fake_values(Event, annotate=True, seed=0) res22 = get_fake_values("Event", annotate=True, seed=0) assert_arrays_equal(res11.pop("time"), time) assert_arrays_equal(res12.pop("time"), time) assert_arrays_equal(res21.pop("time"), time) assert_arrays_equal(res22.pop("time"), time) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 time = get_fake_value('time', pq.Quantity, seed=0, dim=0) duration = get_fake_value('duration', pq.Quantity, seed=1) label = get_fake_value('label', str, seed=2) name = get_fake_value('name', str, seed=3, obj=Epoch) description = get_fake_value('description', str, seed=4, obj='Epoch') file_origin = get_fake_value('file_origin', str) attrs1 = {'label': label, 'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Epoch, annotate=False, seed=0) res12 = get_fake_values('Epoch', annotate=False, seed=0) res21 = get_fake_values(Epoch, annotate=True, seed=0) res22 = get_fake_values('Epoch', annotate=True, seed=0) assert_arrays_equal(res11.pop('time'), time) assert_arrays_equal(res12.pop('time'), time) assert_arrays_equal(res21.pop('time'), time) assert_arrays_equal(res22.pop('time'), time) assert_arrays_equal(res11.pop('duration'), duration) assert_arrays_equal(res12.pop('duration'), duration) assert_arrays_equal(res21.pop('duration'), duration) assert_arrays_equal(res22.pop('duration'), duration) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 index = get_fake_value('index', int, seed=0) coordinate = get_fake_value('coordinate', pq.Quantity, seed=1, dim=1) name = get_fake_value('name', str, seed=2, obj=RecordingChannel) description = get_fake_value('description', str, seed=3, obj='RecordingChannel') file_origin = get_fake_value('file_origin', str) attrs1 = {'index': index, 'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(RecordingChannel, annotate=False, seed=0) res12 = get_fake_values('RecordingChannel', annotate=False, seed=0) res21 = get_fake_values(RecordingChannel, annotate=True, seed=0) res22 = get_fake_values('RecordingChannel', annotate=True, seed=0) assert_arrays_equal(res11.pop('coordinate'), coordinate) assert_arrays_equal(res12.pop('coordinate'), coordinate) assert_arrays_equal(res21.pop('coordinate'), coordinate) assert_arrays_equal(res22.pop('coordinate'), coordinate) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 file_datetime = get_fake_value('file_datetime', datetime, seed=0) rec_datetime = get_fake_value('rec_datetime', datetime, seed=1) index = get_fake_value('index', int, seed=2) name = get_fake_value('name', str, seed=3, obj=Block) description = get_fake_value('description', str, seed=4, obj='Block') file_origin = get_fake_value('file_origin', str) attrs1 = {'file_datetime': file_datetime, 'rec_datetime': rec_datetime, 'index': index, 'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Block, annotate=False, seed=0) res12 = get_fake_values('Block', annotate=False, seed=0) res21 = get_fake_values(Block, annotate=True, seed=0) res22 = get_fake_values('Block', annotate=True, seed=0) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 signal = get_fake_value('signal', pq.Quantity, seed=0, dim=2) sampling_rate = get_fake_value('sampling_rate', pq.Quantity, seed=1, dim=0) t_start = get_fake_value('t_start', pq.Quantity, seed=2, dim=0) channel_index = get_fake_value('channel_index', np.ndarray, seed=3, dim=1, dtype='i') name = get_fake_value('name', str, seed=4, obj=AnalogSignalArray) description = get_fake_value('description', str, seed=5, obj='AnalogSignalArray') file_origin = get_fake_value('file_origin', str) attrs1 = { 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(AnalogSignalArray, annotate=False, seed=0) res12 = get_fake_values('AnalogSignalArray', annotate=False, seed=0) res21 = get_fake_values(AnalogSignalArray, annotate=True, seed=0) res22 = get_fake_values('AnalogSignalArray', annotate=True, seed=0) assert_arrays_equal(res11.pop('signal'), signal) assert_arrays_equal(res12.pop('signal'), signal) assert_arrays_equal(res21.pop('signal'), signal) assert_arrays_equal(res22.pop('signal'), signal) assert_arrays_equal(res11.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res12.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res21.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res22.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res11.pop('t_start'), t_start) assert_arrays_equal(res12.pop('t_start'), t_start) assert_arrays_equal(res21.pop('t_start'), t_start) assert_arrays_equal(res22.pop('t_start'), t_start) assert_arrays_equal(res11.pop('channel_index'), channel_index) assert_arrays_equal(res12.pop('channel_index'), channel_index) assert_arrays_equal(res21.pop('channel_index'), channel_index) assert_arrays_equal(res22.pop('channel_index'), channel_index) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) durations = get_fake_value('durations', pq.Quantity, seed=1, dim=1) labels = get_fake_value('labels', np.ndarray, seed=2, dim=1, dtype='U') name = get_fake_value('name', str, seed=3, obj=Epoch) description = get_fake_value('description', str, seed=4, obj='Epoch') file_origin = get_fake_value('file_origin', str) arr_ann = get_fake_value('array_annotations', dict, seed=6, obj=Epoch, n=5) attrs1 = { 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) attrs2['array_annotations'] = arr_ann res11 = get_fake_values(Epoch, annotate=False, seed=0) res12 = get_fake_values('Epoch', annotate=False, seed=0) res21 = get_fake_values(Epoch, annotate=True, seed=0) res22 = get_fake_values('Epoch', annotate=True, seed=0) assert_arrays_equal(res11.pop('times'), times) assert_arrays_equal(res12.pop('times'), times) assert_arrays_equal(res21.pop('times'), times) assert_arrays_equal(res22.pop('times'), times) assert_arrays_equal(res11.pop('durations'), durations) assert_arrays_equal(res12.pop('durations'), durations) assert_arrays_equal(res21.pop('durations'), durations) assert_arrays_equal(res22.pop('durations'), durations) assert_arrays_equal(res11.pop('labels'), labels) assert_arrays_equal(res12.pop('labels'), labels) assert_arrays_equal(res21.pop('labels'), labels) assert_arrays_equal(res22.pop('labels'), labels) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) # Array annotations need to be compared separately # because numpy arrays define equality differently arr_ann_res21 = res21.pop('array_annotations') arr_ann_attrs2 = attrs2.pop('array_annotations') self.assertEqual(res21, attrs2) assert_arrays_equal(arr_ann_res21['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res21['number'], arr_ann_attrs2['number']) arr_ann_res22 = res22.pop('array_annotations') self.assertEqual(res22, attrs2) assert_arrays_equal(arr_ann_res22['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res22['number'], arr_ann_attrs2['number'])
def subcheck__get_fake_values(self, cls): res1 = get_fake_values(cls, annotate=False, seed=0) res2 = get_fake_values(cls, annotate=True, seed=0) if hasattr(cls, 'lower'): cls = class_by_name[cls] attrs = cls._necessary_attrs + cls._recommended_attrs attrnames = [attr[0] for attr in attrs] attrtypes = [attr[1] for attr in attrs] attritems = zip(attrnames, attrtypes) attrannnames = attrnames + list(self.annotations.keys()) # All DataObjects also have array annotations if issubclass(cls, DataObject): attrannnames.append('array_annotations') self.assertEqual(sorted(attrnames), sorted(res1.keys())) self.assertEqual(sorted(attrannnames), sorted(res2.keys())) items11 = [(name, type(value)) for name, value in res1.items()] self.assertEqual(sorted(attritems), sorted(items11)) for name, value in res1.items(): try: self.assertEqual(res2[name], value) except ValueError: assert_arrays_equal(res2[name], value) for name, value in self.annotations.items(): self.assertFalse(name in res1) self.assertEqual(res2[name], value) for attr in attrs: name = attr[0] if len(attr) < 3: continue dim = attr[2] self.assertEqual(dim, res1[name].ndim) self.assertEqual(dim, res2[name].ndim) if len(attr) < 4: continue dtype = attr[3] self.assertEqual(dtype.kind, res1[name].dtype.kind) self.assertEqual(dtype.kind, res2[name].dtype.kind)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) signal = get_fake_value('signal', pq.Quantity, seed=1, dim=2) name = get_fake_value('name', str, seed=2, obj=IrregularlySampledSignal) description = get_fake_value('description', str, seed=3, obj='IrregularlySampledSignal') file_origin = get_fake_value('file_origin', str) attrs1 = { 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(IrregularlySampledSignal, annotate=False, seed=0) res12 = get_fake_values('IrregularlySampledSignal', annotate=False, seed=0) res21 = get_fake_values(IrregularlySampledSignal, annotate=True, seed=0) res22 = get_fake_values('IrregularlySampledSignal', annotate=True, seed=0) assert_array_equal(res11.pop('times'), times) assert_array_equal(res12.pop('times'), times) assert_array_equal(res21.pop('times'), times) assert_array_equal(res22.pop('times'), times) assert_array_equal(res11.pop('signal'), signal) assert_array_equal(res12.pop('signal'), signal) assert_array_equal(res21.pop('signal'), signal) assert_array_equal(res22.pop('signal'), signal) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 signal = get_fake_value('signal', pq.Quantity, seed=0, dim=2) sampling_rate = get_fake_value('sampling_rate', pq.Quantity, seed=1, dim=0) t_start = get_fake_value('t_start', pq.Quantity, seed=2, dim=0) name = get_fake_value('name', str, seed=3, obj=AnalogSignal) description = get_fake_value('description', str, seed=4, obj='AnalogSignal') file_origin = get_fake_value('file_origin', str) arr_ann = get_fake_value('array_annotations', dict, seed=6, obj=AnalogSignal, n=4) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) attrs2['array_annotations'] = arr_ann res11 = get_fake_values(AnalogSignal, annotate=False, seed=0) res12 = get_fake_values('AnalogSignal', annotate=False, seed=0) res21 = get_fake_values(AnalogSignal, annotate=True, seed=0) res22 = get_fake_values('AnalogSignal', annotate=True, seed=0) assert_arrays_equal(res11.pop('signal'), signal) assert_arrays_equal(res12.pop('signal'), signal) assert_arrays_equal(res21.pop('signal'), signal) assert_arrays_equal(res22.pop('signal'), signal) assert_arrays_equal(res11.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res12.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res21.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res22.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res11.pop('t_start'), t_start) assert_arrays_equal(res12.pop('t_start'), t_start) assert_arrays_equal(res21.pop('t_start'), t_start) assert_arrays_equal(res22.pop('t_start'), t_start) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) # Array annotations need to be compared separately # because numpy arrays define equality differently arr_ann_res21 = res21.pop('array_annotations') arr_ann_attrs2 = attrs2.pop('array_annotations') self.assertEqual(res21, attrs2) assert_arrays_equal(arr_ann_res21['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res21['number'], arr_ann_attrs2['number']) arr_ann_res22 = res22.pop('array_annotations') self.assertEqual(res22, attrs2) assert_arrays_equal(arr_ann_res22['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res22['number'], arr_ann_attrs2['number'])
def test__get_fake_values(self): self.annotations['seed'] = 0 signal = get_fake_value('signal', pq.Quantity, seed=0, dim=2) sampling_rate = get_fake_value('sampling_rate', pq.Quantity, seed=1, dim=0) t_start = get_fake_value('t_start', pq.Quantity, seed=2, dim=0) channel_index = get_fake_value('channel_index', np.ndarray, seed=3, dim=1, dtype='i') name = get_fake_value('name', str, seed=4, obj=AnalogSignalArray) description = get_fake_value('description', str, seed=5, obj='AnalogSignalArray') file_origin = get_fake_value('file_origin', str) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(AnalogSignalArray, annotate=False, seed=0) res12 = get_fake_values('AnalogSignalArray', annotate=False, seed=0) res21 = get_fake_values(AnalogSignalArray, annotate=True, seed=0) res22 = get_fake_values('AnalogSignalArray', annotate=True, seed=0) assert_arrays_equal(res11.pop('signal'), signal) assert_arrays_equal(res12.pop('signal'), signal) assert_arrays_equal(res21.pop('signal'), signal) assert_arrays_equal(res22.pop('signal'), signal) assert_arrays_equal(res11.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res12.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res21.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res22.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res11.pop('t_start'), t_start) assert_arrays_equal(res12.pop('t_start'), t_start) assert_arrays_equal(res21.pop('t_start'), t_start) assert_arrays_equal(res22.pop('t_start'), t_start) assert_arrays_equal(res11.pop('channel_index'), channel_index) assert_arrays_equal(res12.pop('channel_index'), channel_index) assert_arrays_equal(res21.pop('channel_index'), channel_index) assert_arrays_equal(res22.pop('channel_index'), channel_index) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) durations = get_fake_value('durations', pq.Quantity, seed=1, dim=1) labels = get_fake_value('labels', np.ndarray, seed=2, dim=1, dtype='S') name = get_fake_value('name', str, seed=3, obj=Epoch) description = get_fake_value('description', str, seed=4, obj='Epoch') file_origin = get_fake_value('file_origin', str) arr_ann = get_fake_value('array_annotations', dict, seed=6, obj=Epoch, n=5) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) attrs2['array_annotations'] = arr_ann res11 = get_fake_values(Epoch, annotate=False, seed=0) res12 = get_fake_values('Epoch', annotate=False, seed=0) res21 = get_fake_values(Epoch, annotate=True, seed=0) res22 = get_fake_values('Epoch', annotate=True, seed=0) assert_arrays_equal(res11.pop('times'), times) assert_arrays_equal(res12.pop('times'), times) assert_arrays_equal(res21.pop('times'), times) assert_arrays_equal(res22.pop('times'), times) assert_arrays_equal(res11.pop('durations'), durations) assert_arrays_equal(res12.pop('durations'), durations) assert_arrays_equal(res21.pop('durations'), durations) assert_arrays_equal(res22.pop('durations'), durations) assert_arrays_equal(res11.pop('labels'), labels) assert_arrays_equal(res12.pop('labels'), labels) assert_arrays_equal(res21.pop('labels'), labels) assert_arrays_equal(res22.pop('labels'), labels) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) # Array annotations need to be compared separately # because numpy arrays define equality differently arr_ann_res21 = res21.pop('array_annotations') arr_ann_attrs2 = attrs2.pop('array_annotations') self.assertEqual(res21, attrs2) assert_arrays_equal(arr_ann_res21['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res21['number'], arr_ann_attrs2['number']) arr_ann_res22 = res22.pop('array_annotations') self.assertEqual(res22, attrs2) assert_arrays_equal(arr_ann_res22['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res22['number'], arr_ann_attrs2['number'])
def test__get_fake_values(self): self.annotations['seed'] = 0 time = get_fake_value('time', pq.Quantity, seed=0, dim=0) waveform = get_fake_value('waveform', pq.Quantity, seed=1, dim=2) left_sweep = get_fake_value('left_sweep', pq.Quantity, seed=2, dim=0) sampling_rate = get_fake_value('sampling_rate', pq.Quantity, seed=3, dim=0) name = get_fake_value('name', str, seed=4, obj=Spike) description = get_fake_value('description', str, seed=5, obj='Spike') file_origin = get_fake_value('file_origin', str) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Spike, annotate=False, seed=0) res12 = get_fake_values('Spike', annotate=False, seed=0) res21 = get_fake_values(Spike, annotate=True, seed=0) res22 = get_fake_values('Spike', annotate=True, seed=0) assert_arrays_equal(res11.pop('time'), time) assert_arrays_equal(res12.pop('time'), time) assert_arrays_equal(res21.pop('time'), time) assert_arrays_equal(res22.pop('time'), time) assert_arrays_equal(res11.pop('waveform'), waveform) assert_arrays_equal(res12.pop('waveform'), waveform) assert_arrays_equal(res21.pop('waveform'), waveform) assert_arrays_equal(res22.pop('waveform'), waveform) assert_arrays_equal(res11.pop('left_sweep'), left_sweep) assert_arrays_equal(res12.pop('left_sweep'), left_sweep) assert_arrays_equal(res21.pop('left_sweep'), left_sweep) assert_arrays_equal(res22.pop('left_sweep'), left_sweep) assert_arrays_equal(res11.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res12.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res21.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res22.pop('sampling_rate'), sampling_rate) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) signal = get_fake_value('signal', pq.Quantity, seed=1, dim=2) name = get_fake_value('name', str, seed=2, obj=IrregularlySampledSignal) description = get_fake_value('description', str, seed=3, obj='IrregularlySampledSignal') file_origin = get_fake_value('file_origin', str) arr_ann = get_fake_value('array_annotations', dict, seed=5, obj=IrregularlySampledSignal, n=1) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) attrs2['array_annotations'] = arr_ann res11 = get_fake_values(IrregularlySampledSignal, annotate=False, seed=0) res12 = get_fake_values('IrregularlySampledSignal', annotate=False, seed=0) res21 = get_fake_values(IrregularlySampledSignal, annotate=True, seed=0) res22 = get_fake_values('IrregularlySampledSignal', annotate=True, seed=0) assert_array_equal(res11.pop('times'), times) assert_array_equal(res12.pop('times'), times) assert_array_equal(res21.pop('times'), times) assert_array_equal(res22.pop('times'), times) assert_array_equal(res11.pop('signal'), signal) assert_array_equal(res12.pop('signal'), signal) assert_array_equal(res21.pop('signal'), signal) assert_array_equal(res22.pop('signal'), signal) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) # Array annotations need to be compared separately # because numpy arrays define equality differently arr_ann_res21 = res21.pop('array_annotations') arr_ann_attrs2 = attrs2.pop('array_annotations') self.assertEqual(res21, attrs2) assert_arrays_equal(arr_ann_res21['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res21['number'], arr_ann_attrs2['number']) arr_ann_res22 = res22.pop('array_annotations') self.assertEqual(res22, attrs2) assert_arrays_equal(arr_ann_res22['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res22['number'], arr_ann_attrs2['number'])
def subcheck__generate_datasets(self, cls, cascade, seed=None): self.annotations['seed'] = seed if seed is None: res = fake_neo(obj_type=cls, cascade=cascade) else: res = fake_neo(obj_type=cls, cascade=cascade, seed=seed) if not hasattr(cls, 'lower'): self.assertTrue(isinstance(res, cls)) else: self.assertEqual(res.__class__.__name__, cls) assert_neo_object_is_compliant(res) self.assertEqual(res.annotations, self.annotations) resattr = get_fake_values(cls, annotate=False, seed=0) if seed is not None: for name, value in resattr.items(): if name in ['channel_names', 'channel_indexes', 'channel_index']: continue try: try: resvalue = getattr(res, name) except AttributeError: if name == 'signal': continue raise try: self.assertEqual(resvalue, value) except ValueError: assert_arrays_equal(resvalue, value) except BaseException as exc: exc.args += ('from %s' % name,) raise if not getattr(res, '_child_objects', ()): pass elif not cascade: self.assertEqual(res.children, ()) else: self.assertNotEqual(res.children, ()) if cls in ['RecordingChannelGroup', RecordingChannelGroup]: for i, rchan in enumerate(res.recordingchannels): self.assertEqual(rchan.name, res.channel_names[i].astype(str)) self.assertEqual(rchan.index, res.channel_indexes[i]) for i, unit in enumerate(res.units): for sigarr in res.analogsignalarrays: self.assertEqual(unit.channel_indexes[0], sigarr.channel_index[i])
def test__get_fake_values(self): self.annotations['seed'] = 0 name = get_fake_value('name', str, seed=0, obj=Unit) description = get_fake_value('description', str, seed=1, obj='Unit') file_origin = get_fake_value('file_origin', str) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(Unit, annotate=False, seed=0) res12 = get_fake_values('Unit', annotate=False, seed=0) res21 = get_fake_values(Unit, annotate=True, seed=0) res22 = get_fake_values('Unit', annotate=True, seed=0) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def subcheck__generate_datasets(self, cls, cascade, seed=None): self.annotations['seed'] = seed if seed is None: res = fake_neo(obj_type=cls, cascade=cascade) else: res = fake_neo(obj_type=cls, cascade=cascade, seed=seed) if not hasattr(cls, 'lower'): self.assertTrue(isinstance(res, cls)) else: self.assertEqual(res.__class__.__name__, cls) assert_neo_object_is_compliant(res) self.assertEqual(res.annotations, self.annotations) resattr = get_fake_values(cls, annotate=False, seed=0) if seed is not None: for name, value in resattr.items(): if name in [ 'channel_names', 'channel_indexes', 'channel_index', 'coordinates' ]: continue try: try: resvalue = getattr(res, name) except AttributeError: if name == 'signal': continue raise try: self.assertEqual(resvalue, value) except ValueError: assert_arrays_equal(resvalue, value) except BaseException as exc: exc.args += ('from %s' % name, ) raise if not getattr(res, '_child_objects', ()): pass elif not cascade: self.assertEqual(res.children, ()) else: self.assertNotEqual(res.children, ()) if cls in ['ChannelIndex', ChannelIndex]: for i, unit in enumerate(res.units): for sigarr in res.analogsignals: self.assertEqual(unit.get_channel_indexes()[0], sigarr.get_channel_index()[i])
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) signal = get_fake_value('signal', pq.Quantity, seed=1, dim=2) name = get_fake_value('name', str, seed=2, obj=IrregularlySampledSignal) description = get_fake_value('description', str, seed=3, obj='IrregularlySampledSignal') file_origin = get_fake_value('file_origin', str) attrs1 = {'name': name, 'description': description, 'file_origin': file_origin} attrs2 = attrs1.copy() attrs2.update(self.annotations) res11 = get_fake_values(IrregularlySampledSignal, annotate=False, seed=0) res12 = get_fake_values('IrregularlySampledSignal', annotate=False, seed=0) res21 = get_fake_values(IrregularlySampledSignal, annotate=True, seed=0) res22 = get_fake_values('IrregularlySampledSignal', annotate=True, seed=0) assert_array_equal(res11.pop('times'), times) assert_array_equal(res12.pop('times'), times) assert_array_equal(res21.pop('times'), times) assert_array_equal(res22.pop('times'), times) assert_array_equal(res11.pop('signal'), signal) assert_array_equal(res12.pop('signal'), signal) assert_array_equal(res21.pop('signal'), signal) assert_array_equal(res22.pop('signal'), signal) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) self.assertEqual(res21, attrs2) self.assertEqual(res22, attrs2)
def test__get_fake_values(self): self.annotations['seed'] = 0 times = get_fake_value('times', pq.Quantity, seed=0, dim=1) signal = get_fake_value('signal', pq.Quantity, seed=1, dim=2) name = get_fake_value('name', str, seed=2, obj=IrregularlySampledSignal) description = get_fake_value('description', str, seed=3, obj='IrregularlySampledSignal') file_origin = get_fake_value('file_origin', str) arr_ann = get_fake_value('array_annotations', dict, seed=5, obj=IrregularlySampledSignal, n=1) attrs1 = { 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) attrs2['array_annotations'] = arr_ann res11 = get_fake_values(IrregularlySampledSignal, annotate=False, seed=0) res12 = get_fake_values('IrregularlySampledSignal', annotate=False, seed=0) res21 = get_fake_values(IrregularlySampledSignal, annotate=True, seed=0) res22 = get_fake_values('IrregularlySampledSignal', annotate=True, seed=0) assert_array_equal(res11.pop('times'), times) assert_array_equal(res12.pop('times'), times) assert_array_equal(res21.pop('times'), times) assert_array_equal(res22.pop('times'), times) assert_array_equal(res11.pop('signal'), signal) assert_array_equal(res12.pop('signal'), signal) assert_array_equal(res21.pop('signal'), signal) assert_array_equal(res22.pop('signal'), signal) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) # Array annotations need to be compared separately # because numpy arrays define equality differently arr_ann_res21 = res21.pop('array_annotations') arr_ann_attrs2 = attrs2.pop('array_annotations') self.assertEqual(res21, attrs2) assert_arrays_equal(arr_ann_res21['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res21['number'], arr_ann_attrs2['number']) arr_ann_res22 = res22.pop('array_annotations') self.assertEqual(res22, attrs2) assert_arrays_equal(arr_ann_res22['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res22['number'], arr_ann_attrs2['number'])
def test__get_fake_values(self): self.annotations['seed'] = 0 signal = get_fake_value('signal', pq.Quantity, seed=0, dim=2) sampling_rate = get_fake_value('sampling_rate', pq.Quantity, seed=1, dim=0) t_start = get_fake_value('t_start', pq.Quantity, seed=2, dim=0) name = get_fake_value('name', str, seed=3, obj=AnalogSignal) description = get_fake_value('description', str, seed=4, obj='AnalogSignal') file_origin = get_fake_value('file_origin', str) arr_ann = get_fake_value('array_annotations', dict, seed=6, obj=AnalogSignal, n=4) attrs1 = { 'name': name, 'description': description, 'file_origin': file_origin } attrs2 = attrs1.copy() attrs2.update(self.annotations) attrs2['array_annotations'] = arr_ann res11 = get_fake_values(AnalogSignal, annotate=False, seed=0) res12 = get_fake_values('AnalogSignal', annotate=False, seed=0) res21 = get_fake_values(AnalogSignal, annotate=True, seed=0) res22 = get_fake_values('AnalogSignal', annotate=True, seed=0) assert_arrays_equal(res11.pop('signal'), signal) assert_arrays_equal(res12.pop('signal'), signal) assert_arrays_equal(res21.pop('signal'), signal) assert_arrays_equal(res22.pop('signal'), signal) assert_arrays_equal(res11.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res12.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res21.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res22.pop('sampling_rate'), sampling_rate) assert_arrays_equal(res11.pop('t_start'), t_start) assert_arrays_equal(res12.pop('t_start'), t_start) assert_arrays_equal(res21.pop('t_start'), t_start) assert_arrays_equal(res22.pop('t_start'), t_start) self.assertEqual(res11, attrs1) self.assertEqual(res12, attrs1) # Array annotations need to be compared separately # because numpy arrays define equality differently arr_ann_res21 = res21.pop('array_annotations') arr_ann_attrs2 = attrs2.pop('array_annotations') self.assertEqual(res21, attrs2) assert_arrays_equal(arr_ann_res21['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res21['number'], arr_ann_attrs2['number']) arr_ann_res22 = res22.pop('array_annotations') self.assertEqual(res22, attrs2) assert_arrays_equal(arr_ann_res22['valid'], arr_ann_attrs2['valid']) assert_arrays_equal(arr_ann_res22['number'], arr_ann_attrs2['number'])