diff --git a/HISTORY.rst b/HISTORY.rst index 30bdecc3b..52c48c73e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,7 @@ Process.as_dict(): "attrs" and "ad_value". With this you can iterate over all processes in one shot without needing to catch NoSuchProcess and do list/dict comprehensions. +- 1051_: disk_usage() on Python 3 is now able to accept bytes. **Bug fixes** diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index e284bb699..c0d6d001a 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -239,13 +239,9 @@ def swap_memory(): def disk_usage(path): """Return disk usage associated with path.""" - try: - total, free = cext.disk_usage(path) - except WindowsError: - if not os.path.exists(path): - msg = "No such file or directory: '%s'" % path - raise OSError(errno.ENOENT, msg) - raise + if PY3 and isinstance(path, bytes): + path = path.decode(FS_ENCODING) + total, free = cext.disk_usage(path) used = total - free percent = usage_percent(used, total, _round=1) return _common.sdiskusage(total, used, free, percent) diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index 19f997a85..bb485296c 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -463,11 +463,9 @@ def test_disk_usage_unicode(self): if ASCII_FS: with self.assertRaises(UnicodeEncodeError): psutil.disk_usage(TESTFN_UNICODE) - else: - safe_rmpath(TESTFN_UNICODE) - self.addCleanup(safe_rmpath, TESTFN_UNICODE) - os.mkdir(TESTFN_UNICODE) - psutil.disk_usage(TESTFN_UNICODE) + + def test_disk_usage_bytes(self): + psutil.disk_usage(b'.') def test_disk_partitions(self): # all = False