def __init__(self, name=None, description=None, file_origin=None, file_datetime=None, rec_datetime=None, index=None, **annotations): BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.file_datetime = file_datetime self.rec_datetime = rec_datetime self.index = index self.epochs = [] self.epocharrays = [] self.events = [] self.eventarrays = [] self.analogsignals = [] self.analogsignalarrays = [] self.irregularlysampledsignals = [] self.spikes = [] self.spiketrains = [] self.block = None
def __init__(self, times=None, durations=None, labels=None, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`EpochArray` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) if times is None: times = np.array([]) * pq.s if durations is None: durations = np.array([]) * pq.s if labels is None: labels = np.array([], dtype='S') self.times = times self.durations = durations self.labels = labels self.segment = None
def setUp(self): self.name1 = 'a base 1' self.name2 = 'a base 2' self.description1 = 'this is a test 1' self.description2 = 'this is a test 2' self.base1 = BaseNeo(name=self.name1, description=self.description1) self.base2 = BaseNeo(name=self.name2, description=self.description2)
def __init__(self, times=None, durations=None, labels=None, units=None, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`Epoch` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, channel_names=None, channel_indexes=None, name=None, description=None, file_origin=None, **annotations): """Initialize a new RecordingChannelGroup.""" # Inherited initialization # Sets universally recommended attributes, and places all others # in annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) # Defaults if channel_indexes is None: channel_indexes = np.array([]) if channel_names is None: channel_names = np.array([]) # Store recommended attributes self.channel_names = channel_names self.channel_indexes = channel_indexes # Initialize containers for child objects self.analogsignalarrays = [] self.units = [] # Many to many relationship self.recordingchannels = [] self.block = None
def __init__(self, time=0 * pq.s, waveform=None, sampling_rate=None, left_sweep=None, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`Spike` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.time = time self.waveform = waveform self.left_sweep = left_sweep self.sampling_rate = sampling_rate self.segment = None self.unit = None
def __init__(self, index=0, coordinate=None, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`RecordingChannel` instance. ''' # Inherited initialization # Sets universally recommended attributes, and places all others # in annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) # Store required and recommended attributes self.index = index self.coordinate = coordinate # Initialize contianers self.analogsignals = [] self.irregularlysampledsignals = [] # Many to many relationship self.recordingchannelgroups = []
def __init__(self, times=None, durations=None, labels=None, units=None, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`Epoch` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, times, t_stop, units=None, dtype=np.float, copy=True, sampling_rate=1.0 * pq.Hz, t_start=0.0 * pq.s, waveforms=None, left_sweep=None, name=None, file_origin=None, description=None, **annotations): ''' Initializes a newly constructed :class:`SpikeTrain` instance. ''' # This method is only called when constructing a new SpikeTrain, # not when slicing or viewing. We use the same call signature # as __new__ for documentation purposes. Anything not in the call # signature is stored in annotations. # Calls parent __init__, which grabs universally recommended # attributes and sets up self.annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, **annotations): ''' Initializes a newly constructed :class:`AnalogSignal` instance. ''' # This method is only called when constructing a new AnalogSignal, # not when slicing or viewing. We use the same call signature # as __new__ for documentation purposes. Anything not in the call # signature is stored in annotations. # Calls parent __init__, which grabs universally recommended # attributes and sets up self.annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, channel_names=None, channel_indexes=None, name=None, description=None, file_origin=None, **annotations): """Initialize a new RecordingChannelGroup.""" # Inherited initialization # Sets universally recommended attributes, and places all others # in annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) # Defaults if channel_indexes is None: channel_indexes = np.array([]) if channel_names is None: channel_names = np.array([]) # Store recommended attributes self.channel_names = channel_names self.channel_indexes = channel_indexes # Initialize containers for child objects self.analogsignalarrays = [] self.units = [] # Many to many relationship self.recordingchannels = [] self.block = None
def __init__(self, array_annotations=None, **annotations): # this for py27 str vs py3 str in neo attributes ompatibility annotations = check_annotations(annotations) if 'file_origin' not in annotations: # the str is to make compatible with neo_py27 where attribute # used to be str so raw bytes annotations['file_origin'] = str(self._rawio.source_name()) if array_annotations is None: array_annotations = {} for k, v in array_annotations.items(): array_annotations[k] = np.asarray(v) # clean array annotations that are not 1D # TODO remove this once multi-dimensional array_annotations are possible array_annotations = { k: v for k, v in array_annotations.items() if v.ndim == 1 } # this mock the array annotations to avoid inherits DataObject self.array_annotations = ArrayDict(self.shape[-1]) self.array_annotations.update(array_annotations) BaseNeo.__init__(self, **annotations)
def __init__(self, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, channel_index=None, **annotations): ''' Initializes a newly constructed :class:`AnalogSignalArray` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, time, label, name=None, description=None, file_origin=None, **annotations): """Initialize a new Event.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.time = time self.label = label self.segment =None
def __init__(self, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, channel_index=None, **annotations): ''' Initializes a newly constructed :class:`AnalogSignalArray` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, times, signal, units=None, time_units=None, dtype=None, copy=True, name=None, file_origin=None, description=None, **annotations): ''' Initializes a newly constructed :class:`IrregularlySampledSignal` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, times, signal, units=None, time_units=None, dtype=None, copy=True, name=None, description=None, file_origin=None, **annotations): ''' Initializes a newly constructed :class:`IrregularlySampledSignal` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, times=np.array([]) * pq.s, labels=np.array([], dtype='S'), name=None, description=None, file_origin=None, **annotations): """Initialize a new EventArray.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.times = times self.labels = labels self.segment = None
def __init__(self, time, label, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`Event` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.time = time self.label = label self.segment = None
def __init__(self, times, values, name=None, description=None, file_origin=None, **annotations): """Initalize a new IrregularlySampledSignal.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.times = times self.values = values self.segment = None self.recordingchannel = None
def __init__(self, name=None, description=None, file_origin=None, channel_indexes = None, **annotations): """Initialize a new neuronal Unit (spike source)""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.channel_indexes = channel_indexes self.spiketrains = [ ] self.spikes = [ ] self.recordingchannelgroup = None
def __init__(self, name=None, description=None, file_origin=None, file_datetime=None, rec_datetime=None, index=None, **annotations): """Initalize a new Block.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.file_datetime = file_datetime self.rec_datetime = rec_datetime self.index = index self.segments = [] self.recordingchannelgroups = []
def __init__(self, array_annotations=None, **annotations): # this for py27 str vs py3 str in neo attributes ompatibility annotations = check_annotations(annotations) if 'file_origin' not in annotations: # the str is to make compatible with neo_py27 where attribute # used to be str so raw bytes annotations['file_origin'] = str(self._rawio.source_name()) # this mock the array annotaions to avoid inherits DataObject self.array_annotations = ArrayDict(self.shape[-1]) if array_annotations is not None: self.array_annotations.update(array_annotations) BaseNeo.__init__(self, **annotations)
def __init__(self, times, t_stop, units=None, dtype=np.float, copy=True, sampling_rate=1.0 * pq.Hz, t_start=0.0 * pq.s, waveforms=None, left_sweep=None, name=None, file_origin=None, description=None, **annotations): """Initializes newly constructed SpikeTrain.""" # This method is only called when constructing a new SpikeTrain, # not when slicing or viewing. We use the same call signature # as __new__ for documentation purposes. Anything not in the call # signature is stored in annotations. # Calls parent __init__, which grabs universally recommended # attributes and sets up self.annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, array_annotations=None, **annotations): # this for py27 str vs py3 str in neo attributes ompatibility annotations = check_annotations(annotations) if 'file_origin' not in annotations: # the str is to make compatible with neo_py27 where attribute # used to be str so raw bytes annotations['file_origin'] = str(self._rawio.source_name()) # this mock the array annotaions to avoid inherits DataObject self.array_annotations = ArrayDict(self.shape[-1]) if array_annotations is not None: self.array_annotations.update(array_annotations) BaseNeo.__init__(self, **annotations)
def test__children(self): base = BaseNeo() self.assertEqual(base._container_child_objects, ()) self.assertEqual(base._data_child_objects, ()) self.assertEqual(base._single_parent_objects, ()) self.assertEqual(base._multi_child_objects, ()) self.assertEqual(base._multi_parent_objects, ()) self.assertEqual(base._child_properties, ()) self.assertEqual(base._single_child_objects, ()) self.assertEqual(base._container_child_containers, ()) self.assertEqual(base._data_child_containers, ()) self.assertEqual(base._single_child_containers, ()) self.assertEqual(base._single_parent_containers, ()) self.assertEqual(base._multi_child_containers, ()) self.assertEqual(base._multi_parent_containers, ()) self.assertEqual(base._child_objects, ()) self.assertEqual(base._child_containers, ()) self.assertEqual(base._parent_objects, ()) self.assertEqual(base._parent_containers, ()) self.assertEqual(base.children, ()) self.assertEqual(base.parents, ()) base.create_many_to_one_relationship() base.create_many_to_many_relationship() base.create_relationship()
def __init__(self, times=None, labels=None, name=None, description=None, file_origin=None, **annotations): """ Initialize a new :class:`EventArray` instance. """ BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) if times is None: times = np.array([]) * pq.s if labels is None: labels = np.array([], dtype="S") self.times = times self.labels = labels self.segment = None
def __init__(self, name=None, description=None, file_origin=None, channel_indexes=None, **annotations): ''' Initialize a new :clas:`Unit` instance (spike source) ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.channel_indexes = channel_indexes self.spiketrains = [] self.spikes = [] self.recordingchannelgroup = None
def test_annotate(self): '''test to make sure annotation works properly''' base = BaseNeo() base.annotate(test1=1, test2=1) result1 = {'test1': 1, 'test2': 1} self.assertDictEqual(result1, base.annotations) base.annotate(test3=2, test4=3) result2 = {'test3': 2, 'test4': 3} result2a = dict(list(result1.items()) + list(result2.items())) self.assertDictContainsSubset(result1, base.annotations) self.assertDictContainsSubset(result2, base.annotations) self.assertDictEqual(result2a, base.annotations) base.annotate(test1=5, test2=8) result3 = {'test1': 5, 'test2': 8} result3a = dict(list(result3.items()) + list(result2.items())) self.assertDictContainsSubset(result2, base.annotations) self.assertDictContainsSubset(result3, base.annotations) self.assertDictEqual(result3a, base.annotations) self.assertNotEqual(base.annotations['test1'], result1['test1']) self.assertNotEqual(base.annotations['test2'], result1['test2'])
def __init__(self, name=None, description=None, file_origin=None, array_annotations=None, **annotations): """ This method is called by each data object and initializes the newly created object by adding array annotations and calling __init__ of the super class, where more annotations and attributes are processed. """ if not hasattr(self, 'array_annotations') or not self.array_annotations: self.array_annotations = ArrayDict(self._get_arr_ann_length()) if array_annotations is not None: self.array_annotate(**array_annotations) BaseNeo.__init__(self, name=name, description=description, file_origin=file_origin, **annotations)
def __init__(self, name=None, description=None, file_origin=None, array_annotations=None, **annotations): """ This method is called by each data object and initializes the newly created object by adding array annotations and calling __init__ of the super class, where more annotations and attributes are processed. """ if not hasattr(self, 'array_annotations') or not self.array_annotations: self.array_annotations = ArrayDict(self._get_arr_ann_length()) if array_annotations is not None: self.array_annotate(**array_annotations) BaseNeo.__init__(self, name=name, description=description, file_origin=file_origin, **annotations)
def __init__(self, time=0*pq.s, waveform=None, sampling_rate=None, left_sweep=None, name=None, description=None, file_origin=None, **annotations): """Initialize a new Spike.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.time = time self.waveform = waveform self.left_sweep = left_sweep self.sampling_rate = sampling_rate self.segment = None self.unit = None
def __init__(self, signal, units=None, dtype=None, copy=True, t_start=0 * pq.s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, channel_index=None, **annotations): ''' Initializes a newly constructed :class:`BaseAnalogSignal` instance. ''' # This method is only called when constructing a new BaseAnalogSignal, # not when slicing or viewing. We use the same call signature # as __new__ for documentation purposes. Anything not in the call # signature is stored in annotations. # Calls parent __init__, which grabs universally recommended # attributes and sets up self.annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def test__pretty(self): name = 'an object' description = 'this is a test' obj = BaseNeo(name=name, description=description) res = pretty(obj) targ = "BaseNeo name: '%s' description: '%s'" % (name, description) self.assertEqual(res, targ)
def setUp(self): self.name1 = 'a base 1' self.name2 = 'a base 2' self.description1 = 'this is a test 1' self.description2 = 'this is a test 2' self.base1 = BaseNeo(name=self.name1, description=self.description1) self.base2 = BaseNeo(name=self.name2, description=self.description2)
def __init__(self, times=np.array([]) * pq.s, labels=np.array([], dtype='S'), name=None, description=None, file_origin=None, **annotations): """Initialize a new EventArray.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.times = times self.labels = labels self.segment = None
def __init__(self, times, signal, units=None, time_units=None, dtype=None, copy=True, name=None, description=None, file_origin=None, **annotations): """Initalize a new IrregularlySampledSignal.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations)
def __init__(self, time, label, name=None, description=None, file_origin=None, **annotations): """Initialize a new Event.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.time = time self.label = label self.segment = None
def test__children(self): base = BaseNeo() self.assertEqual(base._container_child_objects, ()) self.assertEqual(base._data_child_objects, ()) self.assertEqual(base._single_parent_objects, ()) self.assertEqual(base._multi_child_objects, ()) self.assertEqual(base._multi_parent_objects, ()) self.assertEqual(base._child_properties, ()) self.assertEqual(base._single_child_objects, ()) self.assertEqual(base._container_child_containers, ()) self.assertEqual(base._data_child_containers, ()) self.assertEqual(base._single_child_containers, ()) self.assertEqual(base._single_parent_containers, ()) self.assertEqual(base._multi_child_containers, ()) self.assertEqual(base._multi_parent_containers, ()) self.assertEqual(base._child_objects, ()) self.assertEqual(base._child_containers, ()) self.assertEqual(base._parent_objects, ()) self.assertEqual(base._parent_containers, ()) self.assertEqual(base.children, ()) self.assertEqual(base.parents, ()) base.create_many_to_one_relationship() base.create_many_to_many_relationship() base.create_relationship()
def test_annotate(self): '''test to make sure annotation works properly''' base = BaseNeo() base.annotate(test1=1, test2=1) result1 = {'test1': 1, 'test2': 1} self.assertDictEqual(result1, base.annotations) base.annotate(test3=2, test4=3) result2 = {'test3': 2, 'test4': 3} result2a = dict(list(result1.items()) + list(result2.items())) self.assertDictContainsSubset(result1, base.annotations) self.assertDictContainsSubset(result2, base.annotations) self.assertDictEqual(result2a, base.annotations) base.annotate(test1=5, test2=8) result3 = {'test1': 5, 'test2': 8} result3a = dict(list(result3.items()) + list(result2.items())) self.assertDictContainsSubset(result2, base.annotations) self.assertDictContainsSubset(result3, base.annotations) self.assertDictEqual(result3a, base.annotations) self.assertNotEqual(base.annotations['test1'], result1['test1']) self.assertNotEqual(base.annotations['test2'], result1['test2'])
def __init__(self, index=0, coordinate=None, name=None, description=None, file_origin=None, **annotations): """Initialize a new RecordingChannel.""" # Inherited initialization # Sets universally recommended attributes, and places all others # in annotations BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) # Store required and recommended attributes self.index = index self.coordinate = coordinate # Initialize contianers self.analogsignals = [ ] self.irregularlysampledsignals = [ ] # Many to many relationship self.recordingchannelgroups = [ ]
def __init__(self, name=None, description=None, file_origin=None, channel_indexes=None, **annotations): """Initialize a new neuronal Unit (spike source)""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.channel_indexes = channel_indexes self.spiketrains = [] self.spikes = [] self.recordingchannelgroup = None
def __init__(self, name=None, description=None, file_origin=None, file_datetime=None, rec_datetime=None, index=None, **annotations): BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.file_datetime = file_datetime self.rec_datetime = rec_datetime self.index = index self.epochs = [ ] self.epocharrays = [ ] self.events = [ ] self.eventarrays = [ ] self.analogsignals = [ ] self.analogsignalarrays = [ ] self.irregularlysampledsignals = [ ] self.spikes = [ ] self.spiketrains = [ ] self.block = None
def __init__(self, times=None, durations=None, labels=None, name=None, description=None, file_origin=None, **annotations): ''' Initialize a new :class:`EpochArray` instance. ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) if times is None: times = np.array([]) * pq.s if durations is None: durations = np.array([]) * pq.s if labels is None: labels = np.array([], dtype='S') self.times = times self.durations = durations self.labels = labels self.segment = None
def __init__(self, name=None, description=None, file_origin=None, channel_indexes=None, **annotations): ''' Initialize a new :clas:`Unit` instance (spike source) ''' BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.channel_indexes = channel_indexes self.spiketrains = [] self.spikes = [] self.recordingchannelgroup = None
def __init__(self, name=None, description=None, file_origin=None, file_datetime=None, rec_datetime=None, index=None, **annotations): """Initalize a new Block.""" BaseNeo.__init__(self, name=name, file_origin=file_origin, description=description, **annotations) self.file_datetime = file_datetime self.rec_datetime = rec_datetime self.index = index self.segments = [] self.recordingchannelgroups = []
class TestBaseNeoQuantitiesScalarTypes(unittest.TestCase): """ TestCase to make sure annotations are properly checked for quantities scalars """ def setUp(self): """create the instance to be tested, called before every test""" self.base = BaseNeo() def test_quantities_scalar_int(self): """test to make sure int type quantites scalars are accepted""" value = quantities.Quantity(99, dtype=numpy.int, units=quantities.s) self.base.annotate(data=value) result = {"data": value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_uint(self): """test to make sure uint type quantites scalars are accepted""" value = quantities.Quantity(99, dtype=numpy.uint, units=quantities.meter) self.base.annotate(data=value) result = {"data": value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_float(self): """test to make sure float type quantites scalars are accepted""" value = 99 * quantities.kg self.base.annotate(data=value) result = {"data": value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_str(self): """test to make sure str type quantites scalars are rejected""" value = quantities.Quantity(99, dtype=numpy.str, units=quantities.meter) self.assertRaises(ValueError, self.base.annotate, data=value)
def test__children(self): base = BaseNeo() self.assertEqual(base._single_parent_objects, ()) self.assertEqual(base._multi_parent_objects, ()) self.assertEqual(base._single_parent_containers, ()) self.assertEqual(base._multi_parent_containers, ()) self.assertEqual(base._parent_objects, ()) self.assertEqual(base._parent_containers, ()) self.assertEqual(base.parents, ())
class TestBaseNeoContainerTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for data type inside python built-in container types ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_python_list(self): '''test to make sure list type data is accepted''' value = [None, 10, 9.2, complex(23, 11), ['this is a test', bytes('1,2,3,4,5')], [Fraction(13, 21), Decimal("3.14")]] self.base.annotate(data=value) result = {'data': value} self.assertListEqual(value, self.base.annotations['data']) self.assertDictEqual(result, self.base.annotations) def test_python_tuple(self): '''test to make sure tuple type data is accepted''' value = (None, 10, 9.2, complex(23, 11), ('this is a test', bytes('1,2,3,4,5')), (Fraction(13, 21), Decimal("3.14"))) self.base.annotate(data=value) result = {'data': value} self.assertTupleEqual(value, self.base.annotations['data']) self.assertDictEqual(result, self.base.annotations) def test_python_dict(self): '''test to make sure dict type data is accepted''' value = {'NoneType': None, 'int': 10, 'float': 9.2, 'complex': complex(23, 11), 'dict1': {'string': 'this is a test', 'bytes': bytes('1,2,3,4,5')}, 'dict2': {'Fraction': Fraction(13, 21), 'Decimal': Decimal("3.14")}} self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_python_set(self): '''test to make sure set type data is rejected''' value = {None, 10, 9.2, complex(23, 11)} self.assertRaises(ValueError, self.base.annotate, data=value) def test_python_frozenset(self): '''test to make sure frozenset type data is rejected''' value = frozenset([None, 10, 9.2, complex(23, 11)]) self.assertRaises(ValueError, self.base.annotate, data=value) def test_python_iter(self): '''test to make sure iter type data is rejected''' value = iter([None, 10, 9.2, complex(23, 11)]) self.assertRaises(ValueError, self.base.annotate, data=value)
class TestBaseNeoContainerTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for data type inside python built-in container types ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_python_list(self): '''test to make sure list type data is accepted''' value = [None, 10, 9.2, complex(23, 11), ['this is a test', bytes('1,2,3,4,5')], [Fraction(13, 21), Decimal("3.14")]] self.base.annotate(data=value) result = {'data': value} self.assertListEqual(value, self.base.annotations['data']) self.assertDictEqual(result, self.base.annotations) def test_python_tuple(self): '''test to make sure tuple type data is accepted''' value = (None, 10, 9.2, complex(23, 11), ('this is a test', bytes('1,2,3,4,5')), (Fraction(13, 21), Decimal("3.14"))) self.base.annotate(data=value) result = {'data': value} self.assertTupleEqual(value, self.base.annotations['data']) self.assertDictEqual(result, self.base.annotations) def test_python_dict(self): '''test to make sure dict type data is accepted''' value = {'NoneType': None, 'int': 10, 'float': 9.2, 'complex': complex(23, 11), 'dict1': {'string': 'this is a test', 'bytes': bytes('1,2,3,4,5')}, 'dict2': {'Fraction': Fraction(13, 21), 'Decimal': Decimal("3.14")}} self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_python_set(self): '''test to make sure set type data is rejected''' value = set([None, 10, 9.2, complex(23, 11)]) self.assertRaises(ValueError, self.base.annotate, data=value) def test_python_frozenset(self): '''test to make sure frozenset type data is rejected''' value = frozenset([None, 10, 9.2, complex(23, 11)]) self.assertRaises(ValueError, self.base.annotate, data=value) def test_python_iter(self): '''test to make sure iter type data is rejected''' value = iter([None, 10, 9.2, complex(23, 11)]) self.assertRaises(ValueError, self.base.annotate, data=value)
class TestBaseNeoQuantitiesArrayTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for quantities arrays ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_quantities_array_int(self): '''test to make sure int type quantites arrays are accepted''' value = quantities.Quantity([1, 2, 3, 4, 5], dtype=numpy.int, units=quantities.s) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_array_uint(self): '''test to make sure uint type quantites arrays are accepted''' value = quantities.Quantity([1, 2, 3, 4, 5], dtype=numpy.uint, units=quantities.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_array_float(self): '''test to make sure float type quantites arrays are accepted''' value = [1, 2, 3, 4, 5] * quantities.kg self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_array_str(self): '''test to make sure str type quantites arrays are accepted''' value = quantities.Quantity([1, 2, 3, 4, 5], dtype=numpy.str, units=quantities.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations)
class TestBaseNeoQuantitiesArrayTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for quantities arrays ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_quantities_array_int(self): '''test to make sure int type quantites arrays are accepted''' value = quantities.Quantity([1, 2, 3, 4, 5], dtype=numpy.int, units=quantities.s) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_array_uint(self): '''test to make sure uint type quantites arrays are accepted''' value = quantities.Quantity([1, 2, 3, 4, 5], dtype=numpy.uint, units=quantities.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_array_float(self): '''test to make sure float type quantites arrays are accepted''' value = [1, 2, 3, 4, 5] * quantities.kg self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_array_str(self): '''test to make sure str type quantites arrays are accepted''' value = quantities.Quantity([1, 2, 3, 4, 5], dtype=numpy.str, units=quantities.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations)
class TestBaseNeoQuantitiesScalarTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for quantities scalars ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_quantities_scalar_int(self): '''test to make sure int type quantites scalars are accepted''' value = pq.Quantity(99, dtype=np.int, units=pq.s) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_uint(self): '''test to make sure uint type quantites scalars are accepted''' value = pq.Quantity(99, dtype=np.uint, units=pq.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_float(self): '''test to make sure float type quantites scalars are accepted''' value = 99 * pq.kg self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_str(self): '''test to make sure str type quantites scalars are accepted''' value = pq.Quantity(99, dtype=np.str, units=pq.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations)
class TestBaseNeoQuantitiesScalarTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for quantities scalars ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_quantities_scalar_int(self): '''test to make sure int type quantites scalars are accepted''' value = pq.Quantity(99, dtype=np.int, units=pq.s) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_uint(self): '''test to make sure uint type quantites scalars are accepted''' value = pq.Quantity(99, dtype=np.uint, units=pq.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_float(self): '''test to make sure float type quantites scalars are accepted''' value = 99 * pq.kg self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_quantities_scalar_str(self): '''test to make sure str type quantites scalars are accepted''' value = pq.Quantity(99, dtype=np.str, units=pq.meter) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations)
def test_annotate(self): """test to make sure annotation works properly""" base = BaseNeo() base.annotate(test1=1, test2=1) result1 = {"test1": 1, "test2": 1} self.assertDictEqual(result1, base.annotations) base.annotate(test3=2, test4=3) result2 = {"test3": 2, "test4": 3} result2a = dict(result1.items() + result2.items()) self.assertDictContainsSubset(result1, base.annotations) self.assertDictContainsSubset(result2, base.annotations) self.assertDictEqual(result2a, base.annotations) base.annotate(test1=5, test2=8) result3 = {"test1": 5, "test2": 8} result3a = dict(result3.items() + result2.items()) self.assertDictContainsSubset(result2, base.annotations) self.assertDictContainsSubset(result3, base.annotations) self.assertDictEqual(result3a, base.annotations) self.assertNotEqual(base.annotations["test1"], result1["test1"]) self.assertNotEqual(base.annotations["test2"], result1["test2"])
def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo()
def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo()
class TestBaseNeoNumpyScalarTypes(unittest.TestCase): ''' TestCase to make sure annotations are properly checked for numpy scalars ''' def setUp(self): '''create the instance to be tested, called before every test''' self.base = BaseNeo() def test_numpy_scalar_int(self): '''test to make sure int type numpy scalars are accepted''' value = np.array(99, dtype=np.int) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_uint(self): '''test to make sure uint type numpy scalars are accepted''' value = np.array(99, dtype=np.uint) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_int0(self): '''test to make sure int0 type numpy scalars are accepted''' value = np.array(99, dtype=np.int0) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_uint0(self): '''test to make sure uint0 type numpy scalars are accepted''' value = np.array(99, dtype=np.uint0) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_int8(self): '''test to make sure int8 type numpy scalars are accepted''' value = np.array(99, dtype=np.int8) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_uint8(self): '''test to make sure uint8 type numpy scalars are accepted''' value = np.array(99, dtype=np.uint8) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_int16(self): '''test to make sure int16 type numpy scalars are accepted''' value = np.array(99, dtype=np.int16) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_uint16(self): '''test to make sure uint16 type numpy scalars are accepted''' value = np.array(99, dtype=np.uint16) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_int32(self): '''test to make sure int32 type numpy scalars are accepted''' value = np.array(99, dtype=np.int32) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_uint32(self): '''test to make sure uint32 type numpy scalars are accepted''' value = np.array(99, dtype=np.uint32) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_int64(self): '''test to make sure int64 type numpy scalars are accepted''' value = np.array(99, dtype=np.int64) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_uint64(self): '''test to make sure uint64 type numpy scalars are accepted''' value = np.array(99, dtype=np.uint64) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_float(self): '''test to make sure float type numpy scalars are accepted''' value = np.array(99, dtype=np.float) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_floating(self): '''test to make sure floating type numpy scalars are accepted''' value = np.array(99, dtype=np.floating) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_double(self): '''test to make sure double type numpy scalars are accepted''' value = np.array(99, dtype=np.double) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_float16(self): '''test to make sure float16 type numpy scalars are accepted''' value = np.array(99, dtype=np.float16) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_float32(self): '''test to make sure float32 type numpy scalars are accepted''' value = np.array(99, dtype=np.float32) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_float64(self): '''test to make sure float64 type numpy scalars are accepted''' value = np.array(99, dtype=np.float64) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) @unittest.skipUnless(hasattr(np, "float128"), "float128 not available") def test_numpy_scalar_float128(self): '''test to make sure float128 type numpy scalars are accepted''' value = np.array(99, dtype=np.float128) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_complex(self): '''test to make sure complex type numpy scalars are accepted''' value = np.array(99, dtype=np.complex) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_complex64(self): '''test to make sure complex64 type numpy scalars are accepted''' value = np.array(99, dtype=np.complex64) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_complex128(self): '''test to make sure complex128 type numpy scalars are accepted''' value = np.array(99, dtype=np.complex128) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) @unittest.skipUnless(hasattr(np, "complex256"), "complex256 not available") def test_numpy_scalar_complex256(self): '''test to make sure complex256 type numpy scalars are accepted''' value = np.array(99, dtype=np.complex256) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_bool(self): '''test to make sure bool type numpy scalars are rejected''' value = np.array(99, dtype=np.bool) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_array_str(self): '''test to make sure str type numpy scalars are accepted''' value = np.array(99, dtype=np.str) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations) def test_numpy_scalar_string0(self): '''test to make sure string0 type numpy scalars are rejected''' if sys.version_info[0] >= 3: dtype = np.str0 else: dtype = np.string0 value = np.array(99, dtype=dtype) self.base.annotate(data=value) result = {'data': value} self.assertDictEqual(result, self.base.annotations)
def test_init(self): '''test to make sure initialization works properly''' base = BaseNeo(name='a base', description='this is a test') self.assertEqual(base.name, 'a base') self.assertEqual(base.description, 'this is a test') self.assertEqual(base.file_origin, None)