def testBaseVLenAsciiTypeItem(self): dt = special_dtype(vlen=six.binary_type) typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_STRING') self.assertEqual(typeItem['length'], 'H5T_VARIABLE') self.assertEqual(typeItem['strPad'], 'H5T_STR_NULLTERM') self.assertEqual(typeItem['charSet'], 'H5T_CSET_ASCII')
def testBaseArrayTypeItem(self): dt = np.dtype('(2,2)<int32') typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_ARRAY') baseItem = typeItem['base'] self.assertEqual(baseItem['class'], 'H5T_INTEGER') self.assertEqual(baseItem['base'], 'H5T_STD_I32LE')
def testBaseVLenUnicodeTypeItem(self): dt = special_dtype(vlen=six.text_type) typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_STRING') self.assertEqual(typeItem['length'], 'H5T_VARIABLE') self.assertEqual(typeItem['strPad'], 'H5T_STR_NULLTERM') self.assertEqual(typeItem['charSet'], 'H5T_CSET_UTF8')
def testBaseStringTypeItem(self): dt = np.dtype('S3') typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_STRING') self.assertEqual(typeItem['length'], 3) self.assertEqual(typeItem['strPad'], 'H5T_STR_NULLPAD') self.assertEqual(typeItem['charSet'], 'H5T_CSET_ASCII')
def testBaseStringUTFTypeItem(self): dt = np.dtype('U3') try: typeItem = h5type.getTypeItem(dt) self.assertTrue(False) # expected exception except TypeError: pass # expected
def testCompoundTypeItem(self): dt = np.dtype([("temp", np.float32), ("pressure", np.float32), ("wind", np.int16)]) typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_COMPOUND') self.assertTrue('fields' in typeItem) fields = typeItem['fields'] self.assertEqual(len(fields), 3) tempField = fields[0] self.assertEqual(tempField['name'], 'temp') self.assertTrue('type' in tempField) tempFieldType = tempField['type'] self.assertEqual(tempFieldType['class'], 'H5T_FLOAT') self.assertEqual(tempFieldType['base'], 'H5T_IEEE_F32LE') typeItem = h5type.getTypeResponse(typeItem) # non-verbose format self.assertEqual(typeItem['class'], 'H5T_COMPOUND') self.assertTrue('fields' in typeItem) fields = typeItem['fields'] self.assertEqual(len(fields), 3) tempField = fields[0] self.assertEqual(tempField['name'], 'temp') self.assertTrue('type' in tempField) tempFieldType = tempField['type'] self.assertEqual(tempFieldType['class'], 'H5T_FLOAT') self.assertEqual(tempFieldType['base'], 'H5T_IEEE_F32LE')
def testVlenDataItem(self): dt = special_dtype(vlen=np.dtype('int32')) typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_VLEN') self.assertEqual(typeItem['size'], 'H5T_VARIABLE') baseItem = typeItem['base'] self.assertEqual(baseItem['base'], 'H5T_STD_I32LE')
def testBaseFloatTypeItem(self): dt = np.dtype('<f8') typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_FLOAT') self.assertEqual(typeItem['base'], 'H5T_IEEE_F64LE') typeItem = h5type.getTypeResponse(typeItem) # non-verbose format self.assertEqual(typeItem['class'], 'H5T_FLOAT') self.assertEqual(typeItem['base'], 'H5T_IEEE_F64LE')
def testBaseIntegerTypeItem(self): dt = np.dtype('<i1') typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_INTEGER') self.assertEqual(typeItem['base'], 'H5T_STD_I8LE') typeItem = h5type.getTypeResponse(typeItem) # non-verbose format self.assertEqual(typeItem['class'], 'H5T_INTEGER') self.assertEqual(typeItem['base'], 'H5T_STD_I8LE')
def testBaseEnumTypeItem(self): mapping = {'RED': 0, 'GREEN': 1, 'BLUE': 2} dt = special_dtype(enum=(np.int8, mapping)) typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_ENUM') baseItem = typeItem['base'] self.assertEqual(baseItem['class'], 'H5T_INTEGER') self.assertEqual(baseItem['base'], 'H5T_STD_I8LE') self.assertTrue('mapping' in typeItem) self.assertEqual(typeItem['mapping']['GREEN'], 1)
def testCompoundArrayTypeItem(self): dt = np.dtype([('a', '<i1'), ('b', 'S1', (10,))]) typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_COMPOUND') fields = typeItem['fields'] field_a = fields[0] self.assertEqual(field_a['name'], 'a') field_a_type = field_a['type'] self.assertEqual(field_a_type['class'], 'H5T_INTEGER') self.assertEqual(field_a_type['base'], 'H5T_STD_I8LE') field_b = fields[1] self.assertEqual(field_b['name'], 'b') field_b_type = field_b['type'] self.assertEqual(field_b_type['class'], 'H5T_ARRAY') self.assertEqual(field_b_type['dims'], (10,)) field_b_basetype = field_b_type['base'] self.assertEqual(field_b_basetype['class'], 'H5T_STRING')
def testOpaqueTypeItem(self): dt = np.dtype('V200') typeItem = h5type.getTypeItem(dt) self.assertEqual(typeItem['class'], 'H5T_OPAQUE') self.assertTrue('base' not in typeItem)