def test_merged_profiles_get_coveragepy_data(): from covimerage import MergedProfiles m = MergedProfiles([]) cov_data = m.get_coveragepy_data() assert isinstance(cov_data, coverage.CoverageData) assert repr( cov_data) == '<CoverageData lines={0} arcs=None tracers={0} runs=[0]>'
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)
def test_mergedprofiles_fixes_line_count(): """Ref: https://github.com/vim/vim/issues/2103""" from covimerage import MergedProfiles, Profile profile = textwrap.dedent(""" SCRIPT /path/to/t.vim Sourced 1 time Total time: 0.000009 Self time: 0.000009 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'), ]
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()'), (N, ' call NeomakeTestsProfileRestart()'), (N, " exe 'source ' . expand('<sfile>')"), (1, 'else'), (1, ' function! F()'), (1, ' echom 2'), (N, ' endfunction'), (1, ' echom 2'), (1, ' call F()'), (1, 'endif'), (N, '')]
def test_mergedprofiles_fixes_line_count(): from covimerage import MergedProfiles, Profile fname = 'tests/fixtures/continued_lines.profile' p = Profile(fname) p.parse() script = p.scripts[0] N = None assert [(l.count, l.line) for l in script.lines.values()] == [(N, 'echom 1'), (1, 'echom 2'), (N, ' \\ 3'), (1, 'echom 4')] m = MergedProfiles([p]) assert [(l.count, l.line) for l in m.lines[script.path].values()] == [(1, 'echom 1'), (1, 'echom 2'), (N, ' \\ 3'), (1, 'echom 4')]
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]
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