summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-02-03 18:52:03 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-02-03 18:52:03 +0100
commit44ca122c1c7fc131ad7f6587203a5d8d97a4bb30 (patch)
tree17823f753a2e324caaa59c2f7c9fa9371b8d6832
parent941512903e8cf3e00c403427494500565094ef97 (diff)
downloadpsutil-44ca122c1c7fc131ad7f6587203a5d8d97a4bb30.tar.gz
fix #970 [Linux] sensors_battery()'s name and label fields on Python 3 are bytes
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/_pslinux.py5
-rwxr-xr-xpsutil/tests/test_system.py11
3 files changed, 15 insertions, 3 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 81798899..e5563348 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -8,6 +8,8 @@
**Bug fixes**
- 968_: [Linux] disk_io_counters() raises TypeError on python 3.
+- 970_: [Linux] sensors_battery()'s name and label fields on Python 3 are bytes
+ instead of str.
5.1.1
=====
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 902071c9..fdb48f96 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1082,8 +1082,9 @@ def sensors_temperatures():
[x.split('_')[0] for x in
glob.glob('/sys/class/hwmon/hwmon*/temp*_*')]))
for base in basenames:
- unit_name = cat(os.path.join(os.path.dirname(base), 'name'))
- label = cat(base + '_label', fallback='')
+ unit_name = cat(os.path.join(os.path.dirname(base), 'name'),
+ binary=False)
+ label = cat(base + '_label', fallback='', binary=False)
current = float(cat(base + '_input')) / 1000.0
high = cat(base + '_max', fallback=None)
critical = cat(base + '_crit', fallback=None)
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index 01648380..1c143f97 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -454,6 +454,10 @@ class TestSystemAPIs(unittest.TestCase):
# AssertionError: Lists differ: [0, 1, 2, 3, 4, 5, 6, 7,... != [0]
self.assertTrue(ls, msg=ls)
for disk in ls:
+ self.assertIsInstance(disk.device, (str, unicode))
+ self.assertIsInstance(disk.mountpoint, (str, unicode))
+ self.assertIsInstance(disk.fstype, (str, unicode))
+ self.assertIsInstance(disk.opts, (str, unicode))
if WINDOWS and 'cdrom' in disk.opts:
continue
if not POSIX:
@@ -468,7 +472,6 @@ class TestSystemAPIs(unittest.TestCase):
else:
assert os.path.isdir(disk.mountpoint), disk
assert disk.fstype, disk
- self.assertIsInstance(disk.opts, str)
# all = True
ls = psutil.disk_partitions(all=True)
@@ -512,6 +515,7 @@ class TestSystemAPIs(unittest.TestCase):
self.assertIn(conn.family, families, msg=conn)
if conn.family != getattr(socket, 'AF_UNIX', object()):
self.assertIn(conn.type, types_, msg=conn)
+ self.assertIsInstance(conn.status, (str, unicode))
from psutil._common import conn_tmap
for kind, groups in conn_tmap.items():
@@ -547,6 +551,7 @@ class TestSystemAPIs(unittest.TestCase):
self.assertNotEqual(ret, [])
for key in ret:
self.assertTrue(key)
+ self.assertIsInstance(key, (str, unicode))
check_ntuple(ret[key])
def test_net_if_addrs(self):
@@ -562,6 +567,7 @@ class TestSystemAPIs(unittest.TestCase):
families = set([socket.AF_INET, AF_INET6, psutil.AF_LINK])
for nic, addrs in nics.items():
+ self.assertIsInstance(nic, (str, unicode))
self.assertEqual(len(set(addrs)), len(addrs))
for addr in addrs:
self.assertIsInstance(addr.family, int)
@@ -684,6 +690,9 @@ class TestSystemAPIs(unittest.TestCase):
self.assertNotEqual(users, [])
for user in users:
assert user.name, user
+ self.assertIsInstance(user.name, (str, unicode))
+ self.assertIsInstance(user.terminal, (str, unicode, None))
+ self.assertIsInstance(user.host, (str, unicode, None))
user.terminal
user.host
assert user.started > 0.0, user