-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add parsing for /sys/class/thermal #1345
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0f367e9
Add parsing for /sys/class/thermal
amanusk fcbda4b
Remove a loop when obtaining the base filenames of trippoints
amanusk 59c5bc4
Change Fallback to fallback
amanusk b83e5de
Add test for sensors_temperature
amanusk b004c11
Split tests for class/hwmon, class/thermal
amanusk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1466,6 +1466,8 @@ def test_emulate_eio_error(self): | |
def open_mock(name, *args, **kwargs): | ||
if name.endswith("_input"): | ||
raise OSError(errno.EIO, "") | ||
if name.endswith("temp"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
raise OSError(errno.EIO, "") | ||
else: | ||
return orig_open(name, *args, **kwargs) | ||
|
||
|
@@ -1489,12 +1491,33 @@ def open_mock(name, *args, **kwargs): | |
return io.BytesIO(b"40000") | ||
elif name.endswith('/temp1_crit'): | ||
return io.BytesIO(b"50000") | ||
# Files found in /sys/class/thermal/ | ||
elif name.endswith('0_temp'): | ||
return io.BytesIO(b"50000") | ||
elif name.endswith('temp'): | ||
return io.BytesIO(b"30000") | ||
elif name.endswith('0_type'): | ||
return io.StringIO(u("critical")) | ||
elif name.endswith('type'): | ||
return io.StringIO(u("name")) | ||
else: | ||
return orig_open(name, *args, **kwargs) | ||
|
||
def glob_mock(path): | ||
if path == '/sys/class/hwmon/hwmon*/temp*_*': | ||
return [] | ||
elif path == '/sys/class/hwmon/hwmon*/device/temp*_*': | ||
return [] | ||
elif path == '/sys/class/thermal/thermal_zone*': | ||
return ['/sys/class/thermal/thermal_zone0'] | ||
elif path == '/sys/class/thermal/thermal_zone0/trip_point*': | ||
return ['/sys/class/thermal/thermal_zone1/trip_point_0_type', | ||
'/sys/class/thermal/thermal_zone1/trip_point_0_temp'] | ||
|
||
orig_open = open | ||
patch_point = 'builtins.open' if PY3 else '__builtin__.open' | ||
with mock.patch(patch_point, side_effect=open_mock): | ||
# Test case with /sys/class/hwmon | ||
with mock.patch('glob.glob', | ||
return_value=['/sys/class/hwmon/hwmon0/temp1']): | ||
temp = psutil.sensors_temperatures()['name'][0] | ||
|
@@ -1503,6 +1526,14 @@ def open_mock(name, *args, **kwargs): | |
self.assertEqual(temp.high, 40.0) | ||
self.assertEqual(temp.critical, 50.0) | ||
|
||
# Test case with only /sys/class/thermal | ||
with mock.patch('glob.glob', create=True, side_effect=glob_mock): | ||
temp = psutil.sensors_temperatures()['name'][0] | ||
self.assertEqual(temp.label, '') | ||
self.assertEqual(temp.current, 30.0) | ||
self.assertEqual(temp.high, 50.0) | ||
self.assertEqual(temp.critical, 50.0) | ||
|
||
|
||
@unittest.skipIf(not LINUX, "LINUX only") | ||
class TestSensorsFans(unittest.TestCase): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Squashed 2 for loops into one