diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-02-12 11:46:56 -0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-02-12 11:46:56 -0800 |
commit | d685eaedd054504c7cddeb80d2139301588b701f (patch) | |
tree | 6a1a9620fa555c017abdfb1b7b5959fb81017af4 | |
parent | bcfdbdcd170eaff681890631222132294efc6782 (diff) | |
download | psutil-d685eaedd054504c7cddeb80d2139301588b701f.tar.gz |
fix enum confusion on Windows
-rw-r--r-- | HISTORY.rst | 3 | ||||
-rw-r--r-- | psutil/_pswindows.py | 14 | ||||
-rw-r--r-- | test/test_psutil.py | 8 |
3 files changed, 16 insertions, 9 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index c654b41b..5f7eee31 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,7 +7,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues - #376: new psutil.net_if_addrs() returning all NIC addresses a-la ifconfig. - #469: on Python >= 3.4 ``IOPRIO_CLASS_*`` and ``*_PRIORITY_CLASS`` constants - returned by psutil.Process.ionice() are enums instead of plain integers. + returned by psutil.Process' ionice() and nice() methods are enums instead of + plain integers. - #581: add .gitignore. (patch by Gabi Davar) - #582: connection constants returned by psutil.net_connections() and psutil.Process.connections() were turned from int to enums on Python > 3.4. diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 1ddcd520..43008487 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -67,7 +67,7 @@ TCP_STATUSES = { } if enum is not None: - class IOPriority(enum.IntEnum): + class Priority(enum.IntEnum): ABOVE_NORMAL_PRIORITY_CLASS = ABOVE_NORMAL_PRIORITY_CLASS BELOW_NORMAL_PRIORITY_CLASS = BELOW_NORMAL_PRIORITY_CLASS HIGH_PRIORITY_CLASS = HIGH_PRIORITY_CLASS @@ -75,7 +75,7 @@ if enum is not None: NORMAL_PRIORITY_CLASS = NORMAL_PRIORITY_CLASS REALTIME_PRIORITY_CLASS = REALTIME_PRIORITY_CLASS - globals().update(IOPriority.__members__) + globals().update(Priority.__members__) scputimes = namedtuple('scputimes', ['user', 'system', 'idle']) @@ -433,7 +433,10 @@ class Process(object): @wrap_exceptions def nice_get(self): - return cext.proc_priority_get(self.pid) + value = cext.proc_priority_get(self.pid) + if enum is not None: + value = Priority(value) + return value @wrap_exceptions def nice_set(self, value): @@ -443,10 +446,7 @@ class Process(object): if hasattr(cext, "proc_io_priority_get"): @wrap_exceptions def ionice_get(self): - value = cext.proc_io_priority_get(self.pid) - if enum is not None: - value = IOPriority(value) - return value + return cext.proc_io_priority_get(self.pid) @wrap_exceptions def ionice_set(self, value, _): diff --git a/test/test_psutil.py b/test/test_psutil.py index c248651a..ff8809eb 100644 --- a/test/test_psutil.py +++ b/test/test_psutil.py @@ -1405,6 +1405,7 @@ class TestProcess(unittest.TestCase): else: p = psutil.Process() original = p.ionice() + self.assertIsInstance(original, int) try: value = 0 # very low if original == value: @@ -1619,7 +1620,12 @@ class TestProcess(unittest.TestCase): self.assertRaises(TypeError, p.nice, "str") if WINDOWS: try: - self.assertEqual(p.nice(), psutil.NORMAL_PRIORITY_CLASS) + init = p.nice() + if sys.version_info > (3, 4): + self.assertIsInstance(init, enum.IntEnum) + else: + self.assertIsInstance(init, int) + self.assertEqual(init, psutil.NORMAL_PRIORITY_CLASS) p.nice(psutil.HIGH_PRIORITY_CLASS) self.assertEqual(p.nice(), psutil.HIGH_PRIORITY_CLASS) p.nice(psutil.NORMAL_PRIORITY_CLASS) |