当前位置: 首页>>代码示例>>Python>>正文


Python build.build函数代码示例

本文整理汇总了Python中mypy.build.build函数的典型用法代码示例。如果您正苦于以下问题:Python build函数的具体用法?Python build怎么用?Python build使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了build函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cgen

def test_cgen(testcase):
    # Build the program.
    text = '\n'.join(testcase.input)
    program = '_program.py'
    try:
        build.build(program,
                    target=build.C,
                    program_text=text,
                    flags=[build.TEST_BUILTINS],
                    alt_lib_path='lib')
        # Run the program.
        outfile = './_program'
        outb = subprocess.check_output([outfile], stderr=subprocess.STDOUT)
        # Split output into lines.
        out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()]
        # Remove temp file.
        os.remove(outfile)
    except errors.CompileError as e:
        out = e.messages
    # Include line-end comments in the expected output.
    # Note: # characters in string literals can confuse this.
    for s in testcase.input:
        m = re.search(' #(?! type:)(.*)', s)
        if m:
            testcase.output.append(m.group(1).strip())
    # Verify output.
    assert_string_arrays_equal(testcase.output, out,
                               'Invalid output ({}, line {})'.format(
                                   testcase.file, testcase.line))
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:29,代码来源:testcgen.py

示例2: test_error_stream

def test_error_stream(testcase: DataDrivenTestCase) -> None:
    """Perform a single error streaming test case.

    The argument contains the description of the test case.
    """
    options = Options()
    options.show_traceback = True

    logged_messages = []  # type: List[str]

    def flush_errors(msgs: List[str], serious: bool) -> None:
        if msgs:
            logged_messages.append('==== Errors flushed ====')
            logged_messages.extend(msgs)

    sources = [BuildSource('main', '__main__', '\n'.join(testcase.input))]
    try:
        build.build(sources=sources,
                    options=options,
                    alt_lib_path=test_temp_dir,
                    flush_errors=flush_errors)
    except CompileError as e:
        assert e.messages == []

    assert_string_arrays_equal(testcase.output, logged_messages,
                               'Invalid output ({}, line {})'.format(
                                   testcase.file, testcase.line))
开发者ID:sixolet,项目名称:mypy,代码行数:27,代码来源:testerrorstream.py

示例3: type_check_only

def type_check_only(sources: List[BuildSource],
        options: Options) -> None:
    # Type check the program and dependencies and translate to Python.
    build.build(sources=sources,
                target=build.TYPE_CHECK,
                implementation=options.implementation,
                custom_typing_module=options.custom_typing_module,
                report_dirs=options.report_dirs,
                flags=options.build_flags,
                python_path=options.python_path)
开发者ID:o11c,项目名称:mypy,代码行数:10,代码来源:main.py

示例4: type_check_only

def type_check_only(path: str, module: str, program_text: str,
        bin_dir: str, options: Options) -> None:
    # Type check the program and dependencies and translate to Python.
    build.build(path,
                module=module,
                program_text=program_text,
                bin_dir=bin_dir,
                target=build.TYPE_CHECK,
                pyversion=options.pyversion,
                custom_typing_module=options.custom_typing_module,
                report_dirs=options.report_dirs,
                flags=options.build_flags,
                python_path=options.python_path)
开发者ID:dahlia,项目名称:mypy,代码行数:13,代码来源:main.py

示例5: run_test

 def run_test(self, testcase):
     a = []
     try:
         src = '\n'.join(testcase.input)
         build.build('main',
                     target=build.TYPE_CHECK,
                     program_text=src,
                     flags=[build.TEST_BUILTINS],
                     alt_lib_path=test_temp_dir)
     except CompileError as e:
         a = normalize_error_messages(e.messages)
     assert_string_arrays_equal(
         testcase.output, a,
         'Invalid type checker output ({}, line {})'.format(
             testcase.file, testcase.line))
开发者ID:Varriount,项目名称:mypy,代码行数:15,代码来源:testcheck.py

示例6: run_test

 def run_test(self, testcase):
     a = []
     try:
         line = testcase.input[0]
         mask = ''
         if line.startswith('##'):
             mask = '(' + line[2:].strip() + ')$'
         
         src = '\n'.join(testcase.input)
         result = build.build(program_path='main',
                              target=build.TYPE_CHECK,
                              program_text=src,
                              flags=[build.TEST_BUILTINS],
                              alt_lib_path=testconfig.test_temp_dir)
         map = result.types
         kk = map.keys()
         keys = []
         for k in kk:
             if k.line is not None and k.line != -1 and map[k]:
                 if (re.match(mask, short_type(k))
                         or (isinstance(k, NameExpr)
                             and re.match(mask, k.name))):
                     keys.append(k)
         for key in sorted(keys,
                           key=lambda n: (n.line, short_type(n),
                                          str(n) + str(map[n]))):
             ts = str(map[key]).replace('*', '') # Remove erased tags
             ts = ts.replace('__main__.', '')
             a.append('{}({}) : {}'.format(short_type(key), key.line, ts))
     except CompileError as e:
         a = e.messages
     assert_string_arrays_equal(
         testcase.output, a,
         'Invalid type checker output ({}, line {})'.format(testcase.file,
                                                            testcase.line))
开发者ID:SRiikonen,项目名称:mypy,代码行数:35,代码来源:testtypegen.py

示例7: run_test

    def run_test(self, testcase):
        """Perform a test case."""
        try:
            # Build test case input.
            src = '\n'.join(testcase.input)
            result = build.build('main',
                                 target=build.SEMANTIC_ANALYSIS,
                                 program_text=src,
                                 flags=[build.TEST_BUILTINS],
                                 alt_lib_path=test_temp_dir)

            # Collect all TypeInfos in top-level modules.
            typeinfos = TypeInfoMap()
            for f in result.files.values():
                for n in f.names.values():
                    if isinstance(n.node, TypeInfo):
                        typeinfos[n.fullname] = n.node

            # The output is the symbol table converted into a string.
            a = str(typeinfos).split('\n')
        except CompileError as e:
            a = e.messages
        assert_string_arrays_equal(
            testcase.output, a,
            'Invalid semantic analyzer output ({}, line {})'.format(
                testcase.file, testcase.line))
开发者ID:JamesTFarrington,项目名称:mypy,代码行数:26,代码来源:testsemanal.py

示例8: run_case

    def run_case(self, testcase: DataDrivenTestCase) -> None:
        """Perform a test case."""
        try:
            # Build test case input.
            src = '\n'.join(testcase.input)
            result = build.build(sources=[BuildSource('main', None, src)],
                                 options=get_semanal_options(),
                                 alt_lib_path=test_temp_dir)
            a = result.errors
            if a:
                raise CompileError(a)

            # Collect all TypeInfos in top-level modules.
            typeinfos = TypeInfoMap()
            for f in result.files.values():
                for n in f.names.values():
                    if isinstance(n.node, TypeInfo):
                        assert n.fullname is not None
                        typeinfos[n.fullname] = n.node

            # The output is the symbol table converted into a string.
            a = str(typeinfos).split('\n')
        except CompileError as e:
            a = e.messages
        assert_string_arrays_equal(
            testcase.output, a,
            'Invalid semantic analyzer output ({}, line {})'.format(
                testcase.file, testcase.line))
开发者ID:sixolet,项目名称:mypy,代码行数:28,代码来源:testsemanal.py

示例9: test_semanal

def test_semanal(testcase):
    """Perform a semantic analysis test case.

    The testcase argument contains a description of the test case
    (inputs and output).
    """

    try:
        src = "\n".join(testcase.input)
        options = get_semanal_options()
        options.python_version = testfile_pyversion(testcase.file)
        result = build.build(sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir)
        a = result.errors
        if a:
            raise CompileError(a)
        # Include string representations of the source files in the actual
        # output.
        for fnam in sorted(result.files.keys()):
            f = result.files[fnam]
            # Omit the builtins module and files with a special marker in the
            # path.
            # TODO the test is not reliable
            if (
                not f.path.endswith(
                    (os.sep + "builtins.pyi", "typing.pyi", "mypy_extensions.pyi", "abc.pyi", "collections.pyi")
                )
                and not os.path.basename(f.path).startswith("_")
                and not os.path.splitext(os.path.basename(f.path))[0].endswith("_")
            ):
                a += str(f).split("\n")
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(
        testcase.output, a, "Invalid semantic analyzer output ({}, line {})".format(testcase.file, testcase.line)
    )
开发者ID:rowillia,项目名称:mypy,代码行数:35,代码来源:testsemanal.py

示例10: test_transform

def test_transform(testcase):
    """Perform an identity transform test case."""
    
    try:
        src = '\n'.join(testcase.input)
        result = build.build('main',
                             target=build.SEMANTIC_ANALYSIS,
                             program_text=src,
                             pyversion=testfile_pyversion(testcase.file),
                             flags=[build.TEST_BUILTINS],
                             alt_lib_path=test_temp_dir)
        a = []
        # Include string representations of the source files in the actual
        # output.
        for fnam in sorted(result.files.keys()):
            f = result.files[fnam]

            # Omit the builtins module and files with a special marker in the
            # path.
            # TODO the test is not reliable
            if (not f.path.endswith((os.sep + 'builtins.py',
                                     'typing.py',
                                     'abc.py'))
                    and not os.path.basename(f.path).startswith('_')
                    and not os.path.splitext(
                        os.path.basename(f.path))[0].endswith('_')):
                t = TestTransformVisitor()
                f = t.node(f)
                a += str(f).split('\n')
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(
        testcase.output, a,
        'Invalid semantic analyzer output ({}, line {})'.format(testcase.file,
                                                                testcase.line))
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:35,代码来源:testtransform.py

示例11: test_transform

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(program_path='main',
                             target=build.ICODE,
                             program_text=src,
                             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))
开发者ID:Varriount,项目名称:mypy,代码行数:30,代码来源:testicodegen.py

示例12: type_check_only

def type_check_only(sources: List[BuildSource], bin_dir: Optional[str],
                    options: Options,
                    flush_errors: Optional[Callable[[List[str], bool], None]]) -> BuildResult:
    # Type-check the program and dependencies.
    return build.build(sources=sources,
                       bin_dir=bin_dir,
                       options=options,
                       flush_errors=flush_errors)
开发者ID:sixolet,项目名称:mypy,代码行数:8,代码来源:main.py

示例13: test_semanal_error

def test_semanal_error(testcase):
    """Perform a test case."""

    try:
        src = '\n'.join(testcase.input)
        build.build(target=build.SEMANTIC_ANALYSIS,
                    sources=[BuildSource('main', None, src)],
                    flags=[build.TEST_BUILTINS],
                    alt_lib_path=test_temp_dir)
        raise AssertionError('No errors reported in {}, line {}'.format(
            testcase.file, testcase.line))
    except CompileError as e:
        # Verify that there was a compile error and that the error messages
        # are equivalent.
        assert_string_arrays_equal(
            testcase.output, normalize_error_messages(e.messages),
            'Invalid compiler output ({}, line {})'.format(testcase.file,
                                                           testcase.line))
开发者ID:FaithBradley200,项目名称:mypy,代码行数:18,代码来源:testsemanal.py

示例14: build

 def build(self,
           options: Options,
           sources: List[BuildSource]) -> List[str]:
     try:
         result = build.build(sources=sources,
                              options=options)
     except CompileError as e:
         return e.messages
     return result.errors
开发者ID:mananpal1997,项目名称:mypy,代码行数:9,代码来源:testfinegrained.py

示例15: compile_to_python

def compile_to_python(path, module, args):
    if path:
        basedir = os.path.dirname(path)
    else:
        basedir = os.getcwd()
    
    outputdir = os.path.join(basedir, '__mycache__')
    tempdir = False
    if not os.path.isdir(outputdir):
        try:
            os.mkdir(outputdir)
        except OSError:
            # Could not create a directory under program directory; must
            # fall back to a temp directory. It will be removed later.
            outputdir = tempfile.mkdtemp()
            tempdir = True

    try:
        # Type check the program and dependencies and translate to Python.
        build.build(path,
                    module=module,
                    target=build.PYTHON,
                    output_dir=outputdir,
                    flags=build_flags)

        if build.COMPILE_ONLY not in build_flags:
            # Run the translated program.
            if module:
                # Run the module using runpy. We can't use -m since Python
                # would try to run the mypy code instead of the translated
                # code.
                p = os.path.join(outputdir, '__main__.py')
                f = open(p, 'w')
                f.write('import runpy\n'
                        "runpy.run_module('%s', run_name='__main__')" % module)
                f.close()
                opts = [p]
            else:
                opts = [os.path.join(outputdir, os.path.basename(path))]
            status = subprocess.call([interpreter] + opts + args)
            sys.exit(status)
    finally:
        if tempdir:
            shutil.rmtree(outputdir)
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:44,代码来源:driver.py


注:本文中的mypy.build.build函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。