Skip to content

Commit

Permalink
fix #970 [Linux] sensors_battery()'s name and label fields on Python …
Browse files Browse the repository at this point in the history
…3 are bytes
  • Loading branch information
giampaolo committed Feb 3, 2017
1 parent 9415129 commit 44ca122
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand Down
5 changes: 3 additions & 2 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ def test_disk_partitions(self):
# 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:
Expand All @@ -468,7 +472,6 @@ def test_disk_partitions(self):
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)
Expand Down Expand Up @@ -512,6 +515,7 @@ def check(cons, families, types_):
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():
Expand Down Expand Up @@ -547,6 +551,7 @@ def check_ntuple(nt):
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):
Expand All @@ -562,6 +567,7 @@ def test_net_if_addrs(self):

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)
Expand Down Expand Up @@ -684,6 +690,9 @@ def test_users(self):
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
Expand Down

0 comments on commit 44ca122

Please sign in to comment.