avocado-framework / avocado

Avocado is a set of tools and libraries to help with automated testing. One can call it a test framework with benefits. Native tests are written in Python and they follow the unittest pattern, but any executable can serve as a test.
https://avocado-framework.github.io/
Other
345 stars 343 forks source link

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

Closed clebergnu closed 3 weeks ago

clebergnu commented 3 weeks ago

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

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.