summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-04 01:18:03 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-04 01:18:03 +0200
commitd7d23959b5b9579307c424b08b8d33892d056c92 (patch)
treee20499606dacb3c962a2d2a68187acfe3462ba1c
parentde2b223686d5f8b8fd8cf28a4eef4c91468bf9c2 (diff)
parente6f5f498d508335f359cd2d01a1098afcbcb1b6c (diff)
downloadpsutil-d7d23959b5b9579307c424b08b8d33892d056c92.tar.gz
merge with master
-rw-r--r--HISTORY.rst6
-rw-r--r--psutil/_psutil_windows.c1
-rwxr-xr-xpsutil/tests/test_memory_leaks.py3
-rwxr-xr-xpsutil/tests/test_misc.py3
-rwxr-xr-xpsutil/tests/test_posix.py9
-rwxr-xr-xpsutil/tests/test_process.py23
-rwxr-xr-xpsutil/tests/test_windows.py5
-rwxr-xr-xscripts/internal/winmake.py7
8 files changed, 34 insertions, 23 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index c25491fb..9a3b1793 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -44,13 +44,17 @@
None
- OpenBSD: connections('unix'): laddr and raddr are now set to "" instead of
None
+- 1040_: all strings are encoded by using OS fs encoding.
- 1040_: the following Windows APIs returned unicode and now they return str:
- Process.memory_maps().path
- WindosService.bin_path()
- WindosService.description()
- WindosService.display_name()
- WindosService.username()
-- 1040_: all strings are encoded by using OS fs encoding.
+- 1046_: [Windows] disk_partitions() on Windows overrides user's SetErrorMode.
+- 1047_: [Windows] Process username(): memory leak in case exception is thrown.
+- 1050_: [Windows] Process.memory_maps memory() leaks memory.
+>>>>>>> master
*2017-04-10*
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 31a0e2ea..53deadcc 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -2901,6 +2901,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_tuple);
+ Py_DECREF(py_str);
}
previousAllocationBase = basicInfo.AllocationBase;
baseAddress = (PCHAR)baseAddress + basicInfo.RegionSize;
diff --git a/psutil/tests/test_memory_leaks.py b/psutil/tests/test_memory_leaks.py
index 3c562ea2..28a083f2 100755
--- a/psutil/tests/test_memory_leaks.py
+++ b/psutil/tests/test_memory_leaks.py
@@ -568,6 +568,9 @@ class TestModuleFunctionsLeaks(TestMemLeak):
def test_win_service_iter(self):
self.execute(cext.winservice_enumerate)
+ def test_win_service_get(self):
+ pass
+
def test_win_service_get_config(self):
name = next(psutil.win_service_iter()).name()
self.execute(cext.winservice_query_config, name)
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 272253b6..6bc2e28c 100755
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -37,6 +37,7 @@ from psutil.tests import create_proc_children_pair
from psutil.tests import create_sockets
from psutil.tests import get_free_port
from psutil.tests import get_test_subprocess
+from psutil.tests import HAS_BATTERY
from psutil.tests import HAS_MEMORY_FULL_INFO
from psutil.tests import HAS_MEMORY_MAPS
from psutil.tests import HAS_SENSORS_BATTERY
@@ -503,7 +504,7 @@ class TestScripts(unittest.TestCase):
self.assert_stdout('fans.py')
@unittest.skipIf(not HAS_SENSORS_BATTERY, "not supported")
- @unittest.skipIf(TRAVIS, "not battery on TRAVIS")
+ @unittest.skipIf(not HAS_BATTERY, "no battery")
def test_battery(self):
self.assert_stdout('battery.py')
diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py
index 819da0d2..3274c02c 100755
--- a/psutil/tests/test_posix.py
+++ b/psutil/tests/test_posix.py
@@ -92,6 +92,15 @@ class TestProcess(unittest.TestCase):
username_psutil = psutil.Process(self.pid).username()
self.assertEqual(username_ps, username_psutil)
+ def test_username_no_resolution(self):
+ # Emulate a case where the system can't resolve the uid to
+ # a username in which case psutil is supposed to return
+ # the stringified uid.
+ p = psutil.Process()
+ with mock.patch("psutil.pwd.getpwuid", side_effect=KeyError) as fun:
+ self.assertEqual(p.username(), str(p.uids().real))
+ assert fun.called
+
@skip_on_access_denied()
@retry_before_failing()
def test_rss_memory(self):
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 7bb83b63..d1cb9657 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -9,6 +9,7 @@
import collections
import contextlib
import errno
+import getpass
import os
import select
import signal
@@ -836,22 +837,14 @@ class TestProcess(unittest.TestCase):
def test_username(self):
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
- if POSIX:
- import pwd
- self.assertEqual(p.username(), pwd.getpwuid(os.getuid()).pw_name)
- with mock.patch("psutil.pwd.getpwuid",
- side_effect=KeyError) as fun:
- self.assertEqual(p.username(), str(p.uids().real))
- assert fun.called
-
- elif WINDOWS and 'USERNAME' in os.environ:
- expected_username = os.environ['USERNAME']
- expected_domain = os.environ['USERDOMAIN']
- domain, username = p.username().split('\\')
- self.assertEqual(domain, expected_domain)
- self.assertEqual(username, expected_username)
+ username = p.username()
+ if WINDOWS:
+ domain, username = username.split('\\')
+ self.assertEqual(username, getpass.getuser())
+ if 'USERDOMAIN' in os.environ:
+ self.assertEqual(domain, os.environ['USERDOMAIN'])
else:
- p.username()
+ self.assertEqual(username, getpass.getuser())
def test_cwd(self):
sproc = get_test_subprocess()
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index 7acec9e8..ac787283 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -368,9 +368,8 @@ class TestProcess(unittest.TestCase):
self.assertEqual(a, b)
def test_username(self):
- sys_value = win32api.GetUserName()
- psutil_value = psutil.Process().username()
- self.assertEqual(sys_value, psutil_value.split('\\')[1])
+ self.assertEqual(psutil.Process().username(),
+ win32api.GetUserNameEx(win32con.NameSamCompatible))
def test_cmdline(self):
sys_value = re.sub(' +', ' ', win32api.GetCommandLine()).strip()
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index 69d4d972..b8d111a4 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -73,8 +73,9 @@ def safe_print(text, file=sys.stdout, flush=False):
file.write("\n")
-def sh(cmd):
- safe_print("cmd: " + cmd)
+def sh(cmd, nolog=False):
+ if not nolog:
+ safe_print("cmd: " + cmd)
code = os.system(cmd)
if code:
raise SystemExit
@@ -320,7 +321,7 @@ def flake8():
py_files = py_files.decode()
py_files = [x for x in py_files.split() if x.endswith('.py')]
py_files = ' '.join(py_files)
- sh("%s -m flake8 %s" % (PYTHON, py_files))
+ sh("%s -m flake8 %s" % (PYTHON, py_files), nolog=True)
@cmd