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

selftests/unit/utils/cpu.py: support the context manager pattern #6056

Conversation

clebergnu
Copy link
Contributor

The current mock method on the two tests modified here do not support the context manager pattern. Let's use the standard library support for mocking open that supports it.

This is needed for future lint check improvements that will enforce the use of open() as a context manager to avoid leaking resources.

The test_set_idle_state_withsetstate() test has a significant change of behavior: one io.BytesIO instance was used for the writes that, in real life, would happen on two different files. The proposed change brings a more realistic, with a single write to a single file (although it only checks half of the values now). Still, I believe this is an improvement, including the extra check for the file that was actually written to.

Reference: https://docs.python.org/3/library/unittest.mock.html#mock-open

The current mock method on the two tests modified here do not support
the context manager pattern.  Let's use the standard library support
for mocking open that supports it.

This is needed for future lint check improvements that will enforce
the use of open() as a context manager to avoid leaking resources.

The test_set_idle_state_withsetstate() test has a significant change
of behavior: one io.BytesIO instance was used for the writes that, in
real life, would happen on two different files.  The proposed change
brings a more realistic, with a single write to a single
file (although it only checks half of the values now).  Still, I
believe this is an improvement, including the extra check for the file
that was actually written to.

Reference: https://docs.python.org/3/library/unittest.mock.html#mock-open
Signed-off-by: Cleber Rosa <[email protected]>
@clebergnu clebergnu added this to the 109 - Codename TBD milestone Oct 29, 2024
@clebergnu clebergnu self-assigned this Oct 29, 2024
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.45%. Comparing base (fe11714) to head (bf9b3d5).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6056      +/-   ##
==========================================
- Coverage   54.48%   54.45%   -0.04%     
==========================================
  Files         202      202              
  Lines       21885    21885              
==========================================
- Hits        11925    11917       -8     
- Misses       9960     9968       +8     

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

Copy link
Contributor

@richtja richtja left a comment

Choose a reason for hiding this comment

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

Hi @clebergnu, LGTM, thanks

@richtja richtja merged commit 12863df into avocado-framework:master Oct 30, 2024
60 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done 109
Development

Successfully merging this pull request may close these issues.

2 participants