예제 #1
0
파일: run.py 프로젝트: dztdeng/vim_configs
def run_related_name_test(script, correct, line_nr):
    """
    Runs tests for gotos.
    Tests look like this:
    >>> abc = 1
    >>> #< abc@1,0 abc@3,0
    >>> abc

    Return if the test was a fail or not, with 1 for fail and 0 for success.
    """
    result = script.related_names()
    correct = correct.strip()
    compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1])
                                                            for r in result)
    wanted = []
    if not correct:
        positions = []
    else:
        positions = literal_eval(correct)
    for pos_tup in positions:
        if type(pos_tup[0]) == str:
            # this means that there is a module specified
            wanted.append(pos_tup)
        else:
            wanted.append(('renaming', line_nr + pos_tup[0], pos_tup[1]))

    wanted = sorted(wanted)
    if compare != wanted:
        print('Solution @%s not right, received %s, wanted %s'\
                    % (line_nr - 1, compare, wanted))
        return 1
    return 0
예제 #2
0
파일: run.py 프로젝트: dbrgn/jedi
def run_related_name_test(script, correct, line_nr):
    """
    Runs tests for gotos.
    Tests look like this:
    >>> abc = 1
    >>> #< abc@1,0 abc@3,0
    >>> abc

    Return if the test was a fail or not, with 1 for fail and 0 for success.
    """
    result = script.related_names()
    correct = correct.strip()
    compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1])
                                                            for r in result)
    wanted = []
    if not correct:
        positions = []
    else:
        positions = literal_eval(correct)
    for pos_tup in positions:
        if type(pos_tup[0]) == str:
            # this means that there is a module specified
            wanted.append(pos_tup)
        else:
            wanted.append(('renaming', line_nr + pos_tup[0], pos_tup[1]))

    wanted = sorted(wanted)
    if compare != wanted:
        print('Solution @%s not right, received %s, wanted %s'\
                    % (line_nr - 1, compare, wanted))
        return 1
    return 0
예제 #3
0
파일: run.py 프로젝트: dbrgn/jedi
def run_completion_test(script, correct, line_nr):
    """
    Runs tests for completions.
    Return if the test was a fail or not, with 1 for fail and 0 for success.
    """
    completions = script.complete()
    #import cProfile; cProfile.run('script.complete()')

    comp_str = set([c.word for c in completions])
    if comp_str != set(literal_eval(correct)):
        print('Solution @%s not right, received %s, wanted %s'\
                    % (line_nr - 1, comp_str, correct))
        return 1
    return 0
예제 #4
0
def run_completion_test(script, correct, line_nr):
    """
    Runs tests for completions.
    Return if the test was a fail or not, with 1 for fail and 0 for success.
    """
    completions = script.complete()
    #import cProfile; cProfile.run('script.complete()')

    comp_str = set([c.word for c in completions])
    if comp_str != set(literal_eval(correct)):
        print('Solution @%s not right, received %s, wanted %s'\
                    % (line_nr - 1, comp_str, correct))
        return 1
    return 0
예제 #5
0
파일: modules.py 프로젝트: andviro/jedi
    def detect_encoding():
        """ For the implementation of encoding definitions in Python, look at:
        http://www.python.org/dev/peps/pep-0263/
        http://docs.python.org/2/reference/lexical_analysis.html#encoding-\
                                                                declarations
        """
        byte_mark = '\xef\xbb\xbf' if is_py25 else literal_eval(r"b'\xef\xbb\xbf'")
        if source.startswith(byte_mark):
            # UTF-8 byte-order mark
            return 'utf-8'

        first_two_lines = re.match(r'(?:[^\n]*\n){0,2}', str(source)).group(0)
        possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)", first_two_lines)
        if possible_encoding:
            return possible_encoding.group(1)
        else:
            # the default if nothing else has been set -> PEP 263
            return encoding if encoding is not None else 'iso-8859-1'
예제 #6
0
파일: run.py 프로젝트: omab/dotfiles
def run_related_name_test(script, correct, line_nr):
    """
    Runs tests for gotos.
    Tests look like this:
    >>> abc = 1
    >>> #< abc@1,0 abc@3,0
    >>> abc

    Return if the test was a fail or not, with 1 for fail and 0 for success.
    """
    result = script.related_names()
    correct = correct.strip()
    comp_str = sorted(r.start_pos for r in result)
    correct = sorted(literal_eval(correct))
    if sorted(comp_str) != sorted(correct):
        print('Solution @%s not right, received %s, wanted %s'\
                    % (line_nr - 1, comp_str, correct))
        return 1
    return 0
예제 #7
0
def run_related_name_test(script, correct, line_nr):
    """
    Runs tests for gotos.
    Tests look like this:
    >>> abc = 1
    >>> #< abc@1,0 abc@3,0
    >>> abc

    Return if the test was a fail or not, with 1 for fail and 0 for success.
    """
    result = script.related_names()
    correct = correct.strip()
    comp_str = sorted(r.start_pos for r in result)
    correct = sorted(literal_eval(correct))
    if sorted(comp_str) != sorted(correct):
        print('Solution @%s not right, received %s, wanted %s'\
                    % (line_nr - 1, comp_str, correct))
        return 1
    return 0