summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2022-01-07 13:29:16 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2022-01-07 13:29:16 +0100
commit93c670e0927d18b8fcd191d278fc0a885a3d8c6c (patch)
tree1644761086dbecca1e73e5bdf13e5d2b219392c6
parent9883d336a86a06b8eb445c8a333f507c330d9a56 (diff)
downloadpsutil-93c670e0927d18b8fcd191d278fc0a885a3d8c6c.tar.gz
use explicit 'raise self.fail(...)' in unit tests
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rwxr-xr-xpsutil/tests/test_bsd.py4
-rwxr-xr-xpsutil/tests/test_linux.py2
-rwxr-xr-xpsutil/tests/test_misc.py6
-rwxr-xr-xpsutil/tests/test_posix.py4
-rwxr-xr-xpsutil/tests/test_process.py16
-rwxr-xr-xpsutil/tests/test_system.py11
-rwxr-xr-xpsutil/tests/test_windows.py8
7 files changed, 26 insertions, 25 deletions
diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py
index 54b488bc..1ae810f1 100755
--- a/psutil/tests/test_bsd.py
+++ b/psutil/tests/test_bsd.py
@@ -117,9 +117,9 @@ class BSDTestCase(PsutilTestCase):
self.assertEqual(usage.total, total)
# 10 MB tollerance
if abs(usage.free - free) > 10 * 1024 * 1024:
- self.fail("psutil=%s, df=%s" % (usage.free, free))
+ raise self.fail("psutil=%s, df=%s" % (usage.free, free))
if abs(usage.used - used) > 10 * 1024 * 1024:
- self.fail("psutil=%s, df=%s" % (usage.used, used))
+ raise self.fail("psutil=%s, df=%s" % (usage.used, used))
@unittest.skipIf(not which('sysctl'), "sysctl cmd not available")
def test_cpu_count_logical(self):
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 20e28d29..f9d092d9 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -1104,7 +1104,7 @@ class TestSystemDiskPartitions(PsutilTestCase):
if part.fstype == 'zfs':
break
else:
- self.fail("couldn't find any ZFS partition")
+ raise self.fail("couldn't find any ZFS partition")
else:
# No ZFS partitions on this system. Let's fake one.
fake_file = io.StringIO(u("nodev\tzfs\n"))
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 3e10fee8..a13c295d 100755
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -205,7 +205,7 @@ class TestMisc(PsutilTestCase):
continue
if (fun.__doc__ is not None and
'deprecated' not in fun.__doc__.lower()):
- self.fail('%r not in psutil.__all__' % name)
+ raise self.fail('%r not in psutil.__all__' % name)
# Import 'star' will break if __all__ is inconsistent, see:
# https://github.com/giampaolo/psutil/issues/656
@@ -738,8 +738,8 @@ class TestScripts(PsutilTestCase):
if name.endswith('.py'):
if 'test_' + os.path.splitext(name)[0] not in meths:
# self.assert_stdout(name)
- self.fail('no test defined for %r script'
- % os.path.join(SCRIPTS_DIR, name))
+ raise self.fail('no test defined for %r script'
+ % os.path.join(SCRIPTS_DIR, name))
@unittest.skipIf(not POSIX, "POSIX only")
def test_executable(self):
diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py
index 31b81926..edef7e7d 100755
--- a/psutil/tests/test_posix.py
+++ b/psutil/tests/test_posix.py
@@ -308,7 +308,7 @@ class TestSystemAPIs(PsutilTestCase):
if len(pids_ps) - len(pids_psutil) > 1:
difference = [x for x in pids_psutil if x not in pids_ps] + \
[x for x in pids_ps if x not in pids_psutil]
- self.fail("difference: " + str(difference))
+ raise self.fail("difference: " + str(difference))
# for some reason ifconfig -a does not report all interfaces
# returned by psutil
@@ -322,7 +322,7 @@ class TestSystemAPIs(PsutilTestCase):
if line.startswith(nic):
break
else:
- self.fail(
+ raise self.fail(
"couldn't find %s nic in 'ifconfig -a' output\n%s" % (
nic, output))
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index c9059e33..2a2af93c 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -261,10 +261,10 @@ class TestProcess(PsutilTestCase):
# using a tolerance of +/- 0.1 seconds.
# It will fail if the difference between the values is > 0.1s.
if (max([user_time, utime]) - min([user_time, utime])) > 0.1:
- self.fail("expected: %s, found: %s" % (utime, user_time))
+ raise self.fail("expected: %s, found: %s" % (utime, user_time))
if (max([kernel_time, ktime]) - min([kernel_time, ktime])) > 0.1:
- self.fail("expected: %s, found: %s" % (ktime, kernel_time))
+ raise self.fail("expected: %s, found: %s" % (ktime, kernel_time))
@unittest.skipIf(not HAS_PROC_CPU_NUM, "not supported")
def test_cpu_num(self):
@@ -285,8 +285,8 @@ class TestProcess(PsutilTestCase):
# It will fail if the difference between the values is > 2s.
difference = abs(create_time - now)
if difference > 2:
- self.fail("expected: %s, found: %s, difference: %s"
- % (now, create_time, difference))
+ raise self.fail("expected: %s, found: %s, difference: %s"
+ % (now, create_time, difference))
# make sure returned value can be pretty printed with strftime
time.strftime("%Y %m %d %H:%M:%S", time.localtime(p.create_time()))
@@ -983,7 +983,8 @@ class TestProcess(PsutilTestCase):
file.fd == fileobj.fileno():
break
else:
- self.fail("no file found; files=%s" % repr(p.open_files()))
+ raise self.fail("no file found; files=%s" % (
+ repr(p.open_files())))
self.assertEqual(normcase(file.path), normcase(fileobj.name))
if WINDOWS:
self.assertEqual(file.fd, -1)
@@ -1020,7 +1021,8 @@ class TestProcess(PsutilTestCase):
after = sum(p.num_ctx_switches())
if after > before:
return
- self.fail("num ctx switches still the same after 50.000 iterations")
+ raise self.fail(
+ "num ctx switches still the same after 50.000 iterations")
def test_ppid(self):
p = psutil.Process()
@@ -1495,7 +1497,7 @@ if POSIX and os.getuid() == 0:
except psutil.AccessDenied:
pass
else:
- self.fail("exception not raised")
+ raise self.fail("exception not raised")
@unittest.skipIf(1, "causes problem as root")
def test_zombie_process(self):
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index db2cb348..d98ec5c3 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -184,8 +184,7 @@ class TestProcessAPIs(PsutilTestCase):
# in case the process disappeared in meantime fail only
# if it is no longer in psutil.pids()
time.sleep(.1)
- if pid in psutil.pids():
- self.fail(pid)
+ self.assertIn(pid, psutil.pids())
pids = range(max(pids) + 5000, max(pids) + 6000)
for pid in pids:
self.assertFalse(psutil.pid_exists(pid), msg=pid)
@@ -280,10 +279,10 @@ class TestMemoryAPIs(PsutilTestCase):
self.assertIsInstance(value, (int, long))
if name != 'total':
if not value >= 0:
- self.fail("%r < 0 (%s)" % (name, value))
+ raise self.fail("%r < 0 (%s)" % (name, value))
if value > mem.total:
- self.fail("%r > total (total=%s, %s=%s)"
- % (name, mem.total, name, value))
+ raise self.fail("%r > total (total=%s, %s=%s)"
+ % (name, mem.total, name, value))
def test_swap_memory(self):
mem = psutil.swap_memory()
@@ -376,7 +375,7 @@ class TestCpuAPIs(PsutilTestCase):
t2 = sum(psutil.cpu_times())
if t2 > t1:
return
- self.fail("time remained the same")
+ raise self.fail("time remained the same")
def test_per_cpu_times(self):
# Check type, value >= 0, str().
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index ea694be4..55b6bc7b 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -114,7 +114,7 @@ class TestSystemAPIs(WindowsTestCase):
if "pseudo-interface" in nic.replace(' ', '-').lower():
continue
if nic not in out:
- self.fail(
+ raise self.fail(
"%r nic wasn't found in 'ipconfig /all' output" % nic)
def test_total_phymem(self):
@@ -168,11 +168,11 @@ class TestSystemAPIs(WindowsTestCase):
self.assertEqual(usage.free, wmi_free)
# 10 MB tollerance
if abs(usage.free - wmi_free) > 10 * 1024 * 1024:
- self.fail("psutil=%s, wmi=%s" % (
+ raise self.fail("psutil=%s, wmi=%s" % (
usage.free, wmi_free))
break
else:
- self.fail("can't find partition %s" % repr(ps_part))
+ raise self.fail("can't find partition %s" % repr(ps_part))
@retry_on_failure()
def test_disk_usage(self):
@@ -539,7 +539,7 @@ class TestProcessWMI(WindowsTestCase):
# returned instead.
wmi_usage = int(w.PageFileUsage)
if (vms != wmi_usage) and (vms != wmi_usage * 1024):
- self.fail("wmi=%s, psutil=%s" % (wmi_usage, vms))
+ raise self.fail("wmi=%s, psutil=%s" % (wmi_usage, vms))
def test_create_time(self):
w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0]