Пример #1
0
    def test_unify_basic(self):
        for dst,param,src,exp_up,exp_down in self.cases:

            with self.subTest(dst=dst,param=param,src=src):
               try:
                   checklist = {key:val for key,val in dst.items() if val[0] in '?!'}
                   _dst = {key:val for key,val in dst.items() if val[0] not in '?!'}
                   if param is not None:
                       param_type = [key for key,val in param.items() if key in '+-' ]
                       param = Param([(key,val) for key,val in param.items() if key not in '+-'])
                       param.param_type = param_type[0] if param_type else None
                   result = Parser.unify_up(_dst,param,src)
               except UnifyError:
                   result = None
               self.assertEqual(result, exp_up)

            with self.subTest(dst=dst,param=param,src=src):
               try:
                   checklist = {key:val for key,val in dst.items() if val[0] in '?!'}
                   _dst = {key:val for key,val in dst.items() if val[0] not in '?!'}
                   if param is not None:
                       param_type = [key for key,val in param.items() if key in '+-' ]
                       param = Param([(key,val) for key,val in param.items() if key not in '+-'])
                       param.param_type = param_type[0] if param_type else None
                   result = Parser.unify_down(_dst,param,src,checklist)
               except UnifyError:
                   result = None
               self.assertEqual(result, exp_down)
Пример #2
0
    def test_unify_basic(self):
        for dst,param,src,exp_up,exp_down in self.cases:

            with self.subTest(dst=dst,param=param,src=src):
               try:
                   checklist = [key for key,val in dst.items() if val=='?']
                   _dst = {key:val for key,val in dst.items() if val!='?'}
                   result = Parser.unify_up(_dst,param,src,checklist)
               except UnifyError:
                   result = None
               self.assertEqual(result, exp_up)

            with self.subTest(dst=dst,param=param,src=src):
               try:
                   checklist = [key for key,val in dst.items() if val=='?']
                   _dst = {key:val for key,val in dst.items() if val!='?'}
                   result = Parser.unify_down(_dst,param,src,checklist)
               except UnifyError:
                   result = None
               self.assertEqual(result, exp_down)