How to use covimerage - 10 common examples

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():
    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')"),
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_profile_parse_dict_function_with_continued_lines():
    from covimerage import Profile

    fname = 'tests/fixtures/dict_function_with_continued_lines.profile'
    p = Profile(fname)
    p.parse()

    assert len(p.scripts) == 1
    s = p.scripts[0]

    assert s.dict_functions == {3}
    assert s.mapped_dict_functions == {3}

    N = None
    assert [(l.count, l.line) for l in s.lines.values()] == [
        (N, '" Test parsing of dict function with continued lines.'),
        (1, 'let obj = {}'),
        (1, 'function! obj.dict_function(arg) abort'),
        (3, '  if a:arg'),
        (2, '    echom'),
        (2, '          \\ a:arg'),
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_map_functions(caplog):
    from covimerage import Function, Profile

    p = Profile('fake')

    p.map_functions([])
    assert not caplog.records

    funcs = [Function(name='missing')]
    p.map_functions(funcs)
    assert len(funcs) == 1
    assert caplog.record_tuples == [
        ('covimerage', 40, 'Could not find source for function: missing')]
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_function_in_function_with_ref(caplog):
    from covimerage import Profile

    fname = 'tests/fixtures/function_in_function_with_ref.profile'
    p = Profile(fname)
    p.parse()

    assert len(p.scripts) == 1
    s = p.scripts[0]

    assert [(l.count, l.line) for l in s.lines.values()
            if not l.line.startswith('"')] == [
        (None, ''),
        (1, 'let g:refs = []'),
        (None, ''),
        (1, 'function! Outer()'),
        (1, '  function! GetObj()'),
        (1, '    let obj = {}'),
        (1, '    function obj.func()'),
        (1, '      return 1'),
        (None, '    endfunction'),
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
def test_conditional_functions():
    from covimerage import Profile

    fname = 'tests/fixtures/conditional_function.profile'
    p = Profile(fname)
    p.parse()

    assert len(p.scripts) == 1
    s = p.scripts[0]

    N = None
    assert [(l.count, l.line) for l in s.lines.values()] == [
        (N, '" Test for detection of conditional functions.'),
        (N, ''),
        (1, 'if 0'),
        (N, '  function Foo()'),
        (N, '    return 1'),
        (N, '  endfunction'),
        (N, 'else'),
        (1, '  function Foo()'),
        (1, '    return 1'),
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_profile_repr_lines():
    from covimerage import Line, Profile, Script

    with pytest.raises(TypeError):
        Profile()

    p = Profile('profile-path')
    s = Script('script-path')
    p.scripts.append(s)
    assert repr(p.lines) == '{%r: {}}' % s
    assert repr(s) == "Script(path='script-path', sourced_count=None)"

    line = Line('line1')
    s.lines[1] = line
    assert repr(p.lines) == ('{%r: {1: %r}}' % (s, line))
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_find_func_in_source():
    from covimerage import Function, Profile, Script

    s = Script('fake')
    s.parse_function(1, 'fun! Python_jump(mode, motion, flags) range')
    s.parse_function(2, 'fu g:Foo()')
    s.parse_function(3, 'fun\tsome#autoload()')
    p = Profile('fake', scripts=[s])

    f = p.find_func_in_source

    assert f(Function(name='247_Python_jump')) == (s, 1)
    assert f(Function(name='Foo')) == (s, 2)
    assert f(Function(name='some#autoload')) == (s, 3)
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_profile_fname_or_fobj(caplog, devnull):
    from covimerage import Profile

    with pytest.raises(FileNotFoundError) as excinfo:
        Profile('/does/not/exist').parse()
    assert str(excinfo.value) == \
        "[Errno 2] No such file or directory: '/does/not/exist'"

    with caplog.at_level(logging.DEBUG, logger='covimerage'):
        Profile(devnull).parse()
    msgs = [(r.levelname, r.message) for r in caplog.records]
    assert msgs == [('DEBUG', 'Parsing file: /dev/null')]

    fileobj = StringIO('')
    with caplog.at_level(logging.DEBUG, logger='covimerage'):
        Profile(fileobj).parse()
    msgs = [(r.levelname, r.message) for r in caplog.records]
    assert msgs[-1] == ('DEBUG', 'Parsing file: %s' % fileobj)
    assert len(msgs) == 2
github Vimjas / covimerage / tests / test_main.py View on Github external
def test_function_in_function():
    from covimerage import Profile

    fname = 'tests/fixtures/function_in_function.profile'
    p = Profile(fname)
    p.parse()

    assert len(p.scripts) == 1
    s = p.scripts[0]

    assert [(l.count, l.line) for l in s.lines.values()] == [
        (None, '" Test for dict function in function.'),
        (None, ''),
        (1, 'function! GetObj()'),
        (1, '  let obj = {}'),
        (1, '  function obj.func()'),
        (1, '    return 1'),
        (None, '  endfunction'),
        (1, '  return obj'),
        (None, 'endfunction'),
        (None, ''),