summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-08-31 13:51:47 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2015-08-31 13:51:47 +0200
commitd905793f6c8382e8070dc57624ffdf83a7274991 (patch)
tree98ac8ce992f4dc22e41feb235424c9bb174a4d3d
parentbafd7f4f6c189c9a35c72386839f8c2fd72c5fd6 (diff)
downloadpsutil-d905793f6c8382e8070dc57624ffdf83a7274991.tar.gz
move unicode tests so that they are executed on all platforms
-rw-r--r--test/_windows.py61
-rw-r--r--test/test_psutil.py66
2 files changed, 64 insertions, 63 deletions
diff --git a/test/_windows.py b/test/_windows.py
index 1663158b..827cc449 100644
--- a/test/_windows.py
+++ b/test/_windows.py
@@ -10,17 +10,14 @@
import errno
import os
import platform
-import shutil
import signal
import subprocess
import sys
-import tempfile
import time
import traceback
from test_psutil import APPVEYOR, WINDOWS
from test_psutil import get_test_subprocess, reap_children, unittest
-from test_psutil import safe_remove, safe_rmdir, chdir
import mock
try:
@@ -469,68 +466,10 @@ class TestDualProcessImplementation(unittest.TestCase):
self.assertRaises(psutil.NoSuchProcess, meth, ZOMBIE_PID)
-class TestUnicode(unittest.TestCase):
- # See: https://github.com/giampaolo/psutil/issues/655
-
- @classmethod
- def setUpClass(cls):
- with tempfile.NamedTemporaryFile() as f:
- tdir = os.path.dirname(f.name)
- cls.uexe = os.path.join(tdir, "psutil-è.exe")
- shutil.copyfile(sys.executable, cls.uexe)
-
- @classmethod
- def tearDownClass(cls):
- safe_remove(cls.uexe)
-
- def setUp(self):
- reap_children()
-
- tearDown = setUp
-
- def test_proc_exe(self):
- subp = get_test_subprocess(cmd=[self.uexe])
- p = psutil.Process(subp.pid)
- self.assertIsInstance(p.name(), str)
- self.assertEqual(os.path.basename(p.name()), "psutil-è.exe")
-
- def test_proc_name(self):
- from psutil._pswindows import py2_strencode
- subp = get_test_subprocess(cmd=[self.uexe])
- self.assertEqual(
- py2_strencode(psutil._psplatform.cext.proc_name(subp.pid)),
- "psutil-è.exe")
-
- def test_proc_cmdline(self):
- subp = get_test_subprocess(cmd=[self.uexe])
- p = psutil.Process(subp.pid)
- self.assertIsInstance("".join(p.cmdline()), str)
- self.assertEqual(p.cmdline(), [self.uexe])
-
- def test_proc_cwd(self):
- tdir = tempfile.mkdtemp(prefix="psutil-è-")
- self.addCleanup(safe_rmdir, tdir)
- with chdir(tdir):
- p = psutil.Process()
- self.assertIsInstance(p.cwd(), str)
- self.assertEqual(p.cwd(), tdir)
-
- @unittest.skipIf(APPVEYOR, "")
- def test_proc_open_files(self):
- p = psutil.Process()
- start = set(p.open_files())
- with open(self.uexe, 'rb'):
- new = set(p.open_files())
- path = (new - start).pop().path
- self.assertIsInstance(path, str)
- self.assertEqual(path.lower(), self.uexe.lower())
-
-
def main():
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(WindowsSpecificTestCase))
test_suite.addTest(unittest.makeSuite(TestDualProcessImplementation))
- test_suite.addTest(unittest.makeSuite(TestUnicode))
result = unittest.TextTestRunner(verbosity=2).run(test_suite)
return result.wasSuccessful()
diff --git a/test/test_psutil.py b/test/test_psutil.py
index b51627cf..6b3bb029 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -3083,6 +3083,68 @@ class TestExampleScripts(unittest.TestCase):
self.assertIn(str(os.getpid()), output)
+class TestUnicode(unittest.TestCase):
+ # See: https://github.com/giampaolo/psutil/issues/655
+
+ @classmethod
+ def setUpClass(cls):
+ with tempfile.NamedTemporaryFile() as f:
+ tdir = os.path.dirname(f.name)
+ cls.uexe = os.path.join(tdir, "psutil-è.exe")
+ shutil.copyfile(sys.executable, cls.uexe)
+ if POSIX:
+ st = os.stat(cls.uexe)
+ os.chmod(cls.uexe, st.st_mode | stat.S_IEXEC)
+
+ @classmethod
+ def tearDownClass(cls):
+ safe_remove(cls.uexe)
+
+ def setUp(self):
+ reap_children()
+
+ tearDown = setUp
+
+ def test_proc_exe(self):
+ subp = get_test_subprocess(cmd=[self.uexe])
+ p = psutil.Process(subp.pid)
+ self.assertIsInstance(p.name(), str)
+ self.assertEqual(os.path.basename(p.name()), "psutil-è.exe")
+
+ def test_proc_name(self):
+ subp = get_test_subprocess(cmd=[self.uexe])
+ if WINDOWS:
+ from psutil._pswindows import py2_strencode
+ name = py2_strencode(psutil._psplatform.cext.proc_name(subp.pid))
+ else:
+ name = psutil.Process(subp.pid).name()
+ self.assertEqual(name, "psutil-è.exe")
+
+ def test_proc_cmdline(self):
+ subp = get_test_subprocess(cmd=[self.uexe])
+ p = psutil.Process(subp.pid)
+ self.assertIsInstance("".join(p.cmdline()), str)
+ self.assertEqual(p.cmdline(), [self.uexe])
+
+ def test_proc_cwd(self):
+ tdir = tempfile.mkdtemp(prefix="psutil-è-")
+ self.addCleanup(safe_rmdir, tdir)
+ with chdir(tdir):
+ p = psutil.Process()
+ self.assertIsInstance(p.cwd(), str)
+ self.assertEqual(p.cwd(), tdir)
+
+ @unittest.skipIf(APPVEYOR, "")
+ def test_proc_open_files(self):
+ p = psutil.Process()
+ start = set(p.open_files())
+ with open(self.uexe, 'rb'):
+ new = set(p.open_files())
+ path = (new - start).pop().path
+ self.assertIsInstance(path, str)
+ self.assertEqual(path.lower(), self.uexe.lower())
+
+
def main():
tests = []
test_suite = unittest.TestSuite()
@@ -3092,6 +3154,7 @@ def main():
tests.append(TestMisc)
tests.append(TestExampleScripts)
tests.append(LimitedUserTestCase)
+ tests.append(TestUnicode)
if POSIX:
from _posix import PosixSpecificTestCase
@@ -3103,9 +3166,8 @@ def main():
from _linux import LinuxSpecificTestCase as stc
elif WINDOWS:
from _windows import WindowsSpecificTestCase as stc
- from _windows import TestDualProcessImplementation, TestUnicode
+ from _windows import TestDualProcessImplementation
tests.append(TestDualProcessImplementation)
- tests.append(TestUnicode)
elif OSX:
from _osx import OSXSpecificTestCase as stc
elif BSD: