-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
256c05b
commit ef75f9a
Showing
4 changed files
with
95 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
import os | ||
from pathlib import Path | ||
|
||
coverage = {} | ||
cov_dir = Path() / 'target' / 'coverage' | ||
|
||
for part in cov_dir.glob('*.json'): | ||
with part.open('r') as f: | ||
part = json.load(f) | ||
for file_name, part_file_coverage in part.items(): | ||
file_coverage = coverage.setdefault(file_name, {}) | ||
for line, covered in part_file_coverage.items(): | ||
file_coverage[line] = file_coverage.get(line, False) | covered | ||
|
||
with open(os.environ.get('GITHUB_STEP_SUMMARY', None) or cov_dir / 'summary.md', 'w') as f: | ||
print('| Name | Stmts | Miss | Cover |', file=f) | ||
print('| ---- | ----: | ---: | ----: |', file=f) | ||
total_covered = 0 | ||
total_executable = 0 | ||
for file_name, file_coverage in sorted(coverage.items()): | ||
file_covered = sum(file_coverage.values()) | ||
file_executable = len(file_coverage) | ||
file_percentage = 100 * file_covered / file_executable | ||
print(f'| {file_name} | {file_executable} | {file_covered} | {file_percentage:.1f}% |', file=f) | ||
total_covered += file_covered | ||
total_executable += file_executable | ||
total_percentage = 100 * total_covered / total_executable | ||
print(f'| TOTAL | {total_executable} | {total_covered} | {total_percentage:.1f}% |', file=f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import inspect | ||
import json | ||
import os | ||
from pathlib import Path | ||
import sys | ||
import unittest | ||
|
||
source = str(Path().resolve() / 'nutils') + os.sep | ||
coverage = {} | ||
|
||
if hasattr(sys, 'monitoring'): | ||
|
||
def start(code, _): | ||
if isinstance(code.co_filename, str) and code.co_filename.startswith(source) and not sys.monitoring.get_local_events(sys.monitoring.COVERAGE_ID, code): | ||
file_coverage = coverage.setdefault(code.co_filename, {}) | ||
for _, _, l in code.co_lines(): | ||
if l: | ||
file_coverage.setdefault(l, False) | ||
sys.monitoring.set_local_events(sys.monitoring.COVERAGE_ID, code, sys.monitoring.events.LINE) | ||
for obj in code.co_consts: | ||
if inspect.iscode(obj): | ||
start(obj, None) | ||
return sys.monitoring.DISABLE | ||
|
||
def line(code, line_number): | ||
coverage.get(code.co_filename)[line_number] = True | ||
return sys.monitoring.DISABLE | ||
|
||
sys.monitoring.register_callback(sys.monitoring.COVERAGE_ID, sys.monitoring.events.PY_START, start) | ||
sys.monitoring.register_callback(sys.monitoring.COVERAGE_ID, sys.monitoring.events.LINE, line) | ||
sys.monitoring.use_tool_id(sys.monitoring.COVERAGE_ID, 'test') | ||
sys.monitoring.set_events(sys.monitoring.COVERAGE_ID, sys.monitoring.events.PY_START) | ||
|
||
loader = unittest.TestLoader() | ||
#suite = loader.discover('tests') | ||
suite = loader.loadTestsFromName('tests.test_unit') | ||
runner = unittest.TextTestRunner(buffer=True) | ||
runner.run(suite) | ||
|
||
coverage = {file_name[len(source) - 7:]: file_coverage for file_name, file_coverage in coverage.items()} | ||
cov_dir = (Path() / 'target' / 'coverage') | ||
cov_dir.mkdir(parents=True, exist_ok=True) | ||
cov_file = cov_dir / ((os.environ.get('GITHUB_JOB', '') or 'coverage') + '.json') | ||
with cov_file.open('w') as f: | ||
json.dump(coverage, f) |