Ejemplo n.º 1
0
def prep_context():
    cntxt = {'success_msg': success_msg}
    from pythonwhat.check_syntax import v2_check_functions
    from pythonwhat.probe import build_probe_context
    imports = [
        "from inspect import Parameter as param",
        "from pythonwhat.signatures import sig_from_params, sig_from_obj",
        "from pythonwhat.State import set_converter",
        "from pythonwhat.check_syntax import F, Ex"
    ]
    [exec(line, None, cntxt) for line in imports]

    # only if PYTHONWHAT_V2_ONLY is not set, support v1
    if include_v1():
        tree, probe_cntxt = build_probe_context()
        cntxt.update(probe_cntxt)
    else:
        tree = None

    cntxt.update(v2_check_functions)
    return tree, cntxt
Ejemplo n.º 2
0
def prep_context():
    cntxt = {"success_msg": success_msg}
    from pythonwhat.sct_syntax import v2_check_functions
    from pythonwhat.probe import build_probe_context

    imports = [
        "from inspect import Parameter as param",
        "from pythonwhat.signatures import sig_from_params, sig_from_obj",
        "from pythonwhat.State import set_converter",
        "from pythonwhat.sct_syntax import F, Ex"
    ]
    [exec(line, None, cntxt) for line in imports]

    # only if PYTHONWHAT_V2_ONLY is not set, support v1
    if include_v1():
        tree, probe_cntxt = build_probe_context()
        cntxt.update(probe_cntxt)
    else:
        tree = None

    cntxt.update(v2_check_functions)
    # TODO: ChainStart instances cause errors when dill tries to pass manual converter functions
    # cntxt.update(get_chains())
    return tree, cntxt
Ejemplo n.º 3
0
            return reduce(lambda s, f: f(state=s), self._stack, state)
        else:
            pf = partial(self._crnt_sct, *args, **kwargs)
            return self.__class__(self._stack + [pf])

    @classmethod
    def _from_func(cls, f):
        func_chain = cls(stack=[f])
        return func_chain


def Ex(state=None):
    return Chain(state or State.root_state)


if include_v1():
    # Prepare SCTs that may be chained attributes ----------------------
    # decorate functions that may try to run test_* function nodes as subtests
    # so they remove those nodes from the tree
    for k in ['multi', 'with_context']:
        ATTR_SCTS[k] = multi_dec(ATTR_SCTS[k])

    # allow test_* functions as chained attributes
    for k in TEST_NAMES:
        ATTR_SCTS[k] = Probe(tree=None,
                             f=getattr(test_funcs, k),
                             eval_on_call=True)

    # original logical test_* functions behave like multi
    # this is necessary to allow them to take check_* funcs as args
    # since probe behavior will try to call all SCTs passed (assuming they're also probes)