summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-03 02:58:02 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-03 02:58:02 +0200
commitc2e8ee39c05d007f01fc66b5e99dc3593830cc4d (patch)
tree4a7241fcd0c20fb22f1048ca77b3053f6dc9af1b
parent58aed3b56d275706526e9fa56869d8fe6d1ed369 (diff)
parentb7a8acb12236b1944c7e7064ddbb3f620a9134d2 (diff)
downloadpsutil-c2e8ee39c05d007f01fc66b5e99dc3593830cc4d.tar.gz
Merge branch 'master' into 1040-fix-unicode
-rw-r--r--HISTORY.rst1
-rw-r--r--docs/index.rst3
-rw-r--r--psutil/_psutil_windows.c7
-rw-r--r--psutil/tests/__init__.py2
-rwxr-xr-xpsutil/tests/test_contracts.py7
-rw-r--r--psutil/tests/test_unicode.py16
6 files changed, 16 insertions, 20 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 85092fa6..94126cd3 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -35,6 +35,7 @@
None
- OpenBSD: connections('unix'): laddr and raddr are now set to "" instead of
None
+- 1046_: [Windows] disk_partitions() on Windows overrides user's SetErrorMode.
*2017-04-10*
diff --git a/docs/index.rst b/docs/index.rst
index 394aeae8..16301958 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1245,7 +1245,8 @@ Process class
>>>
On Windows only *ioclass* is used and it can be set to ``2`` (normal),
- ``1`` (low) or ``0`` (very low).
+ ``1`` (low) or ``0`` (very low). Also it returns an integer instead of a
+ named tuple.
Availability: Linux and Windows > Vista
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index b1a62977..1c742afb 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -2447,6 +2447,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
int all;
int type;
int ret;
+ unsigned int old_mode = 0;
char opts[20];
LPTSTR fs_type[MAX_PATH + 1] = { 0 };
DWORD pflags = 0;
@@ -2460,7 +2461,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
// avoid to visualize a message box in case something goes wrong
// see https://github.com/giampaolo/psutil/issues/264
- SetErrorMode(SEM_FAILCRITICALERRORS);
+ old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
if (! PyArg_ParseTuple(args, "O", &py_all))
goto error;
@@ -2541,11 +2542,11 @@ next:
drive_letter = strchr(drive_letter, 0) + 1;
}
- SetErrorMode(0);
+ SetErrorMode(old_mode);
return py_retlist;
error:
- SetErrorMode(0);
+ SetErrorMode(old_mode);
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
return NULL;
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 771a3cc3..c813ce46 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -967,6 +967,8 @@ def copyload_shared_lib(dst_prefix=TESTFILE_PREFIX):
dst = tempfile.mktemp(prefix=dst_prefix, suffix=ext)
libs = [x.path for x in psutil.Process().memory_maps()
if os.path.normcase(os.path.splitext(x.path)[1]) == ext]
+ if WINDOWS:
+ libs = [x for x in libs if 'wow64' not in x.lower()]
src = random.choice(libs)
cfile = None
try:
diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py
index f44b7a41..d3c0377a 100755
--- a/psutil/tests/test_contracts.py
+++ b/psutil/tests/test_contracts.py
@@ -430,9 +430,10 @@ class TestFetchAllProcesses(unittest.TestCase):
self.assertGreaterEqual(field, 0)
def ionice(self, ret, proc):
- assert is_namedtuple(ret)
- for field in ret:
- self.assertIsInstance(field, int)
+ if POSIX:
+ assert is_namedtuple(ret)
+ for field in ret:
+ self.assertIsInstance(field, int)
if LINUX:
self.assertGreaterEqual(ret.ioclass, 0)
self.assertGreaterEqual(ret.value, 0)
diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py
index cf1c02af..ce881eac 100644
--- a/psutil/tests/test_unicode.py
+++ b/psutil/tests/test_unicode.py
@@ -110,16 +110,6 @@ def subprocess_supports_unicode(name):
return True
-def ctypes_supports_unicode(name):
- if PY3:
- return True
- try:
- with copyload_shared_lib():
- pass
- except UnicodeEncodeError:
- return False
-
-
# An invalid unicode string.
if PY3:
INVALID_NAME = (TESTFN.encode('utf8') + b"f\xc0\x80").decode(
@@ -252,10 +242,10 @@ class _BaseFSAPIsTests(object):
psutil.disk_usage(self.funky_name)
@unittest.skipIf(not HAS_MEMORY_MAPS, "not supported")
+ @unittest.skipIf(not PY3, "ctypes opens err msg box on Python 2")
def test_memory_maps(self):
- if not ctypes_supports_unicode(self.funky_name):
- raise unittest.SkipTest("ctypes can't handle unicode")
-
+ # XXX: on Python 2, using ctypes.CDLL with a unicode path
+ # opens a message box which blocks the test run.
with copyload_shared_lib(dst_prefix=self.funky_name) as funky_path:
def normpath(p):
return os.path.realpath(os.path.normcase(p))