diff options
| author | Alex Manuskin <amanusk@protonmail.com> | 2018-10-01 15:50:04 +0300 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-10-01 14:50:04 +0200 |
| commit | 13ef73cd5c41155b6cb6cd5b51cd5d6c100b4d47 (patch) | |
| tree | e60a49495c199aecd56c563b10f42e831b10216c /psutil/tests/test_linux.py | |
| parent | 1d7516c10cc89c60b8b5607ff9656d2f817b22b1 (diff) | |
| download | psutil-13ef73cd5c41155b6cb6cd5b51cd5d6c100b4d47.tar.gz | |
Add parsing for /sys/class/thermal (#1345)
Add parsing for /sys/class/thermal
Diffstat (limited to 'psutil/tests/test_linux.py')
| -rwxr-xr-x | psutil/tests/test_linux.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index a0527851..c565f6c2 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -1466,6 +1466,8 @@ class TestSensorsTemperatures(unittest.TestCase): def open_mock(name, *args, **kwargs): if name.endswith("_input"): raise OSError(errno.EIO, "") + elif name.endswith("temp"): + raise OSError(errno.EIO, "") else: return orig_open(name, *args, **kwargs) @@ -1477,7 +1479,7 @@ class TestSensorsTemperatures(unittest.TestCase): assert m.called self.assertIn("ignoring", str(ws[0].message)) - def test_emulate_data(self): + def test_emulate_class_hwmon(self): def open_mock(name, *args, **kwargs): if name.endswith('/name'): return io.StringIO(u("name")) @@ -1495,6 +1497,7 @@ class TestSensorsTemperatures(unittest.TestCase): 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 +1506,41 @@ class TestSensorsTemperatures(unittest.TestCase): self.assertEqual(temp.high, 40.0) self.assertEqual(temp.critical, 50.0) + def test_emulate_class_thermal(self): + def open_mock(name, *args, **kwargs): + if 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): + + 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): |
