-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: count difference of uploaded sessions
ticket: codecov/engineering-team#1622 These changes introduce a new capabiliy to `ComparisonProxy`. Namely, to get the difference in the number of uploads reported per flag between HEAD and BASE. The idea is to be able to give more actionable message in the PR comment on the following scenario: 1. I have uploaded 5 reports to my base commit 2. I upload 1 report to head commit 3. I have NOT covered all lines of my patch 4. I'm seeing project coverage go WAY down Because typically coverage is uploaded via CI, and CI doesn't change often, a different number of reports present could indicate issues in the coverage results. We have to ignore carryforward sessions because different commits might upload different sets of reports. There are 2 functions so that we can also get the _total_ number of reports uploaded per flag, not only the diff
- Loading branch information
1 parent
242e1a0
commit 6c87069
Showing
3 changed files
with
244 additions
and
3 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
173 changes: 173 additions & 0 deletions
173
services/comparison/tests/unit/test_reports_uploaded_count_diff.py
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,173 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from shared.reports.resources import Report | ||
from shared.utils.sessions import Session, SessionType | ||
|
||
from services.comparison import ComparisonProxy | ||
from services.comparison.types import Comparison, FullCommit, ReportUploadedCount | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"head_sessions, base_sessions, expected", | ||
[ | ||
( | ||
[ | ||
Session( | ||
flags=["unit", "local"], session_type=SessionType.carriedforward | ||
), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=[], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
Session( | ||
flags=["unit", "local"], session_type=SessionType.carriedforward | ||
), | ||
Session(flags=["integration"], session_type=SessionType.carriedforward), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
ReportUploadedCount(flag="unit", base_count=2, head_count=2), | ||
ReportUploadedCount(flag="integration", base_count=0, head_count=2), | ||
ReportUploadedCount(flag="", base_count=0, head_count=1), | ||
], | ||
), | ||
( | ||
[ | ||
Session( | ||
flags=["unit", "local"], session_type=SessionType.carriedforward | ||
), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
Session(flags=["unit", "local"], session_type=SessionType.uploaded), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["obscure_flag"], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
ReportUploadedCount(flag="unit", base_count=3, head_count=2), | ||
ReportUploadedCount(flag="local", base_count=1, head_count=0), | ||
ReportUploadedCount(flag="integration", base_count=1, head_count=2), | ||
ReportUploadedCount(flag="obscure_flag", base_count=1, head_count=0), | ||
], | ||
), | ||
], | ||
) | ||
def test_get_reports_uploaded_count_per_flag(head_sessions, base_sessions, expected): | ||
head_report = Report() | ||
head_report.sessions = head_sessions | ||
base_report = Report() | ||
base_report.sessions = base_sessions | ||
comparison_proxy = ComparisonProxy( | ||
comparison=Comparison( | ||
head=FullCommit(report=head_report, commit=None), | ||
project_coverage_base=FullCommit(report=base_report, commit=None), | ||
patch_coverage_base_commitid=None, | ||
enriched_pull=None, | ||
) | ||
) | ||
# Python Dicts preserve order, so we can actually test this equality | ||
# See more https://stackoverflow.com/a/39537308 | ||
assert comparison_proxy.get_reports_uploaded_count_per_flag() == expected | ||
|
||
|
||
def test_get_reports_uploaded_count_per_flag_cached(): | ||
comparison_proxy = ComparisonProxy(comparison=MagicMock(name="fake_comparison")) | ||
comparison_proxy._cached_reports_uploaded_per_flag = ( | ||
"object_that_doesnt_have_this_shape" | ||
) | ||
assert ( | ||
comparison_proxy.get_reports_uploaded_count_per_flag() | ||
== "object_that_doesnt_have_this_shape" | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"head_sessions, base_sessions, expected_diff", | ||
[ | ||
( | ||
[ | ||
Session( | ||
flags=["unit", "local"], session_type=SessionType.carriedforward | ||
), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
Session( | ||
flags=["unit", "local"], session_type=SessionType.carriedforward | ||
), | ||
Session(flags=["integration"], session_type=SessionType.carriedforward), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
], | ||
[], | ||
), | ||
( | ||
[ | ||
Session( | ||
flags=["unit", "local"], session_type=SessionType.carriedforward | ||
), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
Session(flags=["unit", "local"], session_type=SessionType.uploaded), | ||
Session(flags=["integration"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["unit"], session_type=SessionType.uploaded), | ||
Session(flags=["obscure_flag"], session_type=SessionType.uploaded), | ||
], | ||
[ | ||
ReportUploadedCount(flag="unit", base_count=3, head_count=2), | ||
ReportUploadedCount(flag="integration", base_count=1, head_count=2), | ||
], | ||
), | ||
], | ||
) | ||
def test_get_reports_uploaded_count_per_flag_diff( | ||
head_sessions, base_sessions, expected_diff | ||
): | ||
head_report = Report() | ||
head_report.sessions = head_sessions | ||
base_report = Report() | ||
base_report.sessions = base_sessions | ||
comparison_proxy = ComparisonProxy( | ||
comparison=Comparison( | ||
head=FullCommit(report=head_report, commit=None), | ||
project_coverage_base=FullCommit(report=base_report, commit=None), | ||
patch_coverage_base_commitid=None, | ||
enriched_pull=None, | ||
) | ||
) | ||
# Python Dicts preserve order, so we can actually test this equality | ||
# See more https://stackoverflow.com/a/39537308 | ||
assert comparison_proxy.get_reports_uploaded_count_per_flag_diff() == expected_diff | ||
|
||
|
||
def test_get_reports_uploaded_count_per_flag_diff_missing_report(): | ||
head_report = None | ||
base_report = Report() | ||
base_report.sessions = None | ||
comparison_proxy = ComparisonProxy( | ||
comparison=Comparison( | ||
head=FullCommit(report=head_report, commit=None), | ||
project_coverage_base=FullCommit(report=base_report, commit=None), | ||
patch_coverage_base_commitid=None, | ||
enriched_pull=None, | ||
) | ||
) | ||
assert comparison_proxy.get_reports_uploaded_count_per_flag_diff() == [] |
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