コード例 #1
0
ファイル: testicodegen.py プロジェクト: ztane/mypy
def test_transform(testcase):
    """Perform a runtime checking transformation test case."""
    expected = remove_comment_lines(testcase.output)

    func_names = get_func_names(expected)

    try:
        # Construct input as a single single.
        src = '\n'.join(testcase.input)
        # Parse and type check the input program.
        result = build.build(src, program_path='main',
                             target=build.ICODE,
                             alt_lib_path=test_temp_dir)
        a = []
        for fn in func_names:
            a.append('def {}:'.format(fn))
            try:
                funccode = result.icode[fn]
            except KeyError:
                raise RuntimeError('no icode for %s (%s)' % (
                    fn, list(result.icode.keys())))
            code = icode.render(funccode)
            a.extend(code)
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal_wildcards(
        expected, a,
        'Invalid source code output ({}, line {})'.format(testcase.file,
                                                          testcase.line))
コード例 #2
0
ファイル: testopgen.py プロジェクト: Varriount/mypy
def test_op_gen(testcase):
    """Perform a type operation support data and code genereation test case."""
    any a
    expected = remove_comment_lines(testcase.output)
    try:
        src = '\n'.join(testcase.input)
        # Parse and type check the input program.
        trees, symtable, infos, types = build(src, 'main', False,
                                              test_temp_dir, True)
        a = []
        first = True
        # Transform each file separately.
        for t in trees:
            # Skip the builtins module and files with '_skip.' in the path.
            if not t.path.endswith('/builtins.py') and '_skip.' not in t.path:
                if not first:
                    # Display path for files other than the first.
                    a.append('{}:'.format(
                        remove_prefix(t.path, test_temp_dir)))
                
                # Transform parse tree and produce the code for operations.
                # Note that currently we generate this for each file
                # separately; this needs to be fixed eventually.
                v = DyncheckTransformVisitor(types, symtable, True)
                t.accept(v)
                s = generate_runtime_support(t)
                if s != '':
                    a += s.split('\n')
            first = False
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal_wildcards(
        expected, a,
        'Invalid source code output ({}, line {})'.format(testcase.file,
                                                          testcase.line))
コード例 #3
0
ファイル: testopgen.py プロジェクト: prodigeni/mypy
def test_op_gen(testcase):
    """Perform a type operation support data and code genereation test case."""
    expected = remove_comment_lines(testcase.output)
    try:
        src = '\n'.join(testcase.input)
        # Parse and type check the input program.
        trees, symtable, infos, types = build(src, 'main', False,
                                              test_temp_dir, True)
        a = []
        first = True
        # Transform each file separately.
        for t in trees:
            # Skip the builtins module and files with '_skip.' in the path.
            if not t.path.endswith('/builtins.py') and '_skip.' not in t.path:
                if not first:
                    # Display path for files other than the first.
                    a.append('{}:'.format(remove_prefix(t.path,
                                                        test_temp_dir)))

                # Transform parse tree and produce the code for operations.
                # Note that currently we generate this for each file
                # separately; this needs to be fixed eventually.
                v = DyncheckTransformVisitor(types, symtable, True)
                t.accept(v)
                s = generate_runtime_support(t)
                if s != '':
                    a += s.split('\n')
            first = False
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal_wildcards(
        expected, a, 'Invalid source code output ({}, line {})'.format(
            testcase.file, testcase.line))