-
Notifications
You must be signed in to change notification settings - Fork 4
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
Test create stats report #2170
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Git conflicts ☝️ |
test/unit/test_diagram.py
Outdated
import datetime | ||
from pathlib import Path | ||
|
||
from mock.mock import patch |
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.
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...)
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've recently written a few tests for stats
and monitor
in #2322 , and there you can see the mocker.patch
fixture being used.
test/unit/test_diagram.py
Outdated
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 |
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.
😆 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.
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 agree with Bruno's review and haven't seen anything else worth mentioning :)
Waiting for approval of the issue #2169 to refine this issue |
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.
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.
1e75b9b
to
a73db24
Compare
c3258ed
to
9770e67
Compare
…g to ensure it works as intended
9770e67
to
0d764a5
Compare
@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 ❤️ |
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.
💥
It was fun!!! Thanks for the different Thursday! |
Create a test case for the function create_stats_report asserting if functions is creating files properly with the information from the jobs