summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-04-28 04:56:20 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-04-28 04:56:20 +0200
commit161f4fb751c89a11a843871ccf949e092d68e782 (patch)
tree732bd35b41e574b59f3154c3d23993fde504aa2b
parentd65ab6edb5a73918c2574201ae6887467f549e02 (diff)
downloadpsutil-161f4fb751c89a11a843871ccf949e092d68e782.tar.gz
add unicode test for Process.connections('unix')
-rw-r--r--psutil/tests/test_unicode.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py
index 1eba1291..58d01d4e 100644
--- a/psutil/tests/test_unicode.py
+++ b/psutil/tests/test_unicode.py
@@ -12,7 +12,7 @@ Notes about unicode handling in psutil
In psutil these are the APIs returning or dealing with a string:
- Process.cmdline()
-- Process.connections('unix') (not tested)
+- Process.connections('unix')
- Process.cwd()
- Process.environ()
- Process.exe()
@@ -51,11 +51,16 @@ https://github.com/giampaolo/psutil/issues/655#issuecomment-136131180
"""
import os
+import tempfile
+import contextlib
+import socket
from psutil import BSD
+from psutil import OSX
from psutil import WINDOWS
from psutil._compat import PY3
from psutil.tests import ASCII_FS
+from psutil.tests import TESTFILE_PREFIX
from psutil.tests import chdir
from psutil.tests import create_exe
from psutil.tests import get_test_subprocess
@@ -147,6 +152,28 @@ class _BaseFSAPIsTests(object):
self.assertEqual(os.path.normcase(path),
os.path.normcase(self.funky_name))
+ @unittest.skipUnless(hasattr(socket, "AF_UNIX"), "AF_UNIX not supported")
+ def test_connections(self):
+ safe_rmpath(TESTFN)
+ # TODO: for some reason on OSX a UNIX socket cannot be
+ # deleted once created (EACCES) so we create a temp file
+ # which will remain around. :-\
+ if OSX:
+ tfile = tempfile.mktemp(
+ prefix=TESTFILE_PREFIX + self.funky_name)
+ else:
+ tfile = self.funky_name
+ self.addCleanup(safe_rmpath, tfile)
+
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ with contextlib.closing(sock):
+ try:
+ sock.bind(tfile)
+ except (socket.error, UnicodeEncodeError):
+ raise unittest.SkipTest("not supported")
+ conn = psutil.Process().connections(kind='unix')[0]
+ self.assertEqual(conn.laddr, tfile)
+
def test_disk_usage(self):
safe_mkdir(self.funky_name)
psutil.disk_usage(self.funky_name)