def test_store(self): print("Run: %s.test_store() " % self.__class__.__name__) el = FElement(self._tfname, self._fattrs, None, self._group) self.assertEqual(el.tagName, self._tfname) self.assertEqual(el.content, []) self.assertEqual(el.doc, "") self.assertEqual(el.store(), None) self.assertEqual(el.store("<tag/>"), None)
def test_findShape_ds_2d_ext(self): print("Run: %s.test_findShape_ds_2d() " % self.__class__.__name__) ds = TstDataSource() el = FElement(self._tfname, self._fattrs, None) el.source = ds el.source.numpy = True mlen = [self.__rnd.randint(1, 2), self.__rnd.randint(1, 2)] el.source.dims = mlen self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=False, extends=True) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=False, grows=i, extends=True) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, extends=True) for i in range(-2, 2): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, grows=i, extends=True) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, grows=2, extends=True) for i in range(3, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, grows=i, extends=True) el.source.numpy = False mlen = [self.__rnd.randint(2, 1000), self.__rnd.randint(2, 1000)] el.source.dims = mlen self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=False, extends=True) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=False, grows=i, extends=True) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, extends=True) for i in range(-2, 2): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, grows=i, extends=True) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, grows=2, extends=True) for i in range(3, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "2", extraD=True, grows=i, extends=True)
def test_constructor(self): print("Run: %s.test_constructor() " % self.__class__.__name__) el = FElement(self._tfname, self._fattrs, None) el2 = FElement(self._tfname, self._fattrs, el, self._group) self.assertTrue(isinstance(el2, Element)) self.assertTrue(isinstance(el2, FElement)) self.assertEqual(el2.tagName, self._tfname) self.assertEqual(el2.content, []) self.assertEqual(el2.doc, "") self.assertEqual(el.source, None) self.assertEqual(el.error, None) self.assertEqual(el.h5Object, None) self.assertEqual(el2.h5Object, self._group)
def test_run(self): print("Run: %s.test_run() " % self.__class__.__name__) el = FElement(self._tfname, self._fattrs, None, self._group) self.assertEqual(el.tagName, self._tfname) self.assertEqual(el.content, []) self.assertEqual(el.doc, "") self.assertEqual(el.run(), None) self.assertEqual(el.source, None) ds = TstDataSource() el.source = ds self.assertEqual(el.source, ds) self.assertTrue(hasattr(el.source, "getData")) self.assertTrue(not ds.dataTaken) self.assertEqual(el.run(), None) self.assertTrue(ds.dataTaken)
def test_createAttributes_1d_single(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) self._fname = '%s/%s%s.h5' % (os.getcwd(), self.__class__.__name__, fun) self.createTree() el = FElement(self._tfname, self._fattrs, None) el2 = FElementWithAttr(self._tfname, self._fattrs, el, self._group) self.assertEqual(el2.tagAttributes, {}) attrs = { # "string":["My string","NX_CHAR", "string" , (1,)], # "datetime":["12:34:34","NX_DATE_TIME", "string", (1,) ], # "iso8601":["12:34:34","ISO8601", "string", (1,)], "int": [-123, "NX_INT", "int64", (1, )], "int8": [12, "NX_INT8", "int8", (1, )], "int16": [-123, "NX_INT16", "int16", (1, )], "int32": [12345, "NX_INT32", "int32", (1, )], "int64": [-12345, "NX_INT64", "int64", (1, )], "uint": [123, "NX_UINT", "uint64", (1, )], "uint8": [12, "NX_UINT8", "uint8", (1, )], "uint16": [123, "NX_UINT16", "uint16", (1, )], "uint32": [12345, "NX_UINT32", "uint32", (1, )], "uint64": [12345, "NX_UINT64", "uint64", (1, )], "float": [-12.345, "NX_FLOAT", "float64", (1, ), 1.e-14], "number": [-12.345e+2, "NX_NUMBER", "float64", (1, ), 1.e-14], "float32": [-12.345e-1, "NX_FLOAT32", "float32", (1, ), 1.e-5], "float64": [-12.345, "NX_FLOAT64", "float64", (1, ), 1.e-14], "bool": [True, "NX_BOOLEAN", "bool", (1, )], "bool2": ["FaLse", "NX_BOOLEAN", "bool", (1, )], "bool3": ["false", "NX_BOOLEAN", "bool", (1, )], "bool4": ["true", "NX_BOOLEAN", "bool", (1, )] } for nm in attrs.keys(): if attrs[nm][2] == 'string': "writing multi-dimensional string is not supported by pninx" continue el2.tagAttributes[nm] = (attrs[nm][1], str(attrs[nm][0]), attrs[nm][3]) el2._createAttributes() at = el2.h5Attribute(nm) self.assertEqual(at.dtype, attrs[nm][2]) if attrs[nm][2] == "bool": self.assertEqual(Converters.toBool(str(attrs[nm][0])), at[...]) elif len(attrs[nm]) > 4: self.assertTrue(abs(at[...] - attrs[nm][0]) <= attrs[nm][4]) else: if isinstance(at[...], numpy.ndarray): self.assertEqual( at[...], numpy.array(attrs[nm][0], dtype=attrs[nm][2])) else: self.assertEqual(at[...], attrs[nm][0])
def test_constructor(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) self._fname = '%s/%s%s.h5' % (os.getcwd(), self.__class__.__name__, fun) self.createTree() el = FElement(self._tfname, self._fattrs, None) el2 = FElementWithAttr(self._tfname, self._fattrs, el, self._group) self.assertTrue(isinstance(el2, Element)) self.assertTrue(isinstance(el2, FElement)) self.assertTrue(isinstance(el2, FElementWithAttr)) self.assertEqual(el2.tagName, self._tfname) self.assertEqual(el2.content, []) self.assertEqual(el2.doc, "") self.assertEqual(el.source, None) self.assertEqual(el.error, None) self.assertEqual(el.h5Object, None) self.assertEqual(el2.h5Object, self._group) self.assertEqual(el2.tagAttributes, {})
def test_findShape_ds_2d_extends3_checkData(self): print("Run: %s.test_findShape_ds_2d() " % self.__class__.__name__) ds = TstDataSource() el = FElement(self._tfname, self._fattrs, None) el.source = ds el.source.numpy = True mlen = [1, 1] el.source.dims = mlen self.assertEqual( el._findShape("2", extraD=False, checkData=True), [1, 1]) for i in range(-2, 5): self.assertEqual( el._findShape("2", extraD=False, grows=i, checkData=True), [1, 1]) self.assertEqual( el._findShape("2", extraD=True, checkData=True), [0] + [1, 1]) for i in range(-2, 2): self.assertEqual( el._findShape("2", extraD=True, grows=i, checkData=True), [0] + [1, 1]) self.assertEqual( el._findShape("2", extraD=True, grows=2, checkData=True), [1, 0, 1]) for i in range(3, 5): self.assertEqual( el._findShape("2", extraD=True, grows=i, checkData=True), [1, 1] + [0]) el.source.numpy = False mlen = [1, 1] el.source.dims = mlen self.assertEqual( el._findShape("2", extraD=False, checkData=True), [1, 1]) for i in range(-2, 5): self.assertEqual( el._findShape("2", extraD=False, grows=i, checkData=True), [1, 1]) self.assertEqual( el._findShape("2", extraD=True, checkData=True), [0] + [1, 1]) for i in range(-2, 2): self.assertEqual( el._findShape("2", extraD=True, grows=i, checkData=True), [0] + [1, 1]) self.assertEqual( el._findShape("2", extraD=True, grows=2, checkData=True), [1, 0, 1]) for i in range(3, 5): self.assertEqual( el._findShape("2", extraD=True, grows=i, checkData=True), [1, 1] + [0])
def test_findShape_ds_2d_ext_checkData(self): print("Run: %s.test_findShape_ds_2d() " % self.__class__.__name__) ds = TstDataSource() el = FElement(self._tfname, self._fattrs, None) el.source = ds el.source.numpy = True mlen = [self.__rnd.randint(1, 2), self.__rnd.randint(1, 2)] el.source.dims = mlen self.assertEqual( el._findShape("2", extraD=False, extends=True, checkData=True), mlen) for i in range(-2, 5): self.assertEqual( el._findShape("2", extraD=False, grows=i, extends=True, checkData=True), mlen) self.assertEqual( el._findShape("2", extraD=True, extends=True, checkData=True), [0] + mlen) for i in range(-2, 2): self.assertEqual( el._findShape("2", extraD=True, grows=i, extends=True, checkData=True), [0] + mlen) self.assertEqual( el._findShape("2", extraD=True, grows=2, extends=True, checkData=True), [mlen[0], 0, mlen[1]]) for i in range(3, 5): self.assertEqual( el._findShape("2", extraD=True, grows=i, extends=True, checkData=True), mlen + [0]) el.source.numpy = False mlen = [self.__rnd.randint(2, 1000), self.__rnd.randint(2, 1000)] el.source.dims = mlen self.assertEqual( el._findShape("2", extraD=False, extends=True, checkData=True), mlen) for i in range(-2, 5): self.assertEqual( el._findShape("2", extraD=False, grows=i, extends=True, checkData=True), mlen) self.assertEqual( el._findShape("2", extraD=True, extends=True, checkData=True), [0] + mlen) for i in range(-2, 2): self.assertEqual( el._findShape("2", extraD=True, grows=i, extends=True, checkData=True), [0] + mlen) self.assertEqual( el._findShape("2", extraD=True, grows=2, extends=True, checkData=True), [mlen[0], 0, mlen[1]]) for i in range(3, 5): self.assertEqual( el._findShape("2", extraD=True, grows=i, extends=True, checkData=True), mlen + [0])
def test_findShape_ds_1d(self): print("Run: %s.test_findShape_ds_1d() " % self.__class__.__name__) ds = TstDataSource() el = FElement(self._tfname, self._fattrs, None) el.source = ds self.assertEqual(el._findShape("0"), []) self.assertEqual(el._findShape("0", None, extraD=True), [0]) for i in range(-2, 5): self.assertEqual( el._findShape("0", None, extraD=True, grows=i), [0]) for i in range(-2, 5): self.assertEqual( el._findShape("0", None, extraD=False, grows=i), []) mlen = self.__rnd.randint(1, 10000) el.source.dims = [mlen] self.assertEqual( el._findShape("1", extraD=False, checkData=True), [mlen]) for i in range(-2, 5): self.assertEqual( el._findShape("1", extraD=False, grows=i, checkData=True), [mlen]) self.assertEqual( el._findShape("1", extraD=True, checkData=True), [0, mlen]) for i in range(-2, 2): self.assertEqual( el._findShape("1", extraD=True, grows=i, checkData=True), [0, mlen]) for i in range(2, 5): self.assertEqual( el._findShape("1", extraD=True, grows=i, checkData=True), [mlen, 0]) mlen = self.__rnd.randint(1, 10000) el.source.dims = [mlen] self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=False) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=False, grows=i) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=True) for i in range(-2, 2): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=True, grows=i) for i in range(2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=True, grows=i) el.source.dims = [0] self.assertEqual(el._findShape("1", checkData=True), []) el.source.dims = [0] self.myAssertRaise(XMLSettingSyntaxError, el._findShape, "1") el.source.numpy = False mlen = self.__rnd.randint(1, 10000) el.source.dims = [mlen] self.assertEqual( el._findShape("1", extraD=False, checkData=True), [mlen]) for i in range(-2, 5): self.assertEqual( el._findShape("1", extraD=False, grows=i, checkData=True), [mlen]) self.assertEqual( el._findShape("1", extraD=True, checkData=True), [0, mlen]) for i in range(-2, 2): self.assertEqual( el._findShape("1", extraD=True, grows=i, checkData=True), [0, mlen]) for i in range(2, 5): self.assertEqual( el._findShape("1", extraD=True, grows=i, checkData=True), [mlen, 0]) el.source.dims = [0] self.assertEqual(el._findShape("1", checkData=True), []) mlen = self.__rnd.randint(1, 10000) el.source.dims = [mlen] self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=False) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=False, grows=i) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=True) for i in range(-2, 2): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=True, grows=i) for i in range(2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", extraD=True, grows=i) el.source.dims = [0] self.myAssertRaise(XMLSettingSyntaxError, el._findShape, "1")
def test_findShape_lengths_3d(self): print("Run: %s.test_findShape_lengths_3d() " % self.__class__.__name__) el = FElement(self._tfname, self._fattrs, None) self.myAssertRaise(XMLSettingSyntaxError, el._findShape, "3") mlen = [self.__rnd.randint(1, 100), self.__rnd.randint( 1, 100), self.__rnd.randint(1, 100)] lens = {'1': str(mlen[0]), '2': str(mlen[1]), '3': str(mlen[2])} self.assertEqual( el._findShape("3", lengths=lens, extraD=False), mlen) for i in range(-2, 5): self.assertEqual( el._findShape("3", lengths=lens, extraD=False, grows=i), mlen) self.assertEqual( el._findShape("3", lengths=lens, extraD=True), [0] + mlen) for i in range(-2, 2): self.assertEqual( el._findShape("3", lengths=lens, extraD=True, grows=i), [0] + mlen) self.assertEqual( el._findShape("3", lengths=lens, extraD=True, grows=2), [mlen[0], 0, mlen[1], mlen[2]]) self.assertEqual( el._findShape("3", lengths=lens, extraD=True, grows=3), [mlen[0], mlen[1], 0, mlen[2]]) for i in range(4, 5): self.assertEqual( el._findShape("3", lengths=lens, extraD=True, grows=i), mlen + [0]) lens = {'1': '0', '2': str(mlen[0]), '3': str(mlen[1])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=False) lens = {'2': '0', '1': str(mlen[0]), '3': str(mlen[1])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=False) lens = {'1': '0', '2': '0', '3': str(mlen[0])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=False) lens = {'2': '0', '3': '0', '1': str(mlen[0])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=False) lens = {'3': '0', '1': '0', '2': str(mlen[0])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=False) lens = {'1': '0', '2': str(mlen[0]), '3': str(mlen[1])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True) lens = {'2': '0', '1': str(mlen[0]), '3': str(mlen[1])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True) lens = {'1': '0', '2': '0', '3': str(mlen[0])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True) lens = {'2': '0', '3': '0', '1': str(mlen[0])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True) lens = {'3': '0', '1': '0', '2': str(mlen[0])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True) nlen = [self.__rnd.randint(-100, 0), self.__rnd.randint(-100, 0)] lens = {'1': str(mlen[0]), '2': str(nlen[1]), '3': str(mlen[1])} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=False) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True, grows=i) mlen = self.__rnd.randint(1, 1000) lens = {'2': str(mlen), '3': str(mlen), '4': str(mlen)} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens) mlen = self.__rnd.randint(1, 1000) lens = {'2': str(mlen)} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "3", lengths=lens, extraD=True)
def test_findShape_lengths_1d(self): print("Run: %s.test_findShape_lengths_1d() " % self.__class__.__name__) el = FElement(self._tfname, self._fattrs, None) self.myAssertRaise(ValueError, el._findShape, "") self.assertEqual(el._findShape("0"), []) self.assertEqual(el._findShape("0", None, extraD=True), [0]) for i in range(-2, 5): self.assertEqual( el._findShape("0", None, extraD=True, grows=i), [0]) for i in range(-2, 5): self.assertEqual( el._findShape("0", None, extraD=False, grows=i), []) self.myAssertRaise(XMLSettingSyntaxError, el._findShape, "1") mlen = self.__rnd.randint(1, 10000) lens = {'1': str(mlen)} self.assertEqual( el._findShape("1", lengths=lens, extraD=False), [mlen]) for i in range(-2, 5): self.assertEqual( el._findShape("1", lengths=lens, extraD=False, grows=i), [mlen]) self.assertEqual( el._findShape("1", lengths=lens, extraD=True), [0, mlen]) for i in range(-2, 2): self.assertEqual( el._findShape("1", lengths=lens, extraD=True, grows=i), [0, mlen]) for i in range(2, 5): self.assertEqual( el._findShape("1", lengths=lens, extraD=True, grows=i), [mlen, 0]) lens = {'1': str(0)} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens, extraD=False) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens, extraD=True) mlen = self.__rnd.randint(-10000, 0) lens = {'1': str(mlen)} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens, extraD=False) self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens, extraD=True) for i in range(-2, 5): self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens, extraD=True, grows=i) mlen = self.__rnd.randint(1, 1000) lens = {'2': str(mlen)} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens) mlen = self.__rnd.randint(1, 1000) lens = {'2': str(mlen)} self.myAssertRaise( XMLSettingSyntaxError, el._findShape, "1", lengths=lens, extraD=True)
def test_setMessage(self): print("Run: %s.test_setMessage() " % self.__class__.__name__) message = "My Exception" text = "Data for %s not found. DATASOURCE:%s" uob = "unnamed object" uds = "unknown datasource" ds = TstDataSource() el = FElement(self._tfname, self._fattrs, None) self.assertEqual( el.setMessage(), (text % (uob, uds), None)) self.assertEqual( el.setMessage(message), (text % (uob, uds), message)) el.source = ds self.assertEqual( el.setMessage(), (text % (uob, str(ds)), None)) self.assertEqual( el.setMessage(message), (text % (uob, str(ds)), message)) el2 = FElement(self._tfname, self._fattrs, el, self._group) self.assertEqual( el2.setMessage(), (text % ("/" + self._group.name + ":NXentry", uds), None)) self.assertEqual( el2.setMessage(message), (text % ("/" + self._group.name + ":NXentry", uds), message)) el2.source = ds self.assertEqual( el2.setMessage(), (text % ("/" + self._group.name + ":NXentry", str(ds)), None)) self.assertEqual( el2.setMessage(message), (text % ("/" + self._group.name + ":NXentry", str(ds)), message))
def test_findShape_xml(self): print("Run: %s.test_findShape_xml() " % self.__class__.__name__) el = FElement(self._tfname, self._fattrs, None) el.content = ["123"] self.assertEqual(el._findShape("0"), []) self.assertEqual(el._findShape("0", None, extraD=True), [0]) for i in range(-2, 5): self.assertEqual( el._findShape("0", None, extraD=True, grows=i), [0]) for i in range(-2, 5): self.assertEqual( el._findShape("0", None, extraD=False, grows=i), []) mlen = self.__rnd.randint(1, 10000) el.content = ["123 " * mlen] self.assertEqual(el._findShape("1", extraD=False), [mlen]) for i in range(-2, 5): self.assertEqual( el._findShape("1", extraD=False, grows=i), [mlen]) self.assertEqual(el._findShape("1", extraD=True), [mlen]) for i in range(-2, 5): self.assertEqual( el._findShape("1", extraD=True, grows=i), [mlen]) mlen = [self.__rnd.randint(1, 1000), self.__rnd.randint(1, 1000)] el.content = ["123 " * mlen[1] + "\n "] * mlen[0] self.assertEqual(el._findShape("2", extraD=False), mlen) for i in range(-2, 5): self.assertEqual( el._findShape("2", extraD=False, grows=i), mlen) self.assertEqual(el._findShape("2", extraD=True), mlen) for i in range(-2, 5): self.assertEqual(el._findShape("2", extraD=True, grows=i), mlen)
def test_createAttributes_2d_X1(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) self._fname = '%s/%s%s.h5' % (os.getcwd(), self.__class__.__name__, fun) self.createTree() el = FElement(self._tfname, self._fattrs, None) el2 = FElementWithAttr(self._tfname, self._fattrs, el, self._group) self.assertEqual(el2.tagAttributes, {}) attrs = { # "string":["My string","NX_CHAR", "string" , (1,)], # "datetime":["12:34:34","NX_DATE_TIME", "string", (1,) ], # "iso8601":["12:34:34","ISO8601", "string", (1,)], "int": [-123, "NX_INT", "int64", (1, )], "int8": [12, "NX_INT8", "int8", (1, )], "int16": [-123, "NX_INT16", "int16", (1, )], "int32": [12345, "NX_INT32", "int32", (1, )], "int64": [-12345, "NX_INT64", "int64", (1, )], "uint": [123, "NX_UINT", "uint64", (1, )], "uint8": [12, "NX_UINT8", "uint8", (1, )], "uint16": [123, "NX_UINT16", "uint16", (1, )], "uint32": [12345, "NX_UINT32", "uint32", (1, )], "uint64": [12345, "NX_UINT64", "uint64", (1, )], "float": [-12.345, "NX_FLOAT", "float64", (1, ), 1.e-14], "number": [-12.345e+2, "NX_NUMBER", "float64", (1, ), 1.e-14], "float32": [-12.345e-1, "NX_FLOAT32", "float32", (1, ), 1.e-5], "float64": [-12.345, "NX_FLOAT64", "float64", (1, ), 1.e-14], "bool": [True, "NX_BOOLEAN", "bool", (1, )], "bool2": ["FaLse", "NX_BOOLEAN", "bool", (1, )], "bool3": ["false", "NX_BOOLEAN", "bool", (1, )], "bool4": ["true", "NX_BOOLEAN", "bool", (1, )] } for nm in attrs.keys(): if attrs[nm][2] != "bool": mlen = [self.__rnd.randint(2, 10), 1] attrs[nm][0] = [[ attrs[nm][0] * self.__rnd.randint(0, 3) for r in range(mlen[1]) ] for c in range(mlen[0])] else: mlen = [self.__rnd.randint(2, 10), 1] if nm == 'bool': attrs[nm][0] = [[ bool(self.__rnd.randint(0, 1)) for c in range(mlen[1]) ] for r in range(mlen[0])] else: attrs[nm][0] = [[ ("True" if self.__rnd.randint(0, 1) else "False") for c in range(mlen[1]) ] for r in range(mlen[0])] attrs[nm][3] = (mlen[0], mlen[1]) for nm in attrs.keys(): el2.tagAttributes[nm] = (attrs[nm][1], "".join([ "".join([str(it) + " " for it in sub]) + "\n" for sub in attrs[nm][0] ]), attrs[nm][3]) el2._createAttributes() at = el2.h5Attribute(nm) self.assertEqual(at.dtype, attrs[nm][2]) if attrs[nm][2] == "bool": for i in range(len(attrs[nm][0])): for j in range(len(attrs[nm][0][i])): self.assertEqual( Converters.toBool(str(attrs[nm][0][i][j])), at[i, j]) pass elif len(attrs[nm]) > 4: for i in range(len(attrs[nm][0])): for j in range(len(attrs[nm][0][i])): self.assertTrue( abs(at[i, j] - attrs[nm][0][i][j]) <= attrs[nm][4]) else: for i in range(len(attrs[nm][0])): for j in range(len(attrs[nm][0][i])): self.assertEqual(at[i, j], attrs[nm][0][i][j])