Exemple #1
0
    def setUp(self):
        "setup small data"

        def lfn(x: ConstantString):
            return x.constr.islower()

        pmakerc = PrimitiveMaker("constraint string")
        pmakercons = PrimitiveMaker("constant string")
        nnmaker = PrimitiveMaker("non numeric string")
        cmaker = ContainerMaker
        self.constrio = ConstraintStringIo
        self.consio = ConstantStringIo

        self.mycstr = pmakerc.from_string(mystr="my valid constraint string",
                                          fnc=lfn)
        self.myfn = dill.dumps(self.mycstr.fn)
        self.mynnstr = nnmaker.from_string(mystr="my valid non numeric string")
        self.mynnfn = dill.dumps(self.mynnstr.fn)
        self.parg1 = pmakercons.make(mystr="mystr1")
        self.parg2 = pmakercons.make(mystr="mystr2")
        self.pair = cmaker.from_type(objType=Pair,
                                     arg1=self.parg1,
                                     arg2=self.parg2)
        mystr1 = pmakerc.from_string(mystr="my true string", fnc=lfn)
        mystr2 = pmakerc.from_string(mystr="my another true string", fnc=lfn)
        self.scpair1 = cmaker.from_type(objType=SingleConstraintPair,
                                        arg1=mystr1,
                                        arg2=mystr2)
class TestContainer(unittest.TestCase):
    "test container.py"

    def setUp(self):
        self.currentdir = os.path.abspath(os.curdir)
        self.testdir = os.path.join(self.currentdir, "tests")
        self.assetdir = os.path.join(self.testdir, "assets")
        self.consMaker = PrimitiveMaker("constant string")
        self.constrMaker = PrimitiveMaker("constraint string")
        self.nnmaker = PrimitiveMaker("non numeric string")

    def test_pair(self):
        pmaker = ContainerMaker("pair")
        mystr1 = self.consMaker.make(mystr="mystr1")
        mystr2 = self.nnmaker.from_string(mystr="mystr2")
        mystr3 = self.consMaker.make(mystr="mystr3")
        check = True
        try:
            pair = pmaker.make(arg1=mystr1, arg2=mystr2)
        except ValueError or TypeError:
            check = False
        self.assertTrue(check, "either value or type error triggered")
        check = False
        try:
            pair = pmaker.make(arg1=mystr1, arg2=mystr3)
        except ValueError or TypeError:
            check = True
        self.assertTrue(check, "either value or type error should have been triggered")

    def test_array(self):
        pmaker = ContainerMaker("array")
        mystr1 = self.consMaker.make(mystr="mystr1")
        mystr2 = self.nnmaker.from_string(mystr="mystr2")
        mystr3 = self.consMaker.make(mystr="mystr3")
        check = True
        try:
            arr = pmaker.make(elements=[mystr1, mystr3])
        except ValueError or TypeError:
            check = False
        self.assertTrue(check, "either value or type error triggered")
        check = False
        try:
            arr = pmaker.make(elements=[mystr1, mystr2])
        except ValueError or TypeError:
            check = True
        self.assertTrue(check, "either value or type error should have been triggered")
    def test_primitive_maker_from_str(self):
        pmaker = PrimitiveMaker("constant string")
        cmaker = PrimitiveMaker("constraint string")
        check = True
        try:
            constr = pmaker.from_string(mystr="a str")
        except ValueError or TypeError:
            check = False
        self.assertTrue(check)

        def lfn(x):
            return x.constr.islower()

        check = True
        try:
            constr = cmaker.from_string(mystr="another str", fnc=lfn)
        except ValueError or TypeError:
            check = False
        self.assertTrue(check)