From d50ceccbaf30b334d7f986bf47efa02edfd42692 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 27 Jan 2020 17:54:04 +0100 Subject: refactor some tests --- appveyor.yml | 8 +------- psutil/_pslinux.py | 4 +--- psutil/tests/test_memory_leaks.py | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a99670e3..b38cbf1b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -99,12 +99,6 @@ only_commits: - psutil/_psutil_windows.* - psutil/_pswindows.py - psutil/arch/windows/* - - psutil/tests/__init__.py - - psutil/tests/__main__.py - - psutil/tests/test_memory_leaks.py - - psutil/tests/test_misc.py - - psutil/tests/test_process.py - - psutil/tests/test_system.py - - psutil/tests/test_windows.py + - psutil/tests/* - scripts/* - setup.py diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index d8f8ed5c..06935111 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1213,7 +1213,7 @@ def sensors_temperatures(): current = float(cat(path)) / 1000.0 path = os.path.join(os.path.dirname(base), 'name') unit_name = cat(path, binary=False) - except (IOError, OSError, ValueError) as err: + except (IOError, OSError, ValueError): # A lot of things can go wrong here, so let's just skip the # whole entry. Sure thing is Linux's /sys/class/hwmon really # is a stinky broken mess. @@ -1222,8 +1222,6 @@ def sensors_temperatures(): # https://github.com/giampaolo/psutil/issues/1129 # https://github.com/giampaolo/psutil/issues/1245 # https://github.com/giampaolo/psutil/issues/1323 - warnings.warn("ignoring %r for file %r" % (err, path), - RuntimeWarning) continue high = cat(base + '_max', fallback=None) diff --git a/psutil/tests/test_memory_leaks.py b/psutil/tests/test_memory_leaks.py index ba75eef0..132a0b07 100755 --- a/psutil/tests/test_memory_leaks.py +++ b/psutil/tests/test_memory_leaks.py @@ -23,6 +23,7 @@ import time import psutil import psutil._common +from psutil import FREEBSD from psutil import LINUX from psutil import MACOS from psutil import OPENBSD @@ -32,12 +33,13 @@ from psutil import WINDOWS from psutil._common import bytes2human from psutil._compat import ProcessLookupError from psutil._compat import xrange +from psutil.tests import CIRRUS from psutil.tests import create_sockets from psutil.tests import get_test_subprocess from psutil.tests import HAS_CPU_AFFINITY from psutil.tests import HAS_CPU_FREQ -from psutil.tests import HAS_GETLOADAVG from psutil.tests import HAS_ENVIRON +from psutil.tests import HAS_GETLOADAVG from psutil.tests import HAS_IONICE from psutil.tests import HAS_MEMORY_MAPS from psutil.tests import HAS_NET_IO_COUNTERS @@ -365,14 +367,14 @@ class TestProcessObjectLeaks(TestMemLeak): self.execute(cext.proc_info, os.getpid()) +@unittest.skipIf(not WINDOWS, "WINDOWS only") class TestProcessDualImplementation(TestMemLeak): - if WINDOWS: - def test_cmdline_peb_true(self): - self.execute(cext.proc_cmdline, os.getpid(), use_peb=True) + def test_cmdline_peb_true(self): + self.execute(cext.proc_cmdline, os.getpid(), use_peb=True) - def test_cmdline_peb_false(self): - self.execute(cext.proc_cmdline, os.getpid(), use_peb=False) + def test_cmdline_peb_false(self): + self.execute(cext.proc_cmdline, os.getpid(), use_peb=False) class TestTerminatedProcessLeaks(TestProcessObjectLeaks): @@ -485,8 +487,7 @@ class TestModuleFunctionsLeaks(TestMemLeak): self.execute(psutil.virtual_memory) # TODO: remove this skip when this gets fixed - @unittest.skipIf(SUNOS, - "worthless on SUNOS (uses a subprocess)") + @unittest.skipIf(SUNOS, "worthless on SUNOS (uses a subprocess)") def test_swap_memory(self): self.execute(psutil.swap_memory) @@ -519,14 +520,14 @@ class TestModuleFunctionsLeaks(TestMemLeak): # --- net - @unittest.skipIf(TRAVIS and MACOS, "false positive on travis") + @unittest.skipIf(TRAVIS and MACOS, "false positive on TRAVIS + MACOS") + @unittest.skipIf(CIRRUS and FREEBSD, "false positive on CIRRUS + FREEBSD") @skip_if_linux() @unittest.skipIf(not HAS_NET_IO_COUNTERS, 'not supported') def test_net_io_counters(self): self.execute(psutil.net_io_counters, nowrap=False) - @unittest.skipIf(LINUX, - "worthless on Linux (pure python)") + @skip_if_linux() @unittest.skipIf(MACOS and os.getuid() != 0, "need root access") def test_net_connections(self): with create_sockets(): @@ -564,7 +565,6 @@ class TestModuleFunctionsLeaks(TestMemLeak): def test_boot_time(self): self.execute(psutil.boot_time) - # XXX - on Windows this produces a false positive @unittest.skipIf(WINDOWS, "XXX produces a false positive on Windows") def test_users(self): self.execute(psutil.users) -- cgit v1.2.1