Exemplo n.º 1
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])
Exemplo n.º 2
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])
Exemplo n.º 3
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")
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)