From 81e3a613df6af5d6ffefae8b617da81aa4007868 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 12 Apr 2023 12:37:54 +0200 Subject: fix some tests on BSD platforms --- psutil/tests/__init__.py | 2 +- psutil/tests/test_bsd.py | 1 + psutil/tests/test_contracts.py | 4 ++-- psutil/tests/test_posix.py | 12 ++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index e82bb38d..e6f0abc3 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -836,7 +836,7 @@ def create_exe(outpath, c_code=None): assert not os.path.exists(outpath), outpath if c_code: if not which("gcc"): - raise ValueError("gcc is not installed") + raise unittest.SkipTest("gcc is not installed") if isinstance(c_code, bool): # c_code is True c_code = textwrap.dedent( """ diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index 29ea384d..1ce54b19 100755 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -131,6 +131,7 @@ class BSDTestCase(PsutilTestCase): num = sysctl('hw.physmem') self.assertEqual(num, psutil.virtual_memory().total) + @unittest.skipIf(not which('ifconfig'), "ifconfig cmd not available") def test_net_if_stats(self): for name, stats in psutil.net_if_stats().items(): try: diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index b767e3eb..392eb69b 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -258,8 +258,8 @@ class TestSystemAPITypes(PsutilTestCase): self.assertIsInstance(disk.mountpoint, str) self.assertIsInstance(disk.fstype, str) self.assertIsInstance(disk.opts, str) - self.assertIsInstance(disk.maxfile, int) - self.assertIsInstance(disk.maxpath, int) + self.assertIsInstance(disk.maxfile, (int, type(None))) + self.assertIsInstance(disk.maxpath, (int, type(None))) @unittest.skipIf(SKIP_SYSCONS, "requires root") def test_net_connections(self): diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index a37899fd..774c7f3c 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -115,7 +115,10 @@ def ps_args(pid): field = "command" if AIX or SUNOS: field = "args" - return ps(field, pid) + out = ps(field, pid) + # observed on BSD + Github CI: '/usr/local/bin/python3 -E -O (python3.9)' + out = re.sub(r"\(python.*?\)$", "", out) + return out.strip() def ps_rss(pid): @@ -415,7 +418,12 @@ class TestSystemAPIs(PsutilTestCase): @retry_on_failure() def test_disk_usage(self): def df(device): - out = sh("df -k %s" % device).strip() + try: + out = sh("df -k %s" % device).strip() + except RuntimeError as err: + if "device busy" in str(err).lower(): + raise self.skipTest("df returned EBUSY") + raise line = out.split('\n')[1] fields = line.split() total = int(fields[1]) * 1024 -- cgit v1.2.1