Beispiel #1
0
 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')
Beispiel #2
0
 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')
Beispiel #3
0
 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')
Beispiel #4
0
 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')
Beispiel #5
0
 def testBaseStringUTFTypeItem(self):
     dt = np.dtype('U3')
     try:
         typeItem = h5type.getTypeItem(dt)
         self.assertTrue(False)  # expected exception
     except TypeError:
         pass # expected
Beispiel #6
0
    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')
Beispiel #7
0
 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')
Beispiel #8
0
 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')
Beispiel #9
0
 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')
Beispiel #10
0
 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)
Beispiel #11
0
 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')
Beispiel #12
0
 def testOpaqueTypeItem(self):
     dt = np.dtype('V200')
     typeItem = h5type.getTypeItem(dt)
     self.assertEqual(typeItem['class'], 'H5T_OPAQUE')
     self.assertTrue('base' not in typeItem)