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_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_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_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_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_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")