-
Notifications
You must be signed in to change notification settings - Fork 45
Add phorge-json format #188
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,28 @@ def generate(self): | |
| ) | ||
|
|
||
|
|
||
| class PhorgeJsonReporter(Reporter): | ||
| """ | ||
| A reporter that outputs a JSON object in the Phorge/Phabricator | ||
| coverage format. It is required to have the source files available. | ||
| """ | ||
|
|
||
| def generate_one(self, filename): | ||
| statuses = self.cobertura.line_statuses(filename) | ||
| with self.cobertura.filesystem.open(filename) as f: | ||
| lines = ["N" for _ in f] | ||
| for lineNum, covered in statuses: | ||
| lines[lineNum - 1] = "C" if covered else "U" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a long overdue PR that will introduce partially covered lines. Is there a character you'd like to use when I merge this PR eventually?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per phorge docs, it does not support partially covered lines. A line can only be set to covered, uncovered, not executable, or unreachable. |
||
| return "".join(lines) | ||
|
|
||
| def generate(self): | ||
| filenames = self.cobertura.files(ignore_regex=self.ignore_regex) | ||
| res = {} | ||
| for filename in filenames: | ||
| res[filename] = self.generate_one(filename) | ||
| return json.dumps(res, indent=4) | ||
|
|
||
|
|
||
| class DeltaReporter: | ||
| def __init__( | ||
| self, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -810,3 +810,41 @@ def test_delta_reporter__single_file_coverage_changed(): | |
| "Cover": "+16.67%" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| def test_phorge_json_reporter(): | ||
| from pycobertura.reporters import PhorgeJsonReporter | ||
|
|
||
| cobertura = make_cobertura('tests/dummy.source1/coverage.xml') | ||
| report = PhorgeJsonReporter(cobertura) | ||
|
|
||
| assert report.generate() == """\ | ||
| { | ||
| "dummy/__init__.py": "", | ||
| "dummy/dummy.py": "CCNCUU", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is N?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is described in https://we.phorge.it/book/phorge/article/arcanist_coverage/#building-coverage-support (I have put this link into README): N means "not executable"; C means "covered" and "U" means "not covered" |
||
| "dummy/dummy2.py": "CC", | ||
| "dummy/dummy4.py": "UUNUUU" | ||
| }""" | ||
|
|
||
|
|
||
| def test_phorge_json_reporter__no_source(): | ||
| """ | ||
| This checks that if a file is not found, the PhorgeJsonReporter | ||
| always raises an exception. This is because the phorge-json | ||
| format only wants coverage information for each line, and this | ||
| does not make sense if a source file is not found. | ||
| """ | ||
| from pycobertura.reporters import PhorgeJsonReporter | ||
| import pycobertura.filesystem | ||
|
|
||
| cobertura = make_cobertura('tests/cobertura.xml') | ||
| report = PhorgeJsonReporter(cobertura) | ||
|
|
||
| exception = None | ||
|
|
||
| try: | ||
| report.generate() | ||
| except pycobertura.filesystem.FileSystem.FileNotFound as e: | ||
| exception = e | ||
|
|
||
| assert exception is not None | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we do something like
["N"] * len(f)? On my phone now so I can't test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, as the file handle is not an array at all.