Skip to content

Test create stats report #2170

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

Merged
merged 1 commit into from
May 9, 2025
Merged

Test create stats report #2170

merged 1 commit into from
May 9, 2025

Conversation

VindeeR
Copy link
Contributor

@VindeeR VindeeR commented Mar 3, 2025

Create a test case for the function create_stats_report asserting if functions is creating files properly with the information from the jobs

@VindeeR VindeeR self-assigned this Mar 3, 2025
@VindeeR VindeeR added the enhancement New feature or request label Mar 3, 2025
@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.36%. Comparing base (2d3e90a) to head (0d764a5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2170      +/-   ##
==========================================
+ Coverage   56.87%   57.36%   +0.48%     
==========================================
  Files          73       73              
  Lines       17351    17351              
  Branches     3368     3368              
==========================================
+ Hits         9869     9954      +85     
+ Misses       6625     6529      -96     
- Partials      857      868      +11     
Flag Coverage Δ
fast-tests 57.36% <ø> (+0.48%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@VindeeR VindeeR requested a review from isimo00 March 3, 2025 15:46
@kinow
Copy link
Member

kinow commented Mar 5, 2025

Git conflicts ☝️

import datetime
from pathlib import Path

from mock.mock import patch
Copy link
Member

Choose a reason for hiding this comment

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

tepmfile and patch can be replaced by the built-in fixtures that come with pytest: https://docs.pytest.org/en/6.2.x/fixture.html#pytest-fixtures-explicit-modular-scalable

For tempfile there's tmp_path which returns a Path already for you (I think you may not need to import Path` here, maybe.

And for patch, the pytest_mock lib we use has mocker, https://pytest-mock.readthedocs.io/en/latest/usage.html

Both work the same, but with pytest fixture the code is a bit shorter (one of the main selling points of pytest over unittest was to write less to have the same -- no classes, just functions, no need to import a lot of things, just use fixtures, etc...)

Copy link
Member

Choose a reason for hiding this comment

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

I've recently written a few tests for stats and monitor in #2322 , and there you can see the mocker.patch fixture being used.

jobs_by_association.return_value = [JobData(),JobAggData()]
create_status = diagram.create_stats_report(expid, jobs_data, {}, temp_dir,True,True,False,None,
None,None)
assert create_status is False
Copy link
Member

Choose a reason for hiding this comment

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

😆 this is not really fair. This is the function you mentioned that receives a bool and returns that same bool. So this test will pass whether we break the create_stats_report or not (the focus when writing tests must be to prevent bugs, not only coverage).

I think a better test would be one that either produces a plot somewhere in a temp dir, and then we assert the plot was created, has more than 0 bytes, and maybe that's that. Or then mock just the matplotlib part, and confirm the mock was called as expected.

Copy link
Contributor

@isimo00 isimo00 left a comment

Choose a reason for hiding this comment

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

I agree with Bruno's review and haven't seen anything else worth mentioning :)

@isimo00
Copy link
Contributor

isimo00 commented Apr 30, 2025

This just popped up again in my Github notifications because @kinow commented so I apologize for the random "review", but please @VindeeR could you expand the description of the PR (and link any issue that is being fixed by these changes, if any)? Thanks!

@VindeeR
Copy link
Contributor Author

VindeeR commented May 5, 2025

Waiting for approval of the issue #2169 to refine this issue

@VindeeR VindeeR requested a review from kinow May 6, 2025 15:16
Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

Remove CSV, use pytest-mock, and figure out what's creating the CSV file. Otherwise, looks good. Will approve once these tests are updated and GH Actions is passing.

@VindeeR VindeeR force-pushed the test_create_stats_report branch 5 times, most recently from 1e75b9b to a73db24 Compare May 8, 2025 13:15
@VindeeR VindeeR requested a review from kinow May 8, 2025 13:20
@VindeeR VindeeR force-pushed the test_create_stats_report branch 4 times, most recently from c3258ed to 9770e67 Compare May 9, 2025 08:42
@VindeeR VindeeR force-pushed the test_create_stats_report branch from 9770e67 to 0d764a5 Compare May 9, 2025 08:44
@VindeeR
Copy link
Contributor Author

VindeeR commented May 9, 2025

@kinow I used the new fixture to develop the test and a bit of tidiness of the code too

Thanks for the master class yesterday, I'm not sure I would manage this branch this easily without it ❤️

Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

💥

@kinow
Copy link
Member

kinow commented May 9, 2025

@kinow I used the new fixture to develop the test and a bit of tidiness of the code too

Thanks for the master class yesterday, I'm not sure I would manage this branch this easily without it ❤️

It was fun!!! Thanks for the different Thursday!

@kinow kinow added this to the 4.1.15 milestone May 9, 2025
@VindeeR VindeeR merged commit cce0758 into master May 9, 2025
16 checks passed
@VindeeR VindeeR deleted the test_create_stats_report branch May 9, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants