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


Python coverage.process_startup方法代码示例

本文整理汇总了Python中coverage.process_startup方法的典型用法代码示例。如果您正苦于以下问题:Python coverage.process_startup方法的具体用法?Python coverage.process_startup怎么用?Python coverage.process_startup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage的用法示例。


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

示例1: deploy_models

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def deploy_models(self, username: str, password: str):
        repo_dir = os.path.abspath(os.path.dirname(tabpy.__file__))
        path = os.path.join(repo_dir, "models", "deploy_models.py")
        with open(self.tmp_dir + "/deploy_models_output.txt", "w") as outfile:
            outfile.write(
                f"--<< Running {self.py} {path} "
                f"{self._get_config_file_name()} >>--\n"
            )
            input_string = f"{username}\n{password}\n"
            outfile.write(f"--<< Input = {input_string} >>--")
            coverage.process_startup()
            subprocess.run(
                [self.py, path, self._get_config_file_name()],
                input=input_string.encode("utf-8"),
                stdout=outfile,
                stderr=outfile,
            ) 
开发者ID:tableau,项目名称:TabPy,代码行数:19,代码来源:integ_test_base.py

示例2: test_subprocess_main

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def test_subprocess_main(self, basicConfig):
        import parallel_render
        import coverage
        environ = {
            'COVERAGE_PROCESS_START': 'something',
            'PYTHONPATH': 'path',
        }
        sys = mock.MagicMock()
        sys.path = []
        sys.argv = ['--', 'render']
        with mock.patch.object(os, 'environ', environ):
            with mock.patch.object(coverage, 'process_startup') as process_startup:
                with mock.patch.object(parallel_render, 'render') as render:
                    with mock.patch.object(parallel_render, 'sys', sys):
                        parallel_render.main()
                        self.assertTrue(render.called)
                        self.assertTrue(basicConfig.called)
                        self.assertTrue(process_startup.called) 
开发者ID:elmopl,项目名称:ktba,代码行数:20,代码来源:test_parallel_render.py

示例3: main

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def main():
    covstart = os.environ.get('COVERAGE_PROCESS_START')
    if covstart is not None:
        sys.path.extend(os.environ['PYTHONPATH'].split(os.path.sep))
        import coverage
        coverage.process_startup()

    # Get everything after '--' as those are arguments
    # to our script
    args = sys.argv[sys.argv.index('--') + 1:]
    logging.basicConfig(level=logging.INFO)

    action = args[0]

    if action == 'render':
        render() 
开发者ID:elmopl,项目名称:ktba,代码行数:18,代码来源:parallel_render.py

示例4: setUp

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def setUp(self):
        super(IntegTestBase, self).setUp()
        prefix = "TabPy_IntegTest_"
        self.tmp_dir = tempfile.mkdtemp(prefix=prefix)

        # create temporary state.ini
        orig_state_file_name = os.path.abspath(
            self._get_state_file_path() + "/state.ini"
        )
        self.state_file_name = os.path.abspath(self.tmp_dir + "/state.ini")
        if orig_state_file_name != self.state_file_name:
            shutil.copyfile(orig_state_file_name, self.state_file_name)

        # create config file
        orig_config_file_name = os.path.abspath(self._get_config_file_name())
        self.config_file_name = os.path.abspath(
            self.tmp_dir + "/" + os.path.basename(orig_config_file_name)
        )
        if orig_config_file_name != self.config_file_name:
            shutil.copyfile(orig_config_file_name, self.config_file_name)

        # Platform specific - for integration tests we want to engage
        # startup script
        with open(self.tmp_dir + "/output.txt", "w") as outfile:
            cmd = ["tabpy", "--config=" + self.config_file_name]
            preexec_fn = None
            if platform.system() == "Windows":
                self.py = "python"
            else:
                self.py = "python3"
                preexec_fn = os.setsid

            coverage.process_startup()
            self.process = subprocess.Popen(
                cmd, preexec_fn=preexec_fn, stdout=outfile, stderr=outfile
            )

            # give the app some time to start up...
            time.sleep(5) 
开发者ID:tableau,项目名称:TabPy,代码行数:41,代码来源:integ_test_base.py

示例5: _prevent_sub_process_measurement

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def _prevent_sub_process_measurement():
    """Stop any subprocess auto-measurement from writing data."""
    auto_created_coverage = getattr(process_startup, "coverage", None)
    if auto_created_coverage is not None:
        auto_created_coverage._auto_save = False 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:7,代码来源:control.py

示例6: setUp

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def setUp(self):
        super(ProcessCoverageMixin, self).setUp()

        # Create the .pth file.
        self.assertTrue(PTH_DIR)
        pth_contents = "import coverage; coverage.process_startup()\n"
        pth_path = os.path.join(PTH_DIR, "subcover_{0}.pth".format(WORKER))
        with open(pth_path, "w") as pth:
            pth.write(pth_contents)
            self.pth_path = pth_path

        self.addCleanup(os.remove, self.pth_path) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:14,代码来源:test_process.py

示例7: main

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def main():
    if sys.argv[1:] == ['subprocess']:
        print('subprocess')
        cov = coverage.process_startup()
        subprocess_main()
    elif sys.argv[1:] == []:
        print('process')
        subprocess.check_call((sys.executable, __file__, 'subprocess')) 
开发者ID:elmopl,项目名称:ktba,代码行数:10,代码来源:test_dummy.py

示例8: run_tests

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def run_tests(args):
    extra_pythonpath = args[1]
    sys.path.append(extra_pythonpath)
    LOGGER.info("Appending extra PYTHONPATH %s", extra_pythonpath)
    import coverage
    coverage.process_startup()

    # I split this into separate function to increase coverage
    # ever so slightly.
    # I am not clear why, but it seems that coverage misses out on lines
    # within the same function as coverage.process_startup() got called.
    # Caling into another function seems to help it.
    _run_tests(args) 
开发者ID:elmopl,项目名称:ktba,代码行数:15,代码来源:test_parallel_render.py

示例9: setUp

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def setUp(self):
        super(ProcessCoverageMixin, self).setUp()

        # Create the .pth file.
        self.assertTrue(PTH_DIR)
        pth_contents = "import coverage; coverage.process_startup()\n"
        pth_path = os.path.join(PTH_DIR, "subcover_{}.pth".format(WORKER))
        with open(pth_path, "w") as pth:
            pth.write(pth_contents)
            self.pth_path = pth_path

        self.addCleanup(persistent_remove, self.pth_path) 
开发者ID:nedbat,项目名称:coveragepy,代码行数:14,代码来源:test_process.py

示例10: _runTest

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def _runTest(self):
        kernel = "python%d" % sys.version_info[0]
        cur_dir = os.path.dirname(self.nbfile)

        with open(self.nbfile) as f:
            nb = nbformat.read(f, as_version=4)
            if self.cov:
                covdict = {
                    "cell_type": "code",
                    "execution_count": 1,
                    "metadata": {"collapsed": True},
                    "outputs": [],
                    "nbsphinx": "hidden",
                    "source": "import coverage\n"
                    "coverage.process_startup()\n"
                    "import sys\n"
                    'sys.path.append("{0}")\n'.format(cur_dir),
                }
                nb["cells"].insert(0, nbformat.from_dict(covdict))

            exproc = ExecutePreprocessor(kernel_name=kernel, timeout=600)

            try:
                run_dir = os.getenv("WRADLIB_BUILD_DIR", cur_dir)
                exproc.preprocess(nb, {"metadata": {"path": run_dir}})
            except CellExecutionError as e:
                raise e

        if self.cov:
            nb["cells"].pop(0)

        with io.open(self.nbfile, "wt") as f:
            nbformat.write(nb, f)

        self.assertTrue(True) 
开发者ID:wradlib,项目名称:wradlib,代码行数:37,代码来源:testrunner.py

示例11: _initCoverage

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def _initCoverage():
    if  'COVERAGE_PROCESS_START' in os.environ:
        try:
            import coverage
            coverage.process_startup()
        except ImportError:
            pass 
开发者ID:RobotLocomotion,项目名称:director,代码行数:9,代码来源:__init__.py

示例12: process_startup

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def process_startup():
    """Call this at Python start-up to perhaps measure coverage.

    If the environment variable COVERAGE_PROCESS_START is defined, coverage
    measurement is started.  The value of the variable is the config file
    to use.

    There are two ways to configure your Python installation to invoke this
    function when Python starts:

    #. Create or append to sitecustomize.py to add these lines::

        import coverage
        coverage.process_startup()

    #. Create a .pth file in your Python installation containing::

        import coverage; coverage.process_startup()

    Returns the :class:`Coverage` instance that was started, or None if it was
    not started by this call.

    """
    cps = os.environ.get("COVERAGE_PROCESS_START")
    if not cps:
        # No request for coverage, nothing to do.
        return None

    # This function can be called more than once in a process. This happens
    # because some virtualenv configurations make the same directory visible
    # twice in sys.path.  This means that the .pth file will be found twice,
    # and executed twice, executing this function twice.  We set a global
    # flag (an attribute on this function) to indicate that coverage.py has
    # already been started, so we can avoid doing it twice.
    #
    # https://bitbucket.org/ned/coveragepy/issue/340/keyerror-subpy has more
    # details.

    if hasattr(process_startup, "coverage"):
        # We've annotated this function before, so we must have already
        # started coverage.py in this process.  Nothing to do.
        return None

    cov = Coverage(config_file=cps)
    process_startup.coverage = cov
    cov._warn_no_data = False
    cov._warn_unimported_source = False
    cov._warn_preimported_source = False
    cov._auto_save = True
    cov.start()

    return cov 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:54,代码来源:control.py

示例13: run_tests_with_coverage

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def run_tests_with_coverage(tracer, *runner_args):
    """Run tests, but with coverage."""
    # Need to define this early enough that the first import of env.py sees it.
    os.environ['COVERAGE_TESTING'] = "True"
    os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
    os.environ['COVERAGE_HOME'] = os.getcwd()

    # Create the .pth file that will let us measure coverage in sub-processes.
    # The .pth file seems to have to be alphabetically after easy-install.pth
    # or the sys.path entries aren't created right?
    pth_dir = os.path.dirname(pytest.__file__)
    pth_path = os.path.join(pth_dir, "zzz_metacov.pth")
    with open(pth_path, "w") as pth_file:
        pth_file.write("import coverage; coverage.process_startup()\n")

    # Make names for the data files that keep all the test runs distinct.
    impl = platform.python_implementation().lower()
    version = "%s%s" % sys.version_info[:2]
    if '__pypy__' in sys.builtin_module_names:
        version += "_%s%s" % sys.pypy_version_info[:2]
    suffix = "%s%s_%s_%s" % (impl, version, tracer, platform.platform())

    os.environ['COVERAGE_METAFILE'] = os.path.abspath(".metacov."+suffix)

    import coverage
    cov = coverage.Coverage(config_file="metacov.ini", data_suffix=False)
    cov._warn_unimported_source = False
    cov._warn_preimported_source = False
    cov.start()

    try:
        # Re-import coverage to get it coverage tested!  I don't understand all
        # the mechanics here, but if I don't carry over the imported modules
        # (in covmods), then things go haywire (os == None, eventually).
        covmods = {}
        covdir = os.path.split(coverage.__file__)[0]
        # We have to make a list since we'll be deleting in the loop.
        modules = list(sys.modules.items())
        for name, mod in modules:
            if name.startswith('coverage'):
                if getattr(mod, '__file__', "??").startswith(covdir):
                    covmods[name] = mod
                    del sys.modules[name]
        import coverage                         # pylint: disable=reimported
        sys.modules.update(covmods)

        # Run tests, with the arguments from our command line.
        status = run_tests(tracer, *runner_args)

    finally:
        cov.stop()
        os.remove(pth_path)

    cov.combine()
    cov.save()

    return status 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:59,代码来源:igor.py

示例14: run_tests_with_coverage

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import process_startup [as 别名]
def run_tests_with_coverage(tracer, *runner_args):
    """Run tests, but with coverage."""
    # Need to define this early enough that the first import of env.py sees it.
    os.environ['COVERAGE_TESTING'] = "True"
    os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
    os.environ['COVERAGE_HOME'] = os.getcwd()

    # Create the .pth file that will let us measure coverage in sub-processes.
    # The .pth file seems to have to be alphabetically after easy-install.pth
    # or the sys.path entries aren't created right?
    # There's an entry in "make clean" to get rid of this file.
    pth_dir = os.path.dirname(pytest.__file__)
    pth_path = os.path.join(pth_dir, "zzz_metacov.pth")
    with open(pth_path, "w") as pth_file:
        pth_file.write("import coverage; coverage.process_startup()\n")

    suffix = "%s_%s" % (make_env_id(tracer), platform.platform())
    os.environ['COVERAGE_METAFILE'] = os.path.abspath(".metacov."+suffix)

    import coverage
    cov = coverage.Coverage(config_file="metacov.ini")
    cov._warn_unimported_source = False
    cov._warn_preimported_source = False
    cov.start()

    try:
        # Re-import coverage to get it coverage tested!  I don't understand all
        # the mechanics here, but if I don't carry over the imported modules
        # (in covmods), then things go haywire (os == None, eventually).
        covmods = {}
        covdir = os.path.split(coverage.__file__)[0]
        # We have to make a list since we'll be deleting in the loop.
        modules = list(sys.modules.items())
        for name, mod in modules:
            if name.startswith('coverage'):
                if getattr(mod, '__file__', "??").startswith(covdir):
                    covmods[name] = mod
                    del sys.modules[name]
        import coverage                         # pylint: disable=reimported
        sys.modules.update(covmods)

        # Run tests, with the arguments from our command line.
        status = run_tests(tracer, *runner_args)

    finally:
        cov.stop()
        os.remove(pth_path)

    cov.combine()
    cov.save()

    return status 
开发者ID:nedbat,项目名称:coveragepy,代码行数:54,代码来源:igor.py


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