def test__int(self): name = 'test__int' datatype = int targ = np.random.randint(100) res = get_fake_value(name, datatype, seed=0) self.assertTrue(isinstance(res, int)) self.assertEqual(targ, res)
def test__float(self): name = 'test__float' datatype = float targ = 1000. * np.random.random() res = get_fake_value(name, datatype, seed=0) self.assertTrue(isinstance(res, float)) self.assertEqual(targ, res)
def test__str(self): name = 'test__str' datatype = str targ = str(np.random.randint(100000)) res = get_fake_value(name, datatype, seed=0) self.assertTrue(isinstance(res, str)) self.assertEqual(targ, res)
def test__sampling_rate(self): name = 'sampling_rate' datatype = pq.Quantity targ = 10000.0 * pq.Hz res = get_fake_value(name, datatype) self.assertTrue(isinstance(res, pq.Quantity)) self.assertEqual(res.units, pq.Hz) assert_arrays_equal(targ, res) self.assertRaises(ValueError, get_fake_value, name, datatype, dim=1) self.assertRaises(ValueError, get_fake_value, name, np.ndarray)
def test__t_stop(self): name = 't_stop' datatype = pq.Quantity targ = 1.0 * pq.millisecond res = get_fake_value(name, datatype) self.assertTrue(isinstance(res, pq.Quantity)) self.assertEqual(res.units, pq.millisecond) assert_arrays_equal(targ, res) self.assertRaises(ValueError, get_fake_value, name, datatype, dim=1) self.assertRaises(ValueError, get_fake_value, name, np.ndarray)
def test__ndarray(self): name = 'test__quantity' datatype = np.ndarray dim = 2 size = [] for i in range(int(dim)): size.append(np.random.randint(100) + 1) targ = np.random.random(size) * pq.millisecond res = get_fake_value(name, datatype, dim=dim, seed=0) self.assertTrue(isinstance(res, np.ndarray)) assert_arrays_equal(targ, res)
def test_attr_changes(self): """ gets an object, changes its attributes, saves it, then compares how good the changes were saved. """ iom = NeoHdf5IO(filename=self.test_file) for obj_type in objectnames: obj = fake_neo(obj_type=obj_type, cascade=False) iom.save(obj) orig_obj = iom.get(obj.hdf5_path) for attr in obj._all_attrs: if hasattr(orig_obj, attr[0]): setattr(obj, attr[0], get_fake_value(*attr)) iom.save(orig_obj) test_obj = iom.get(orig_obj.hdf5_path) assert_objects_equivalent(orig_obj, test_obj)
def test_attr_changes(self): """ gets an object, changes its attributes, saves it, then compares how good the changes were saved. """ iom = NeoHdf5IO(filename=self.test_file) for obj_type in class_by_name.keys(): obj = fake_neo(obj_type=obj_type, cascade=False) iom.save(obj) orig_obj = iom.get(obj.hdf5_path) attrs = (classes_necessary_attributes[obj_type] + classes_recommended_attributes[obj_type]) for attr in attrs: if hasattr(orig_obj, attr[0]): setattr(obj, attr[0], get_fake_value(*attr)) iom.save(orig_obj) test_obj = iom.get(orig_obj.hdf5_path) assert_objects_equivalent(orig_obj, test_obj)
def test__datetime(self): name = 'test__datetime' datatype = datetime res = get_fake_value(name, datatype) self.assertTrue(isinstance(res, datetime))