Example #1
0
            def run_test(args):
                if isinstance(args, Exception):
                    exc = type(args)
                    args = args.args
                else:
                    exc = None
                pip = pipeline.make()
                if abstract is None:
                    argspec = tuple(
                        from_value(arg, broaden=True) for arg in args)
                else:
                    argspec = tuple(to_abstract_test(a) for a in abstract)

                if exc is not None:
                    try:
                        mfn = pip(input=fn, argspec=argspec)
                        mfn['output'](*args)
                    except exc:
                        pass
                    return

                result_py = fn(*args)

                try:
                    res = pip(input=fn, argspec=argspec)
                except InferenceError as ierr:
                    print_inference_error(ierr)
                    raise ierr
                except ValidationError as verr:
                    print('Collected the following errors:')
                    for err in verr.errors:
                        n = err.node
                        nlbl = lbl.label(n)
                        tname = type(n).__name__
                        print(f'   {nlbl} ({tname}) :: {n.abstract}')
                        print(f'      {err.args[0]}')
                    raise verr

                result_final = res['output'](*args)
                assert _eq(result_py, result_final)
Example #2
0
            def run_test(args):
                pip = pipeline.make()
                argspec = tuple(from_value(arg, broaden=True) for arg in args)

                result_py = fn(*args)

                try:
                    res = pip(input=fn, argspec=argspec)
                except InferenceError as ierr:
                    print_inference_error(ierr)
                    raise ierr
                except ValidationError as verr:
                    print('Collected the following errors:')
                    for err in verr.errors:
                        n = err.node
                        nlbl = lbl.label(n)
                        print(f'   {nlbl} ({type(n).__name__}) :: {n.type}')
                        print(f'      {err.args[0]}')
                    raise verr

                result_final = res['output'](*args)
                assert _eq(result_py, result_final)
Example #3
0
            def run_test(spec):
                *args, expected_out = spec

                print('Args:')
                print(args)

                def out():
                    pip = pipeline.make()
                    res = pip(input=fn, argspec=args)
                    rval = res['outspec']

                    print('Output of inferrer:')
                    rval = pip.resources.inferrer.engine.run_coroutine(
                        concretize_abstract(rval))
                    print(rval)
                    return rval

                print('Expected:')
                print(expected_out)

                if _is_exc_type(expected_out):
                    try:
                        out()
                    except expected_out as e:
                        if issubclass(expected_out, InferenceError):
                            print_inference_error(e)
                        else:
                            pass
                    else:
                        raise Exception(
                            f'Expected {expected_out}, got: (see stdout).')
                else:
                    try:
                        assert out() == expected_out
                    except InferenceError as e:
                        print_inference_error(e)
                        raise