Esempio n. 1
0
def assert_params(param_string, **wanted_dct):
    source = dedent('''
    def x(%s):
        pass
    ''') % param_string

    parser = Parser(load_grammar(), dedent(source))
    funcdef = parser.get_parsed_node().subscopes[0]
    dct = dict((p.name.value, p.default and p.default.get_code())
               for p in funcdef.params)
    assert dct == wanted_dct
    assert parser.get_parsed_node().get_code() == source
Esempio n. 2
0
File: run.py Progetto: bstaint/jedi
        def definition(correct, correct_start, path):
            should_be = set()
            for match in re.finditer('(?:[^ ]+)', correct):
                string = match.group(0)
                parser = Parser(load_grammar(), string, start_symbol='eval_input')
                parser.position_modifier.line = self.line_nr
                element = parser.get_parsed_node()
                element.parent = jedi.api.completion.get_user_scope(
                    script._get_module(),
                    (self.line_nr, self.column)
                )
                results = evaluator.eval_element(element)
                if not results:
                    raise Exception('Could not resolve %s on line %s'
                                    % (match.string, self.line_nr - 1))

                should_be |= set(Definition(evaluator, r) for r in results)

            # Because the objects have different ids, `repr`, then compare.
            should = set(comparison(r) for r in should_be)
            return should
Esempio n. 3
0
        def definition(correct, correct_start, path):
            should_be = set()
            for match in re.finditer('(?:[^ ]+)', correct):
                string = match.group(0)
                parser = Parser(load_grammar(),
                                string,
                                start_symbol='eval_input')
                parser.position_modifier.line = self.line_nr
                element = parser.get_parsed_node()
                element.parent = jedi.api.completion.get_user_scope(
                    script._get_module(), (self.line_nr, self.column))
                results = evaluator.eval_element(element)
                if not results:
                    raise Exception('Could not resolve %s on line %s' %
                                    (match.string, self.line_nr - 1))

                should_be |= set(Definition(evaluator, r) for r in results)

            # Because the objects have different ids, `repr`, then compare.
            should = set(comparison(r) for r in should_be)
            return should
Esempio n. 4
0
def _fix_forward_reference(context, node):
    evaled_nodes = context.eval_node(node)
    if len(evaled_nodes) != 1:
        debug.warning("Eval'ed typing index %s should lead to 1 object, "
                      " not %s" % (node, evaled_nodes))
        return node
    evaled_node = list(evaled_nodes)[0]
    if isinstance(evaled_node, compiled.CompiledObject) and \
            isinstance(evaled_node.obj, str):
        try:
            p = Parser(load_grammar(), _compatibility.unicode(evaled_node.obj),
                       start_symbol='eval_input')
            new_node = p.get_parsed_node()
        except ParseError:
            debug.warning('Annotation not parsed: %s' % evaled_node.obj)
            return node
        else:
            module = node.get_parent_until()
            new_node.move(module.end_pos[0])
            new_node.parent = context.tree_node
            return new_node
    else:
        return node
Esempio n. 5
0
        def definition(correct, correct_start, path):
            should_be = set()
            for match in re.finditer('(?:[^ ]+)', correct):
                string = match.group(0)
                parser = Parser(load_grammar(), string, start_symbol='eval_input')
                parser.get_root_node().move(self.line_nr)
                element = parser.get_parsed_node()
                module_context = script._get_module()
                # The context shouldn't matter for the test results.
                user_context = get_user_scope(module_context, (self.line_nr, 0))
                if user_context.api_type == 'function':
                    user_context = user_context.get_function_execution()
                element.parent = user_context.tree_node
                results = evaluator.eval_element(user_context, element)
                if not results:
                    raise Exception('Could not resolve %s on line %s'
                                    % (match.string, self.line_nr - 1))

                should_be |= set(Definition(evaluator, r.name) for r in results)
            debug.dbg('Finished getting types', color='YELLOW')

            # Because the objects have different ids, `repr`, then compare.
            should = set(comparison(r) for r in should_be)
            return should