diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-01 22:44:28 +0200 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-01 22:44:28 +0200 |
| commit | e2ab08d50aab5c2cc4a92cdbee0e1325da470ddf (patch) | |
| tree | 3f089f1964d04b29403ccf1c62e67eeec87985bb | |
| parent | ed98d3ca2bdb2e4989de4fc9fdbea08274734d7b (diff) | |
| download | psutil-e2ab08d50aab5c2cc4a92cdbee0e1325da470ddf.tar.gz | |
fix different tests on openbsd
| -rw-r--r-- | psutil/tests/__init__.py | 5 | ||||
| -rwxr-xr-x | psutil/tests/test_bsd.py | 5 | ||||
| -rwxr-xr-x | psutil/tests/test_misc.py | 29 | ||||
| -rwxr-xr-x | scripts/fans.py | 3 | ||||
| -rwxr-xr-x | scripts/sensors.py | 4 |
5 files changed, 22 insertions, 24 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 0dbb003b..7023ab37 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -41,6 +41,8 @@ except ImportError: import psutil from psutil import POSIX from psutil import WINDOWS +from psutil import LINUX +from psutil import OSX from psutil._common import supports_ipv6 from psutil._compat import PY3 from psutil._compat import u @@ -80,7 +82,7 @@ __all__ = [ "HAS_CPU_AFFINITY", "HAS_CPU_FREQ", "HAS_ENVIRON", "HAS_PROC_IO_COUNTERS", "HAS_IONICE", "HAS_MEMORY_MAPS", "HAS_PROC_CPU_NUM", "HAS_RLIMIT", "HAS_SENSORS_BATTERY", "HAS_BATTERY""HAS_SENSORS_FANS", - "HAS_SENSORS_TEMPERATURES", + "HAS_SENSORS_TEMPERATURES", "HAS_MEMORY_FULL_INFO", # classes 'ThreadTask' # test utils @@ -158,6 +160,7 @@ HAS_CPU_FREQ = hasattr(psutil, "cpu_freq") HAS_ENVIRON = hasattr(psutil.Process, "environ") HAS_PROC_IO_COUNTERS = hasattr(psutil.Process, "io_counters") HAS_IONICE = hasattr(psutil.Process, "ionice") +HAS_MEMORY_FULL_INFO = LINUX or OSX or WINDOWS HAS_MEMORY_MAPS = hasattr(psutil.Process, "memory_maps") HAS_PROC_CPU_NUM = hasattr(psutil.Process, "cpu_num") HAS_RLIMIT = hasattr(psutil.Process, "rlimit") diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index 0f98a3c6..8fd7fe1d 100755 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -136,8 +136,9 @@ class BSDSpecificTestCase(unittest.TestCase): pass else: self.assertEqual(stats.isup, 'RUNNING' in out, msg=out) - self.assertEqual(stats.mtu, - int(re.findall('mtu (\d+)', out)[0])) + if "mtu" in out: + self.assertEqual(stats.mtu, + int(re.findall('mtu (\d+)', out)[0])) # ===================================================================== diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py index b24212a6..cb22c5fc 100755 --- a/psutil/tests/test_misc.py +++ b/psutil/tests/test_misc.py @@ -22,7 +22,6 @@ import stat import sys from psutil import LINUX -from psutil import OSX from psutil import POSIX from psutil import WINDOWS from psutil._common import memoize @@ -36,7 +35,11 @@ from psutil.tests import create_proc_children_pair from psutil.tests import create_sockets from psutil.tests import get_free_port from psutil.tests import get_test_subprocess +from psutil.tests import HAS_MEMORY_FULL_INFO from psutil.tests import HAS_MEMORY_MAPS +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 importlib from psutil.tests import mock from psutil.tests import reap_children @@ -459,7 +462,7 @@ class TestScripts(unittest.TestCase): def test_pmap(self): self.assert_stdout('pmap.py', args=str(os.getpid())) - @unittest.skipIf(not OSX or WINDOWS or LINUX, "platform not supported") + @unittest.skipIf(not HAS_MEMORY_FULL_INFO, "not supported") def test_procsmem(self): self.assert_stdout('procsmem.py') @@ -486,30 +489,20 @@ class TestScripts(unittest.TestCase): def test_cpu_distribution(self): self.assert_syntax('cpu_distribution.py') + @unittest.skipIf(not HAS_SENSORS_TEMPERATURES, "not supported") @unittest.skipIf(TRAVIS, "unreliable on TRAVIS") def test_temperatures(self): - if hasattr(psutil, "sensors_temperatures") and \ - psutil.sensors_temperatures(): - self.assert_stdout('temperatures.py') - else: - self.assert_syntax('temperatures.py') + self.assert_stdout('temperatures.py') + @unittest.skipIf(not HAS_SENSORS_FANS, "not supported") @unittest.skipIf(TRAVIS, "unreliable on TRAVIS") def test_fans(self): - if hasattr(psutil, "sensors_fans") and psutil.sensors_fans(): - self.assert_stdout('fans.py') - else: - self.assert_syntax('fans.py') + self.assert_stdout('fans.py') + @unittest.skipIf(not HAS_SENSORS_BATTERY, "not supported") def test_battery(self): - if hasattr(psutil, "sensors_battery") and \ - psutil.sensors_battery() is not None: - self.assert_stdout('battery.py') - else: - self.assert_syntax('battery.py') + self.assert_stdout('battery.py') - @unittest.skipIf(APPVEYOR or TRAVIS, "unreliable on CI") - @unittest.skipIf(OSX, "platform not supported") def test_sensors(self): self.assert_stdout('sensors.py') diff --git a/scripts/fans.py b/scripts/fans.py index e302aec5..7a0ccf91 100755 --- a/scripts/fans.py +++ b/scripts/fans.py @@ -23,7 +23,8 @@ def main(): return sys.exit("platform not supported") fans = psutil.sensors_fans() if not fans: - return sys.exit("no fans detected") + print("no fans detected") + return for name, entries in fans.items(): print(name) for entry in entries: diff --git a/scripts/sensors.py b/scripts/sensors.py index e3301ebf..bbf3ac90 100755 --- a/scripts/sensors.py +++ b/scripts/sensors.py @@ -30,7 +30,6 @@ Battery: """ from __future__ import print_function -import sys import psutil @@ -56,7 +55,8 @@ def main(): battery = None if not any((temps, fans, battery)): - return sys.exit("can't read any temperature, fans or battery info") + print("can't read any temperature, fans or battery info") + return names = set(list(temps.keys()) + list(fans.keys())) for name in names: |
