How to use the covimerage.MergedProfiles function in covimerage

To help you get started, we’ve selected a few covimerage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Vimjas / covimerage / tests / test_main.py View on Github external
def test_merged_profiles_get_coveragepy_data():
    from covimerage import MergedProfiles

    m = MergedProfiles([])
    cov_data = m.get_coveragepy_data()
    try:
        from coverage.data import CoverageJsonData
    except ImportError:
        assert isinstance(cov_data, coverage.CoverageData)
    else:
        assert isinstance(cov_data, CoverageJsonData)
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_merged_profiles_write_coveragepy_data_handles_fname_and_fobj(
        mocker, caplog):
    from covimerage import MergedProfiles

    m = MergedProfiles([])
    mocked_data = mocker.Mock()
    mocker.patch.object(m, 'get_coveragepy_data', return_value=mocked_data)

    m.write_coveragepy_data()
    assert mocked_data.write_file.call_args_list == [mocker.call('.coverage')]
    assert mocked_data.write_fileobj.call_args_list == []

    mocked_data.reset_mock()
    fileobj = StringIO()
    m.write_coveragepy_data(data_file=fileobj)
    assert mocked_data.write_file.call_args_list == []
    assert mocked_data.write_fileobj.call_args_list == [mocker.call(fileobj)]
    msgs = [r.message for r in caplog.records]
    assert msgs == [
        'Writing coverage file .coverage.',
        'Writing coverage file %s.' % fileobj]
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_merged_profiles():
    from covimerage import MergedProfiles, Profile

    p1 = Profile('tests/fixtures/merge-1.profile')
    p1.parse()
    p2 = Profile('tests/fixtures/merge-2.profile')
    p2.parse()
    assert p1.scriptfiles == p2.scriptfiles

    m = MergedProfiles([p1, p2])

    assert list(m.scripts) == p1.scripts + p2.scripts
    assert m.scriptfiles == p1.scriptfiles

    N = None
    s_fname = '/test_plugin/merged_profiles.vim'
    assert [(l.count, l.line) for lnum, l in m.lines[s_fname].items()] == [
        (N, '" Generate profile output for merged profiles.'),
        (N, '" Used merged_profiles-init.vim'),
        (2, "if !exists('s:conditional')"),
        (1, '  function! F()'),
        (1, '    echom 1'),
        (N, '  endfunction'),
        (1, '  let s:conditional = 1'),
        (1, '  echom 1'),
        (1, '  call F()'),
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_mergedprofiles_caches_coveragepy_data(mocker):
    from covimerage import MergedProfiles, Profile

    m = MergedProfiles([])
    spy = mocker.spy(m, '_get_coveragepy_data')

    m.get_coveragepy_data()
    assert spy.call_count == 1
    m.get_coveragepy_data()
    assert spy.call_count == 1

    m.profiles += [Profile('foo')]
    m.get_coveragepy_data()
    assert spy.call_count == 2

    m.profiles = [Profile('bar')]
    m.get_coveragepy_data()
    assert spy.call_count == 3
github Vimjas / covimerage / tests / test_main.py View on Github external
count  total (s)   self (s)
                                let foo = 1
        1              0.000002 let bar = 2
    """)

    p = Profile(StringIO(profile))
    p.parse()

    script = p.scripts[0]

    assert [(l.count, l.line) for l in script.lines.values()] == [
        (None, 'let foo = 1'),
        (1, 'let bar = 2'),
    ]

    m = MergedProfiles([p])
    assert [(l.count, l.line) for l in m.lines[script.path].values()] == [
        (1, 'let foo = 1'),
        (1, 'let bar = 2'),
    ]
github Vimjas / covimerage / covimerage / cli.py View on Github external
A wrapper around `coverage report`.

    This will automatically add covimerage as a plugin, and then just forwards
    most options.

    If PROFILE_FILE is provided this gets parsed, otherwise DATA_FILE is used.
    """
    # Use None instead of empty set, for coveragepy to use the config file.
    include = include if include else None
    omit = omit if omit else None

    if data:
        data_file = None
    elif profile_file:
        data_file = None
        m = MergedProfiles(source=source)
        m.add_profile_files(*profile_file)
        data = m.get_coveragepy_data()
    config_file = ctx.obj.get('rcfile') if ctx.obj else None
    CoverageWrapper(
        data=data,
        data_file=data_file,
        config_file=config_file,
    ).report(
        report_file=report_file,
        show_missing=show_missing,
        include=include,
        omit=omit,
        skip_covered=skip_covered,
    )
github Vimjas / covimerage / covimerage / cli.py View on Github external
if profile_file:
        if not os.path.exists(profile_file):
            if not exit_code:
                raise CustomClickException(
                    'The profile file (%s) has not been created.' % (
                        profile_file))

        elif write_data or report:
            logger.info('Parsing profile file %s.', profile_file)
            p = Profile(profile_file)
            p.parse()

            if append:
                m = MergedProfiles([p], source=source, append_to=data_file)
            else:
                m = MergedProfiles([p], source=source)

            if write_data:
                m.write_coveragepy_data(data_file)

            if report:
                cov_data = m.get_coveragepy_data()
                if not cov_data:
                    raise CustomClickException('No data to report.')
                report_opts['data'] = cov_data
                ctx.invoke(report_cmd, report_file=report_file,
                           **report_opts)
        if unlink_profile_file:
            try:
                os.unlink(profile_file)
            except Exception:  # ignore FileNotFoundError (OSError on py2).
                if os.path.exists(profile_file):
github Vimjas / covimerage / covimerage / cli.py View on Github external
def write_coverage(profile_file, data_file, source, append):
    """
    Parse PROFILE_FILE (output from Vim's :profile) and write it into DATA_FILE
    (Coverage.py compatible).
    """
    if append:
        m = MergedProfiles(source=source, append_to=data_file)
    else:
        m = MergedProfiles(source=source)

    m.add_profile_files(*profile_file)

    if not m.write_coveragepy_data(data_file=data_file):
        raise CustomClickException('No data to report.')
github Vimjas / covimerage / covimerage / cli.py View on Github external
def write_coverage(profile_file, data_file, source, append):
    """
    Parse PROFILE_FILE (output from Vim's :profile) and write it into DATA_FILE
    (Coverage.py compatible).
    """
    if append:
        m = MergedProfiles(source=source, append_to=data_file)
    else:
        m = MergedProfiles(source=source)

    m.add_profile_files(*profile_file)

    if not m.write_coveragepy_data(data_file=data_file):
        raise CustomClickException('No data to report.')
github Vimjas / covimerage / covimerage / cli.py View on Github external
raise CustomClickException('Failed to run %s: %s' % (cmd, exc))

    if profile_file:
        if not os.path.exists(profile_file):
            if not exit_code:
                raise CustomClickException(
                    'The profile file (%s) has not been created.' % (
                        profile_file))

        elif write_data or report:
            logger.info('Parsing profile file %s.', profile_file)
            p = Profile(profile_file)
            p.parse()

            if append:
                m = MergedProfiles([p], source=source, append_to=data_file)
            else:
                m = MergedProfiles([p], source=source)

            if write_data:
                m.write_coveragepy_data(data_file)

            if report:
                cov_data = m.get_coveragepy_data()
                if not cov_data:
                    raise CustomClickException('No data to report.')
                report_opts['data'] = cov_data
                ctx.invoke(report_cmd, report_file=report_file,
                           **report_opts)
        if unlink_profile_file:
            try:
                os.unlink(profile_file)