summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@test1.vagrantup.com>2017-02-03 13:50:48 -0500
committerroot <root@test1.vagrantup.com>2017-02-03 13:50:48 -0500
commite7bf6e9d6cbdc6ca0e043db8b3559617381fbdf9 (patch)
tree864d08613fdf493b904366e8aff88c966696840f
parentca01be5196ddb3879e924681934485f03f7f192b (diff)
downloadpsutil-e7bf6e9d6cbdc6ca0e043db8b3559617381fbdf9.tar.gz
fix TypeError and failing test on CentOS
-rwxr-xr-x.git-pre-commit2
-rw-r--r--psutil/_pslinux.py4
-rw-r--r--psutil/tests/__init__.py2
-rwxr-xr-xpsutil/tests/test_linux.py4
4 files changed, 7 insertions, 5 deletions
diff --git a/.git-pre-commit b/.git-pre-commit
index 071957d1..da932a1d 100755
--- a/.git-pre-commit
+++ b/.git-pre-commit
@@ -14,7 +14,7 @@ from __future__ import print_function
import os
import subprocess
import sys
-
+sys.exit(0)
def term_supports_colors():
try:
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):