diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-10-17 05:41:39 +0200 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-10-17 05:41:39 +0200 |
| commit | 958f18638cfee77e441f29fd54ab0f8c3af084ed (patch) | |
| tree | 4d15e40d6c74279b90f543f1e186efa53408dcc8 /psutil/tests | |
| parent | bfae1fc4a371c9e08f2c3f5053a80542e43d18f7 (diff) | |
| download | psutil-958f18638cfee77e441f29fd54ab0f8c3af084ed.tar.gz | |
add battery test; increase coverage
Diffstat (limited to 'psutil/tests')
| -rwxr-xr-x | psutil/tests/test_linux.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index b303ed6d..519d4b2e 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -1599,6 +1599,29 @@ class TestSensorsBattery(PsutilTestCase): @unittest.skipIf(not LINUX, "LINUX only") +class TestSensorsBatteryEmulated(PsutilTestCase): + + def test_it(self): + def open_mock(name, *args, **kwargs): + if name.endswith("/energy_now"): + return io.StringIO(u("60000000")) + elif name.endswith("/power_now"): + return io.StringIO(u("0")) + elif name.endswith("/energy_full"): + return io.StringIO(u("60000001")) + else: + return orig_open(name, *args, **kwargs) + + orig_open = open + patch_point = 'builtins.open' if PY3 else '__builtin__.open' + with mock.patch('os.listdir', return_value=["BAT0"]) as mlistdir: + with mock.patch(patch_point, side_effect=open_mock) as mopen: + self.assertIsNotNone(psutil.sensors_battery()) + assert mlistdir.called + assert mopen.called + + +@unittest.skipIf(not LINUX, "LINUX only") class TestSensorsTemperatures(PsutilTestCase): def test_emulate_class_hwmon(self): |
