Skip to content
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

Merge EditableReport into Report #549

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Swatinem
Copy link
Contributor

The primary usecase for EditableReport was to always keep a list of "partially parsed" ReportFiles around, as well as making sure that totals (and to some extent file_totals) are uptodate.

This now moves all the methods from EditableReport onto Report, and introduces a new method to iterate over "partially parsed" ReportFiles, making sure those are being kept around as well.


Part of codecov/engineering-team#3381, and built on top of #548.

@Swatinem Swatinem requested a review from a team February 27, 2025 14:17
@Swatinem Swatinem self-assigned this Feb 27, 2025
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 90.66667% with 7 lines in your changes missing coverage. Please review.

Project coverage is 88.52%. Comparing base (bc3e338) to head (395cbee).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
shared/reports/resources.py 90.41% 2 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #549      +/-   ##
==========================================
+ Coverage   88.50%   88.52%   +0.01%     
==========================================
  Files         451      451              
  Lines       13107    13094      -13     
  Branches     1528     1524       -4     
==========================================
- Hits        11600    11591       -9     
+ Misses       1184     1183       -1     
+ Partials      323      320       -3     
Flag Coverage Δ
shared-docker-uploader 88.52% <90.66%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-staging
Copy link

codecov-staging bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 90.66667% with 7 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
shared/reports/resources.py 90.41% 2 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Feb 27, 2025

❌ 22 Tests Failed:

Tests completed Failed Passed Skipped
1638 22 1616 1
View the top 3 failed test(s) by shortest run time
tests/unit/reports/test_editable.py::TestEditableReportHelpers::test_delete_labels_session_without_datapoints
Stack Traces | 0.002s run time
self = <test_editable.TestEditableReportHelpers object at 0x7f537b72f980>

    def test_delete_labels_session_without_datapoints(self):
        line = ReportLine.create(
            1,
            None,
            [LineSession(0, 1), LineSession(1, 1), LineSession(2, 0)],
            datapoints=[
                CoverageDatapoint(1, 1, None, [5, 6]),
                CoverageDatapoint(1, 0, None, [7, 6]),
                CoverageDatapoint(2, 0, None, [10]),
            ],
        )
>       assert EditableReportFile.line_without_labels(
            line, [1], [5, 6, 10]
        ) == ReportLine.create(
            1,
            None,
            [LineSession(0, 1), LineSession(2, 0)],
            datapoints=[CoverageDatapoint(2, 0, None, [10])],
        )

.../unit/reports/test_editable.py:219: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'shared.reports.resources.ReportFile'>
line = ReportLine(coverage=1, type=None, sessions=[LineSession(id=0, coverage=1, branches=None, partials=None, complexity=Non...coverage_type=None, label_ids=[7, 6]), CoverageDatapoint(sessionid=2, coverage=0, coverage_type=None, label_ids=[10])])
session_ids_to_delete = [1], label_ids_to_delete = [5, 6, 10]

    @classmethod
    def line_without_labels(
        cls, line, session_ids_to_delete: set[int], label_ids_to_delete: set[int]
    ):
        new_datapoints = (
            [
                dp
                for dp in line.datapoints
                if dp.sessionid not in session_ids_to_delete
                or all(lb not in label_ids_to_delete for lb in dp.label_ids)
            ]
            if line.datapoints is not None
            else None
        )
        remaining_session_ids = set(dp.sessionid for dp in new_datapoints)
>       removed_session_ids = session_ids_to_delete - remaining_session_ids
E       TypeError: unsupported operand type(s) for -: 'list' and 'set'

shared/reports/resources.py:434: TypeError
tests/unit/reports/test_editable.py::TestEditableReportHelpers::test_line_without_labels
Stack Traces | 0.002s run time
self = <test_editable.TestEditableReportHelpers object at 0x7f537b72e000>

    def test_line_without_labels(self):
        line = ReportLine.create(
            "2/2",
            None,
            [LineSession(1, 0), LineSession(0, 1)],
            datapoints=[
                CoverageDatapoint(1, 0, None, [5, 6]),
                CoverageDatapoint(1, 0, None, [7, 6]),
                CoverageDatapoint(0, 1, None, [5, 6]),
                CoverageDatapoint(0, "1/2", None, [5, 8]),
                CoverageDatapoint(0, "1/2", None, [9, 10]),
                CoverageDatapoint(0, 0, None, [10, 8]),
            ],
        )
>       assert EditableReportFile.line_without_labels(
            line, [1], [5]
        ) == ReportLine.create(
            "2/2",
            None,
            [LineSession(1, 0), LineSession(0, 1)],
            datapoints=[
                CoverageDatapoint(1, 0, None, [7, 6]),
                CoverageDatapoint(0, 1, None, [5, 6]),
                CoverageDatapoint(0, "1/2", None, [5, 8]),
                CoverageDatapoint(0, "1/2", None, [9, 10]),
                CoverageDatapoint(0, 0, None, [10, 8]),
            ],
        )

.../unit/reports/test_editable.py:145: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'shared.reports.resources.ReportFile'>
line = ReportLine(coverage='2/2', type=None, sessions=[LineSession(id=1, coverage=0, branches=None, partials=None, complexity...rage_type=None, label_ids=[9, 10]), CoverageDatapoint(sessionid=0, coverage=0, coverage_type=None, label_ids=[10, 8])])
session_ids_to_delete = [1], label_ids_to_delete = [5]

    @classmethod
    def line_without_labels(
        cls, line, session_ids_to_delete: set[int], label_ids_to_delete: set[int]
    ):
        new_datapoints = (
            [
                dp
                for dp in line.datapoints
                if dp.sessionid not in session_ids_to_delete
                or all(lb not in label_ids_to_delete for lb in dp.label_ids)
            ]
            if line.datapoints is not None
            else None
        )
        remaining_session_ids = set(dp.sessionid for dp in new_datapoints)
>       removed_session_ids = session_ids_to_delete - remaining_session_ids
E       TypeError: unsupported operand type(s) for -: 'list' and 'set'

shared/reports/resources.py:434: TypeError
tests/unit/test_report.py::test_encode_chunk[chunk1-{}\n]
Stack Traces | 0.002s run time
chunk = <ReportFile name=name.ply lines=0>, res = '{}\n'

    @pytest.mark.unit
    @pytest.mark.parametrize(
        "chunk, res",
        [
            (None, "null"),
            (ReportFile(name="name.ply"), "{}\n"),
            (
                [ReportLine.create(2), ReportLine.create(1)],
                "[[2,null,null,null,null,null],[1,null,null,null,null,null]]",
            ),
        ],
    )
    def test_encode_chunk(chunk, res):
>       assert _encode_chunk(chunk) == res
E       assert '{"present_sessions":[]}\n' == '{}\n'
E         
E         - {}
E         + {"present_sessions":[]}

tests/unit/test_report.py:938: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link

codspeed-hq bot commented Feb 27, 2025

CodSpeed Performance Report

Merging #549 will create unknown performance changes

Comparing swatinem/no-editablereport (395cbee) with main (bc3e338)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.\

Copy link

❌ 22 Tests Failed:

Tests completed Failed Passed Skipped
1638 22 1616 1
View the top 3 failed tests by shortest run time
tests/integration/test_report_file.py::::test_encode[r1-null\n[1]\n[2]]
Stack Traces | 0.002s run time
r = <ReportFile name=name.py lines=2>, encoded_val = 'null\n[1]\n[2]'

    @pytest.mark.integration
    @pytest.mark.parametrize(
        "r, encoded_val",
        [
            (ReportFile("name.py"), "{}\n"),
            (
                ReportFile("name.py", lines=[ReportLine.create(1), ReportLine.create(2)]),
                "null\n[1]\n[2]",
            ),
        ],
    )
    def test_encode(r, encoded_val):
>       assert r._encode() == encoded_val

tests/integration/test_report_file.py:370: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
shared/reports/resources.py:145: in _encode
    details = orjson.dumps(self.details, option=orjson_option)
shared/reports/resources.py:132: in details
    self._details["present_sessions"] = sorted(self._present_sessions)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ReportFile name=name.py lines=2>

    @property
    def _present_sessions(self):
        if self.__present_sessions is None:
            self.__present_sessions = set()
            for _, line in self.lines:
>               self.__present_sessions.update(int(s.id) for s in line.sessions)
E               TypeError: 'NoneType' object is not iterable

shared/reports/resources.py:127: TypeError
tests/unit/reports/test_editable.py::TestEditableReport::test_init
Stack Traces | 0.002s run time
self = <test_editable.TestEditableReport object at 0x7f537b77ec00>

    def test_init(self):
        with open(current_file.parent / "samples" / "chunks_01.txt", "r") as f:
            chunks = f.read()
        files_dict = {
            "awesome/__init__.py": [
                2,
                [0, 10, 8, 2, 0, "80.00000", 0, 0, 0, 0, 0, 0, 0],
                [[0, 10, 8, 2, 0, "80.00000", 0, 0, 0, 0, 0, 0, 0]],
                [0, 2, 1, 1, 0, "50.00000", 0, 0, 0, 0, 0, 0, 0],
            ],
            "tests/__init__.py": [
                0,
                [0, 3, 2, 1, 0, "66.66667", 0, 0, 0, 0, 0, 0, 0],
                [[0, 3, 2, 1, 0, "66.66667", 0, 0, 0, 0, 0, 0, 0]],
                None,
            ],
            "tests/test_sample.py": [
                1,
                [0, 7, 7, 0, 0, "100", 0, 0, 0, 0, 0, 0, 0],
                [[0, 7, 7, 0, 0, "100", 0, 0, 0, 0, 0, 0, 0]],
                None,
            ],
        }
        sessions_dict = {
            "0": {
                "N": None,
                "a": ".../4434BC2A2EC4FCA57F77B473D83F928C/abf6d4df662c47e32460020ab14abf9303581429/9ccc55a1-8b41-4bb1-a946-ee7a33a7fb56.txt",
                "c": None,
                "d": 1547084427,
                "e": None,
                "f": ["unit"],
                "j": None,
                "n": None,
                "p": None,
                "t": [3, 20, 17, 3, 0, "85.00000", 0, 0, 0, 0, 0, 0, 0],
                "": None,
            }
        }
        report = EditableReport(chunks=chunks, files=files_dict, sessions=sessions_dict)
        assert report._files == {
            "awesome/__init__.py": ReportFileSummary(
                2,
                [0, 10, 8, 2, 0, "80.00000", 0, 0, 0, 0, 0, 0, 0],
                [0, 2, 1, 1, 0, "50.00000", 0, 0, 0, 0, 0, 0, 0],
            ),
            "tests/__init__.py": ReportFileSummary(
                0,
                [0, 3, 2, 1, 0, "66.66667", 0, 0, 0, 0, 0, 0, 0],
                None,
            ),
            "tests/test_sample.py": ReportFileSummary(
                1,
                [0, 7, 7, 0, 0, "100", 0, 0, 0, 0, 0, 0, 0],
                None,
            ),
        }
>       assert all(
            (isinstance(x, EditableReportFile) or x is None) for x in report._chunks
        )
E       assert False
E        +  where False = all(<generator object TestEditableReport.test_init.<locals>.<genexpr> at 0x7f537823fd80>)

.../unit/reports/test_editable.py:1196: AssertionError
tests/unit/test_report.py::::test_encode_chunk[chunk1-{}\n]
Stack Traces | 0.002s run time
chunk = <ReportFile name=name.ply lines=0>, res = '{}\n'

    @pytest.mark.unit
    @pytest.mark.parametrize(
        "chunk, res",
        [
            (None, "null"),
            (ReportFile(name="name.ply"), "{}\n"),
            (
                [ReportLine.create(2), ReportLine.create(1)],
                "[[2,null,null,null,null,null],[1,null,null,null,null,null]]",
            ),
        ],
    )
    def test_encode_chunk(chunk, res):
>       assert _encode_chunk(chunk) == res
E       assert '{"present_sessions":[]}\n' == '{}\n'
E         
E         - {}
E         + {"present_sessions":[]}

tests/unit/test_report.py:938: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@Swatinem Swatinem force-pushed the swatinem/no-editablefile branch from 676f04d to 4f96ce2 Compare February 28, 2025 09:39
@Swatinem Swatinem force-pushed the swatinem/no-editablereport branch from 3b3bf9c to fdd778f Compare February 28, 2025 09:48
Base automatically changed from swatinem/no-editablefile to main February 28, 2025 10:40
The primary usecase for `EditableReport` was to always keep a list of "partially parsed" `ReportFile`s around, as well as making sure that `totals` (and to some extent `file_totals`) are uptodate.

This now moves all the methods from `EditableReport` onto `Report`, and introduces a new method to iterate over "partially parsed" `ReportFile`s, making sure those are being kept around as well.
@Swatinem Swatinem force-pushed the swatinem/no-editablereport branch from fdd778f to 395cbee Compare February 28, 2025 10:40
@Swatinem Swatinem marked this pull request as ready for review February 28, 2025 10:41
]

EDITABLE_VARIANTS = [Report, EditableReport]
EDITABLE_VARIANTS = [Report]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it'd be nice to hardcode this instead of parametrize, since there should only be one variant going forward

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants