Skip to content

[WIP] Python provider: report partial lines and percentage from coveragepy #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions autoload/coverage.vim
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,23 @@ endfunction
function! coverage#GetFormattedStats(filename) abort
if has_key(s:cache, a:filename)
let l:data = s:cache[a:filename]
let l:stats = {'total': 0}
for l:state in s:coverage_states
let l:stats[l:state] = len(l:data[l:state])
let l:stats['total'] += len(l:data[l:state])
endfor
let l:percentage = 100.0 * l:stats.covered / l:stats.total
return printf('Coverage is %.2f%% (%d/%d lines).',
\ l:percentage, l:stats.covered, l:stats.total)
if has_key(l:data, 'stats')
let l:stats = l:data.stats
else
let l:stats = {'total': 0}
for l:state in s:coverage_states
let l:stats[l:state] = len(l:data[l:state])
let l:stats['total'] += len(l:data[l:state])
endfor
if has_key(l:data, 'percentage')
let l:stats.percentage = printf('%s%%', l:data.percentage)
else
let l:stats.percentage = printf('%.2f%%', 100.0 * l:stats.covered / l:stats.total)
endif
let l:data['stats'] = l:stats
endif
return printf('Coverage is %s (%d/%d lines (%d partial)).',
\ l:stats.percentage, l:stats.covered, l:stats.total, l:stats.partial)
endif
endfunction

Expand Down
6 changes: 4 additions & 2 deletions autoload/coverage/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ function! coverage#python#GetCoveragePyProvider() abort
\ 'vim_coverage.GetCoveragePyLines(%s, %s)',
\ string(l:cov_file),
\ string(a:filename)))
let [l:covered_lines, l:uncovered_lines] = l:coverage_data
return coverage#CreateReport(l:covered_lines, l:uncovered_lines, [])
let [l:covered_lines, l:uncovered_lines, l:partial_lines, l:percentage]
\ = l:coverage_data
return coverage#CreateReport(l:covered_lines, l:uncovered_lines, l:partial_lines,
\ {'percentage': l:percentage})
endfunction

return l:provider
Expand Down
12 changes: 10 additions & 2 deletions python/vim_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@


def GetCoveragePyLines(path, source_file):
"""Get (covered, uncovered) lines for source_file from .coverage file at path.
"""Get coverage information for source_file from .coverage file at path.

Returns (covered, uncovered, partial, percentage).
"""
prev_cwd = os.getcwd()
source_file = os.path.abspath(source_file)
Expand All @@ -39,4 +41,10 @@ def GetCoveragePyLines(path, source_file):
except TypeError:
covered_lines = cov.data.line_data()[source_file]
uncovered_lines = cov.analysis(source_file)[2]
return (covered_lines, uncovered_lines)

analysis = cov._analyze(source_file)
partial = list(analysis.missing_branch_arcs().keys())

percentage = analysis.numbers.pc_covered_str

return (covered_lines, uncovered_lines, partial, percentage)
2 changes: 1 addition & 1 deletion vroom/main.vroom
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ a fake coverage provider.

:silent edit $VROOMDIR/testdata/dummy.py
:CoverageShow test_coverage_provider
~ Coverage is 50.00% (7/14 lines).
~ Coverage is 50.00% (7/14 lines (0 partial)).
:silent file foo.unrecognized
:CoverageShow test_coverage_provider
~ Error rendering coverage: ERROR\(NotFound\): Provider (regex)
Expand Down
2 changes: 1 addition & 1 deletion vroom/python.vroom
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ surface the coverage results inside your vim editor.
:call WriteFakeCoveragePyFile(g:tmpdir, {'blah.py': [1, 2, 5]})

:CoverageShow coverage.py
~ Coverage is 50.00% (3/6 lines).
~ Coverage is 50% (3/6 lines (1 partial)).