summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-04-30 12:43:09 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-04-30 12:43:09 +0200
commit497f4a9dd8302ca64d328939d91afd3560189b30 (patch)
tree6e0e8b17137237f39555eea0cc89f9b448c3b153
parent5f56983c2195ff6c20c8066749fa8b28d47dbd2e (diff)
downloadpsutil-497f4a9dd8302ca64d328939d91afd3560189b30.tar.gz
provide generic PsutilTestCase class
-rw-r--r--psutil/tests/__init__.py18
-rwxr-xr-xpsutil/tests/test_aix.py3
-rwxr-xr-xpsutil/tests/test_bsd.py11
-rwxr-xr-xpsutil/tests/test_connections.py6
-rwxr-xr-xpsutil/tests/test_contracts.py11
-rwxr-xr-xpsutil/tests/test_linux.py44
-rwxr-xr-xpsutil/tests/test_misc.py7
-rwxr-xr-xpsutil/tests/test_osx.py9
-rwxr-xr-xpsutil/tests/test_posix.py5
-rwxr-xr-xpsutil/tests/test_process.py6
-rwxr-xr-xpsutil/tests/test_sunos.py3
-rwxr-xr-xpsutil/tests/test_system.py16
-rwxr-xr-xpsutil/tests/test_testutils.py14
-rwxr-xr-xpsutil/tests/test_unicode.py8
-rwxr-xr-xpsutil/tests/test_windows.py8
15 files changed, 88 insertions, 81 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index fc4bff01..3f387c51 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -88,7 +88,7 @@ __all__ = [
'ThreadTask'
# test utils
'unittest', 'skip_on_access_denied', 'skip_on_not_implemented',
- 'retry_on_failure', 'TestMemoryLeak', 'ProcessTestCase',
+ 'retry_on_failure', 'TestMemoryLeak', 'PsutilTestCase',
# install utils
'install_pip', 'install_test_deps',
# fs utils
@@ -841,11 +841,16 @@ class TestCase(unittest.TestCase):
unittest.TestCase = TestCase
-class ProcessTestCase(TestCase):
+class PsutilTestCase(TestCase):
"""Test class providing auto-cleanup wrappers on top of process
test utilities.
"""
+ def get_testfn(self, suffix="", dir=None):
+ fname = get_testfn(suffix=suffix, dir=suffix)
+ self.addCleanup(safe_rmpath(fname))
+ return fname
+
def get_test_subprocess(self, *args, **kwds):
sproc = get_test_subprocess(*args, **kwds)
self.addCleanup(terminate, sproc)
@@ -853,8 +858,8 @@ class ProcessTestCase(TestCase):
def create_proc_children_pair(self):
child1, child2 = create_proc_children_pair()
- self.addCleanup(terminate, child1)
self.addCleanup(terminate, child2)
+ self.addCleanup(terminate, child1) # executed first
return (child1, child2)
def create_zombie_proc(self):
@@ -868,14 +873,9 @@ class ProcessTestCase(TestCase):
self.addCleanup(terminate, sproc)
return sproc
- def get_testfn(self, suffix="", dir=None):
- fname = get_testfn(suffix=suffix, dir=suffix)
- self.addCleanup(safe_rmpath(fname))
- return fname
-
@unittest.skipIf(PYPY, "unreliable on PYPY")
-class TestMemoryLeak(unittest.TestCase):
+class TestMemoryLeak(PsutilTestCase):
"""Test framework class for detecting function memory leaks (typically
functions implemented in C).
It does so by calling a function many times, and checks whether the
diff --git a/psutil/tests/test_aix.py b/psutil/tests/test_aix.py
index 889526ad..caf20357 100755
--- a/psutil/tests/test_aix.py
+++ b/psutil/tests/test_aix.py
@@ -11,13 +11,14 @@
import re
from psutil import AIX
+from psutil.tests import PsutilTestCase
from psutil.tests import sh
from psutil.tests import unittest
import psutil
@unittest.skipIf(not AIX, "AIX only")
-class AIXSpecificTestCase(unittest.TestCase):
+class AIXSpecificTestCase(PsutilTestCase):
def test_virtual_memory(self):
out = sh('/usr/bin/svmon -O unit=KB')
diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py
index 427b9219..598ec0bf 100755
--- a/psutil/tests/test_bsd.py
+++ b/psutil/tests/test_bsd.py
@@ -22,6 +22,7 @@ from psutil import NETBSD
from psutil import OPENBSD
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_BATTERY
+from psutil.tests import PsutilTestCase
from psutil.tests import retry_on_failure
from psutil.tests import sh
from psutil.tests import SYSMEM_TOLERANCE
@@ -72,7 +73,7 @@ def muse(field):
@unittest.skipIf(not BSD, "BSD only")
-class BSDTestCase(unittest.TestCase):
+class BSDTestCase(PsutilTestCase):
"""Generic tests common to all BSD variants."""
@classmethod
@@ -148,7 +149,7 @@ class BSDTestCase(unittest.TestCase):
@unittest.skipIf(not FREEBSD, "FREEBSD only")
-class FreeBSDProcessTestCase(unittest.TestCase):
+class FreeBSDPsutilTestCase(PsutilTestCase):
@classmethod
def setUpClass(cls):
@@ -238,7 +239,7 @@ class FreeBSDProcessTestCase(unittest.TestCase):
@unittest.skipIf(not FREEBSD, "FREEBSD only")
-class FreeBSDSystemTestCase(unittest.TestCase):
+class FreeBSDSystemTestCase(PsutilTestCase):
@staticmethod
def parse_swapinfo():
@@ -479,7 +480,7 @@ class FreeBSDSystemTestCase(unittest.TestCase):
@unittest.skipIf(not OPENBSD, "OPENBSD only")
-class OpenBSDTestCase(unittest.TestCase):
+class OpenBSDTestCase(PsutilTestCase):
def test_boot_time(self):
s = sysctl('kern.boottime')
@@ -494,7 +495,7 @@ class OpenBSDTestCase(unittest.TestCase):
@unittest.skipIf(not NETBSD, "NETBSD only")
-class NetBSDTestCase(unittest.TestCase):
+class NetBSDTestCase(PsutilTestCase):
@staticmethod
def parse_meminfo(look_for):
diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py
index 9c1bbe8e..5092b01d 100755
--- a/psutil/tests/test_connections.py
+++ b/psutil/tests/test_connections.py
@@ -39,7 +39,7 @@ from psutil.tests import enum
from psutil.tests import get_free_port
from psutil.tests import get_testfn
from psutil.tests import HAS_CONNECTIONS_UNIX
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import serialrun
from psutil.tests import skip_on_access_denied
from psutil.tests import SKIP_SYSCONS
@@ -55,7 +55,7 @@ SOCK_SEQPACKET = getattr(socket, "SOCK_SEQPACKET", object())
@serialrun
-class _ConnTestCase(ProcessTestCase):
+class _ConnTestCase(PsutilTestCase):
def setUp(self):
if not (NETBSD or FREEBSD):
@@ -610,7 +610,7 @@ class TestSystemWideConnections(_ConnTestCase):
self.assertEqual(len(p.connections('all')), expected)
-class TestMisc(unittest.TestCase):
+class TestMisc(PsutilTestCase):
def test_connection_constants(self):
ints = []
diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py
index 69bb0b2f..a80a6b78 100755
--- a/psutil/tests/test_contracts.py
+++ b/psutil/tests/test_contracts.py
@@ -37,6 +37,7 @@ from psutil.tests import HAS_RLIMIT
from psutil.tests import HAS_SENSORS_FANS
from psutil.tests import HAS_SENSORS_TEMPERATURES
from psutil.tests import is_namedtuple
+from psutil.tests import PsutilTestCase
from psutil.tests import SKIP_SYSCONS
from psutil.tests import unittest
from psutil.tests import VALID_PROC_STATUSES
@@ -51,7 +52,7 @@ import psutil
# Make sure code reflects what doc promises in terms of APIs
# availability.
-class TestAvailConstantsAPIs(unittest.TestCase):
+class TestAvailConstantsAPIs(PsutilTestCase):
def test_PROCFS_PATH(self):
self.assertEqual(hasattr(psutil, "PROCFS_PATH"),
@@ -105,7 +106,7 @@ class TestAvailConstantsAPIs(unittest.TestCase):
ae(hasattr(psutil, "RLIMIT_SIGPENDING"), hasit)
-class TestAvailSystemAPIs(unittest.TestCase):
+class TestAvailSystemAPIs(PsutilTestCase):
def test_win_service_iter(self):
self.assertEqual(hasattr(psutil, "win_service_iter"), WINDOWS)
@@ -132,7 +133,7 @@ class TestAvailSystemAPIs(unittest.TestCase):
LINUX or WINDOWS or FREEBSD or MACOS)
-class TestAvailProcessAPIs(unittest.TestCase):
+class TestAvailProcessAPIs(PsutilTestCase):
def test_environ(self):
self.assertEqual(hasattr(psutil.Process, "environ"),
@@ -182,7 +183,7 @@ class TestAvailProcessAPIs(unittest.TestCase):
# ===================================================================
-class TestSystemAPITypes(unittest.TestCase):
+class TestSystemAPITypes(PsutilTestCase):
"""Check the return types of system related APIs.
Mainly we want to test we never return unicode on Python 2, see:
https://github.com/giampaolo/psutil/issues/1039
@@ -312,7 +313,7 @@ class TestSystemAPITypes(unittest.TestCase):
# ===================================================================
-class TestFetchAllProcesses(unittest.TestCase):
+class TestFetchAllProcesses(PsutilTestCase):
"""Test which iterates over all running processes and performs
some sanity checks against Process API's returned values.
"""
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index bac20b05..3f200fc4 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -34,7 +34,7 @@ from psutil.tests import HAS_CPU_FREQ
from psutil.tests import HAS_GETLOADAVG
from psutil.tests import HAS_RLIMIT
from psutil.tests import mock
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import PYPY
from psutil.tests import reload_module
from psutil.tests import retry_on_failure
@@ -188,7 +188,7 @@ def mock_open_exception(for_path, exc):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemVirtualMemory(unittest.TestCase):
+class TestSystemVirtualMemory(PsutilTestCase):
def test_total(self):
# free_value = free_physmem().total
@@ -494,7 +494,7 @@ class TestSystemVirtualMemory(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemSwapMemory(unittest.TestCase):
+class TestSystemSwapMemory(PsutilTestCase):
@staticmethod
def meminfo_has_swap_info():
@@ -588,7 +588,7 @@ class TestSystemSwapMemory(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemCPUTimes(unittest.TestCase):
+class TestSystemCPUTimes(PsutilTestCase):
@unittest.skipIf(TRAVIS, "unknown failure on travis")
def test_fields(self):
@@ -610,7 +610,7 @@ class TestSystemCPUTimes(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemCPUCountLogical(unittest.TestCase):
+class TestSystemCPUCountLogical(PsutilTestCase):
@unittest.skipIf(not os.path.exists("/sys/devices/system/cpu/online"),
"/sys/devices/system/cpu/online does not exist")
@@ -674,7 +674,7 @@ class TestSystemCPUCountLogical(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemCPUCountPhysical(unittest.TestCase):
+class TestSystemCPUCountPhysical(PsutilTestCase):
@unittest.skipIf(not which("lscpu"), "lscpu utility not available")
def test_against_lscpu(self):
@@ -695,7 +695,7 @@ class TestSystemCPUCountPhysical(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemCPUFrequency(unittest.TestCase):
+class TestSystemCPUFrequency(PsutilTestCase):
@unittest.skipIf(TRAVIS, "fails on Travis")
@unittest.skipIf(not HAS_CPU_FREQ, "not supported")
@@ -843,7 +843,7 @@ class TestSystemCPUFrequency(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemCPUStats(unittest.TestCase):
+class TestSystemCPUStats(PsutilTestCase):
@unittest.skipIf(TRAVIS, "fails on Travis")
def test_ctx_switches(self):
@@ -859,7 +859,7 @@ class TestSystemCPUStats(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestLoadAvg(unittest.TestCase):
+class TestLoadAvg(PsutilTestCase):
@unittest.skipIf(not HAS_GETLOADAVG, "not supported")
def test_getloadavg(self):
@@ -878,7 +878,7 @@ class TestLoadAvg(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemNetIfAddrs(unittest.TestCase):
+class TestSystemNetIfAddrs(PsutilTestCase):
def test_ips(self):
for name, addrs in psutil.net_if_addrs().items():
@@ -907,7 +907,7 @@ class TestSystemNetIfAddrs(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemNetIfStats(unittest.TestCase):
+class TestSystemNetIfStats(PsutilTestCase):
def test_against_ifconfig(self):
for name, stats in psutil.net_if_stats().items():
@@ -923,7 +923,7 @@ class TestSystemNetIfStats(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemNetIOCounters(unittest.TestCase):
+class TestSystemNetIOCounters(PsutilTestCase):
@retry_on_failure()
def test_against_ifconfig(self):
@@ -969,7 +969,7 @@ class TestSystemNetIOCounters(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemNetConnections(unittest.TestCase):
+class TestSystemNetConnections(PsutilTestCase):
@mock.patch('psutil._pslinux.socket.inet_ntop', side_effect=ValueError)
@mock.patch('psutil._pslinux.supports_ipv6', return_value=False)
@@ -1002,7 +1002,7 @@ class TestSystemNetConnections(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemDiskPartitions(unittest.TestCase):
+class TestSystemDiskPartitions(PsutilTestCase):
@unittest.skipIf(not hasattr(os, 'statvfs'), "os.statvfs() not available")
@skip_on_not_implemented()
@@ -1067,7 +1067,7 @@ class TestSystemDiskPartitions(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemDiskIoCounters(unittest.TestCase):
+class TestSystemDiskIoCounters(PsutilTestCase):
def test_emulate_kernel_2_4(self):
# Tests /proc/diskstats parsing format for 2.4 kernels, see:
@@ -1208,7 +1208,7 @@ class TestSystemDiskIoCounters(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestMisc(unittest.TestCase):
+class TestMisc(PsutilTestCase):
def test_boot_time(self):
vmstat_value = vmstat('boot time')
@@ -1397,7 +1397,7 @@ class TestMisc(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
@unittest.skipIf(not HAS_BATTERY, "no battery")
-class TestSensorsBattery(unittest.TestCase):
+class TestSensorsBattery(PsutilTestCase):
@unittest.skipIf(not which("acpi"), "acpi utility not available")
def test_percent(self):
@@ -1545,7 +1545,7 @@ class TestSensorsBattery(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSensorsTemperatures(unittest.TestCase):
+class TestSensorsTemperatures(PsutilTestCase):
def test_emulate_class_hwmon(self):
def open_mock(name, *args, **kwargs):
@@ -1611,7 +1611,7 @@ class TestSensorsTemperatures(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSensorsFans(unittest.TestCase):
+class TestSensorsFans(PsutilTestCase):
def test_emulate_data(self):
def open_mock(name, *args, **kwargs):
@@ -1640,7 +1640,7 @@ class TestSensorsFans(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestProcess(ProcessTestCase):
+class TestProcess(PsutilTestCase):
@retry_on_failure()
def test_memory_full_info(self):
@@ -2009,7 +2009,7 @@ class TestProcess(ProcessTestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestProcessAgainstStatus(unittest.TestCase):
+class TestProcessAgainstStatus(PsutilTestCase):
"""/proc/pid/stat and /proc/pid/status have many values in common.
Whenever possible, psutil uses /proc/pid/stat (it's faster).
For all those cases we check that the value found in
@@ -2092,7 +2092,7 @@ class TestProcessAgainstStatus(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestUtils(unittest.TestCase):
+class TestUtils(PsutilTestCase):
def test_readlink(self):
with mock.patch("os.readlink", return_value="foo (deleted)") as m:
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 18781e75..4fb8ba5a 100755
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -37,6 +37,7 @@ from psutil.tests import HAS_SENSORS_FANS
from psutil.tests import HAS_SENSORS_TEMPERATURES
from psutil.tests import import_module_by_path
from psutil.tests import mock
+from psutil.tests import PsutilTestCase
from psutil.tests import PYTHON_EXE
from psutil.tests import reload_module
from psutil.tests import ROOT_DIR
@@ -53,7 +54,7 @@ import psutil.tests
# ===================================================================
-class TestMisc(unittest.TestCase):
+class TestMisc(PsutilTestCase):
def test_process__repr__(self, func=repr):
p = psutil.Process()
@@ -386,7 +387,7 @@ class TestMisc(unittest.TestCase):
nt = collections.namedtuple('foo', 'a b c')
-class TestWrapNumbers(unittest.TestCase):
+class TestWrapNumbers(PsutilTestCase):
def setUp(self):
wrap_numbers.cache_clear()
@@ -627,7 +628,7 @@ class TestWrapNumbers(unittest.TestCase):
@unittest.skipIf(not os.path.exists(SCRIPTS_DIR),
"can't locate scripts directory")
-class TestScripts(unittest.TestCase):
+class TestScripts(PsutilTestCase):
"""Tests for scripts in the "scripts" directory."""
@staticmethod
diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py
index 4df6a884..c2e6ad72 100755
--- a/psutil/tests/test_osx.py
+++ b/psutil/tests/test_osx.py
@@ -15,9 +15,10 @@ from psutil import MACOS
from psutil.tests import create_zombie_proc
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_BATTERY
-from psutil.tests import SYSMEM_TOLERANCE
+from psutil.tests import PsutilTestCase
from psutil.tests import retry_on_failure
from psutil.tests import sh
+from psutil.tests import SYSMEM_TOLERANCE
from psutil.tests import terminate
from psutil.tests import unittest
@@ -76,7 +77,7 @@ def human2bytes(s):
@unittest.skipIf(not MACOS, "MACOS only")
-class TestProcess(unittest.TestCase):
+class TestProcess(PsutilTestCase):
@classmethod
def setUpClass(cls):
@@ -102,7 +103,7 @@ class TestProcess(unittest.TestCase):
# TODO: probably needs removal (duplicate)
@unittest.skipIf(not MACOS, "MACOS only")
-class TestZombieProcessAPIs(unittest.TestCase):
+class TestZombieProcessAPIs(PsutilTestCase):
@classmethod
def setUpClass(cls):
@@ -160,7 +161,7 @@ class TestZombieProcessAPIs(unittest.TestCase):
@unittest.skipIf(not MACOS, "MACOS only")
-class TestSystemAPIs(unittest.TestCase):
+class TestSystemAPIs(PsutilTestCase):
# --- disk
diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py
index 1b37fa2f..9eeb5c2b 100755
--- a/psutil/tests/test_posix.py
+++ b/psutil/tests/test_posix.py
@@ -27,6 +27,7 @@ from psutil.tests import get_kernel_version
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_NET_IO_COUNTERS
from psutil.tests import mock
+from psutil.tests import PsutilTestCase
from psutil.tests import PYTHON_EXE
from psutil.tests import retry_on_failure
from psutil.tests import sh
@@ -126,7 +127,7 @@ def ps_vsz(pid):
@unittest.skipIf(not POSIX, "POSIX only")
-class TestProcess(unittest.TestCase):
+class TestProcess(PsutilTestCase):
"""Compare psutil results against 'ps' command line utility (mainly)."""
@classmethod
@@ -326,7 +327,7 @@ class TestProcess(unittest.TestCase):
@unittest.skipIf(not POSIX, "POSIX only")
-class TestSystemAPIs(unittest.TestCase):
+class TestSystemAPIs(PsutilTestCase):
"""Test some system APIs."""
@retry_on_failure()
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index c87df1b1..61ef77b3 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -50,7 +50,7 @@ from psutil.tests import HAS_PROC_IO_COUNTERS
from psutil.tests import HAS_RLIMIT
from psutil.tests import HAS_THREADS
from psutil.tests import mock
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import PYPY
from psutil.tests import PYTHON_EXE
from psutil.tests import reap_children
@@ -69,7 +69,7 @@ from psutil.tests import wait_for_pid
# ===================================================================
-class TestProcess(ProcessTestCase):
+class TestProcess(PsutilTestCase):
"""Tests for psutil.Process class."""
def test_pid(self):
@@ -1560,7 +1560,7 @@ if POSIX and os.getuid() == 0:
# ===================================================================
-class TestPopen(unittest.TestCase):
+class TestPopen(PsutilTestCase):
"""Tests for psutil.Popen class."""
@classmethod
diff --git a/psutil/tests/test_sunos.py b/psutil/tests/test_sunos.py
index bac1a212..ad94f774 100755
--- a/psutil/tests/test_sunos.py
+++ b/psutil/tests/test_sunos.py
@@ -10,12 +10,13 @@ import os
import psutil
from psutil import SUNOS
+from psutil.tests import PsutilTestCase
from psutil.tests import sh
from psutil.tests import unittest
@unittest.skipIf(not SUNOS, "SUNOS only")
-class SunOSSpecificTestCase(unittest.TestCase):
+class SunOSSpecificTestCase(PsutilTestCase):
def test_swap_memory(self):
out = sh('env PATH=/usr/sbin:/sbin:%s swap -l' % os.environ['PATH'])
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index d0817459..d9fa253c 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -44,7 +44,7 @@ from psutil.tests import HAS_SENSORS_BATTERY
from psutil.tests import HAS_SENSORS_FANS
from psutil.tests import HAS_SENSORS_TEMPERATURES
from psutil.tests import mock
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import PYPY
from psutil.tests import retry_on_failure
from psutil.tests import TRAVIS
@@ -57,7 +57,7 @@ from psutil.tests import unittest
# ===================================================================
-class TestProcessAPIs(ProcessTestCase):
+class TestProcessAPIs(PsutilTestCase):
def test_process_iter(self):
self.assertIn(os.getpid(), [x.pid for x in psutil.process_iter()])
@@ -190,7 +190,7 @@ class TestProcessAPIs(ProcessTestCase):
self.assertFalse(psutil.pid_exists(pid), msg=pid)
-class TestMiscAPIs(unittest.TestCase):
+class TestMiscAPIs(PsutilTestCase):
def test_boot_time(self):
bt = psutil.boot_time()
@@ -272,7 +272,7 @@ class TestMiscAPIs(unittest.TestCase):
self.assertIs(getattr(psutil, name), False, msg=name)
-class TestMemoryAPIs(unittest.TestCase):
+class TestMemoryAPIs(PsutilTestCase):
def test_virtual_memory(self):
mem = psutil.virtual_memory()
@@ -309,7 +309,7 @@ class TestMemoryAPIs(unittest.TestCase):
assert mem.sout >= 0, mem
-class TestCpuAPIs(unittest.TestCase):
+class TestCpuAPIs(PsutilTestCase):
def test_cpu_count_logical(self):
logical = psutil.cpu_count()
@@ -550,7 +550,7 @@ class TestCpuAPIs(unittest.TestCase):
self.assertGreaterEqual(load, 0.0)
-class TestDiskAPIs(unittest.TestCase):
+class TestDiskAPIs(PsutilTestCase):
def test_disk_usage(self):
usage = psutil.disk_usage(os.getcwd())
@@ -684,7 +684,7 @@ class TestDiskAPIs(unittest.TestCase):
assert m.called
-class TestNetAPIs(unittest.TestCase):
+class TestNetAPIs(PsutilTestCase):
@unittest.skipIf(not HAS_NET_IO_COUNTERS, 'not supported')
def test_net_io_counters(self):
@@ -829,7 +829,7 @@ class TestNetAPIs(unittest.TestCase):
assert m.called
-class TestSensorsAPIs(unittest.TestCase):
+class TestSensorsAPIs(PsutilTestCase):
@unittest.skipIf(not HAS_SENSORS_TEMPERATURES, "not supported")
def test_sensors_temperatures(self):
diff --git a/psutil/tests/test_testutils.py b/psutil/tests/test_testutils.py
index 85b61aea..299cd24c 100755
--- a/psutil/tests/test_testutils.py
+++ b/psutil/tests/test_testutils.py
@@ -36,7 +36,7 @@ from psutil.tests import get_testfn
from psutil.tests import HAS_CONNECTIONS_UNIX
from psutil.tests import is_namedtuple
from psutil.tests import mock
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import PYTHON_EXE
from psutil.tests import reap_children
from psutil.tests import retry
@@ -59,7 +59,7 @@ import psutil.tests
# ===================================================================
-class TestRetryDecorator(unittest.TestCase):
+class TestRetryDecorator(PsutilTestCase):
@mock.patch('time.sleep')
def test_retry_success(self, sleep):
@@ -125,7 +125,7 @@ class TestRetryDecorator(unittest.TestCase):
self.assertRaises(ValueError, retry, retries=5, timeout=1)
-class TestSyncTestUtils(unittest.TestCase):
+class TestSyncTestUtils(PsutilTestCase):
def test_wait_for_pid(self):
wait_for_pid(os.getpid())
@@ -164,7 +164,7 @@ class TestSyncTestUtils(unittest.TestCase):
self.assertEqual(ret, 1)
-class TestFSTestUtils(unittest.TestCase):
+class TestFSTestUtils(PsutilTestCase):
def test_open_text(self):
with open_text(__file__) as f:
@@ -209,7 +209,7 @@ class TestFSTestUtils(unittest.TestCase):
self.assertEqual(os.getcwd(), base)
-class TestProcessUtils(ProcessTestCase):
+class TestProcessUtils(PsutilTestCase):
def test_reap_children(self):
subp = self.get_test_subprocess()
@@ -275,7 +275,7 @@ class TestProcessUtils(ProcessTestCase):
assert not psutil.pid_exists(zombie.pid)
-class TestNetUtils(unittest.TestCase):
+class TestNetUtils(PsutilTestCase):
def bind_socket(self):
port = get_free_port()
@@ -417,7 +417,7 @@ class TestMemLeakClass(TestMemoryLeak):
self.execute_w_exc(ZeroDivisionError, fun)
-class TestOtherUtils(unittest.TestCase):
+class TestOtherUtils(PsutilTestCase):
def test_is_namedtuple(self):
assert is_namedtuple(collections.namedtuple('foo', 'a b c')(1, 2, 3))
diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py
index ae9f7f51..69e52419 100755
--- a/psutil/tests/test_unicode.py
+++ b/psutil/tests/test_unicode.py
@@ -98,7 +98,7 @@ from psutil.tests import HAS_CONNECTIONS_UNIX
from psutil.tests import HAS_ENVIRON
from psutil.tests import HAS_MEMORY_MAPS
from psutil.tests import INVALID_UNICODE_SUFFIX
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import PYPY
from psutil.tests import reap_children
from psutil.tests import safe_mkdir
@@ -304,7 +304,7 @@ class _BaseFSAPIsTests(object):
@unittest.skipIf(ASCII_FS, "ASCII fs")
@unittest.skipIf(not subprocess_supports_unicode(UNICODE_SUFFIX),
"subprocess can't deal with unicode")
-class TestFSAPIs(_BaseFSAPIsTests, ProcessTestCase):
+class TestFSAPIs(_BaseFSAPIsTests, PsutilTestCase):
"""Test FS APIs with a funky, valid, UTF8 path name."""
funky_suffix = UNICODE_SUFFIX
@@ -322,7 +322,7 @@ class TestFSAPIs(_BaseFSAPIsTests, ProcessTestCase):
@unittest.skipIf(PYPY, "unreliable on PYPY")
@unittest.skipIf(not subprocess_supports_unicode(INVALID_UNICODE_SUFFIX),
"subprocess can't deal with invalid unicode")
-class TestFSAPIsWithInvalidPath(_BaseFSAPIsTests, ProcessTestCase):
+class TestFSAPIsWithInvalidPath(_BaseFSAPIsTests, PsutilTestCase):
"""Test FS APIs with a funky, invalid path name."""
funky_suffix = INVALID_UNICODE_SUFFIX
@@ -337,7 +337,7 @@ class TestFSAPIsWithInvalidPath(_BaseFSAPIsTests, ProcessTestCase):
# ===================================================================
-class TestNonFSAPIS(ProcessTestCase):
+class TestNonFSAPIS(PsutilTestCase):
"""Unicode tests for non fs-related APIs."""
def tearDown(self):
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index a51c9c15..0c5faf18 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -26,7 +26,7 @@ from psutil.tests import APPVEYOR
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_BATTERY
from psutil.tests import mock
-from psutil.tests import ProcessTestCase
+from psutil.tests import PsutilTestCase
from psutil.tests import PY3
from psutil.tests import PYPY
from psutil.tests import reap_children
@@ -66,7 +66,7 @@ def wrap_exceptions(fun):
@unittest.skipIf(PYPY, "pywin32 not available on PYPY") # skip whole module
-class TestCase(unittest.TestCase):
+class TestCase(PsutilTestCase):
pass
@@ -300,7 +300,7 @@ class TestSensorsBattery(TestCase):
@unittest.skipIf(not WINDOWS, "WINDOWS only")
-class TestProcess(ProcessTestCase):
+class TestProcess(PsutilTestCase):
@classmethod
def setUpClass(cls):
@@ -677,7 +677,7 @@ class TestDualProcessImplementation(TestCase):
@unittest.skipIf(not WINDOWS, "WINDOWS only")
-class RemoteProcessTestCase(ProcessTestCase):
+class RemotePsutilTestCase(PsutilTestCase):
"""Certain functions require calling ReadProcessMemory.
This trivially works when called on the current process.
Check that this works on other processes, especially when they