summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-02-03 20:11:50 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-02-03 20:11:50 +0100
commit4d219e1349187553245c9ec57d9a2fb6923d601e (patch)
tree9262caa517f34ae51cbf8fdd39d0c4e6defd05fc
parentbb3cc6035bccc04dea7f98ce5e0bba113cb677ac (diff)
parent0db4ec677d0812a63bdc841558077c36a96412f3 (diff)
downloadpsutil-4d219e1349187553245c9ec57d9a2fb6923d601e.tar.gz
Merge branch 'master' of github.com:giampaolo/psutilrelease-5.1.2
-rw-r--r--psutil/_pslinux.py4
-rw-r--r--psutil/tests/__init__.py2
-rwxr-xr-xpsutil/tests/test_linux.py4
3 files changed, 6 insertions, 4 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index beddb8b6..8fc0bb6d 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1143,8 +1143,8 @@ def sensors_battery():
except ZeroDivisionError:
percent = 0.0
else:
- percent = int(cat(root + "/capacity", fallback=null))
- if percent == null:
+ percent = int(cat(root + "/capacity", fallback=-1))
+ if percent == -1:
return None
# Is AC power cable plugged in?
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index b119a788..13c4cfca 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -199,7 +199,7 @@ def get_test_subprocess(cmd=None, **kwds):
kwds.setdefault("stdin", DEVNULL)
kwds.setdefault("stdout", DEVNULL)
if cmd is None:
- assert not os.path.exists(_TESTFN)
+ safe_rmpath(_TESTFN)
pyline = "from time import sleep;"
pyline += "open(r'%s', 'w').close();" % _TESTFN
pyline += "sleep(60)"
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 3e55d32e..5db4c309 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -1119,13 +1119,15 @@ class TestSensorsBattery(unittest.TestCase):
def open_mock(name, *args, **kwargs):
if name.startswith("/sys/class/power_supply/BAT0/energy_full"):
raise IOError(errno.ENOENT, "")
+ elif name.startswith("/sys/class/power_supply/BAT0/capacity"):
+ return io.BytesIO(b"88")
else:
return orig_open(name, *args, **kwargs)
orig_open = open
patch_point = 'builtins.open' if PY3 else '__builtin__.open'
with mock.patch(patch_point, side_effect=open_mock) as m:
- self.assertGreaterEqual(psutil.sensors_battery().percent, 0)
+ self.assertEqual(psutil.sensors_battery().percent, 88)
assert m.called
def test_emulate_no_ac0_online(self):