From df3d5271b9153c6510c6178194bb33cbd1a7b732 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 17 Apr 2015 09:15:44 +0200 Subject: swap: fix finding the 'swap' utility on SunOS This is a bit of a kludge, but allows to find the swap utility when invoced by normal users which shouldn't have the sbin paths in PATH by default. One can argue the paths should be appended instead of prepended, but I doubt whether one wants to use another swap utility, since the code relies on its output format. --- test/_sunos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/_sunos.py') diff --git a/test/_sunos.py b/test/_sunos.py index 7fdc50b6..b1943373 100644 --- a/test/_sunos.py +++ b/test/_sunos.py @@ -7,6 +7,7 @@ """Sun OS specific tests. These are implicitly run by test_psutil.py.""" import sys +import os from test_psutil import sh, unittest import psutil @@ -15,7 +16,7 @@ import psutil class SunOSSpecificTestCase(unittest.TestCase): def test_swap_memory(self): - out = sh('swap -l -k') + out = sh('env PATH=/usr/sbin:/sbin:%s swap -l -k' % os.environ['PATH']) lines = out.strip().split('\n')[1:] if not lines: raise ValueError('no swap device(s) configured') -- cgit v1.2.1 From d9f580538224d63f1a1273854293e2c87b0144dd Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 4 Jun 2015 03:37:02 +0200 Subject: #629: 'skip' platorm specific tests if we're on another platform (instead of failing); rename test_main to main otherwise pytest / nose will execute it as a test case --- test/_sunos.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/_sunos.py') diff --git a/test/_sunos.py b/test/_sunos.py index b1943373..3d54ccd8 100644 --- a/test/_sunos.py +++ b/test/_sunos.py @@ -9,10 +9,11 @@ import sys import os -from test_psutil import sh, unittest +from test_psutil import SUNOS, sh, unittest import psutil +@unittest.skipUnless(SUNOS, "not a SunOS system") class SunOSSpecificTestCase(unittest.TestCase): def test_swap_memory(self): @@ -36,12 +37,12 @@ class SunOSSpecificTestCase(unittest.TestCase): self.assertEqual(psutil_swap.free, free) -def test_main(): +def main(): test_suite = unittest.TestSuite() test_suite.addTest(unittest.makeSuite(SunOSSpecificTestCase)) result = unittest.TextTestRunner(verbosity=2).run(test_suite) return result.wasSuccessful() if __name__ == '__main__': - if not test_main(): + if not main(): sys.exit(1) -- cgit v1.2.1 From 870e00f71c15ef39f8259ff16b682e495ea5d6eb Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 4 Jun 2015 03:42:11 +0200 Subject: #629: rename test/_linux.py (and others) to test/test_pslinux.py in order to ease test discovery for nose and pytest --- test/_sunos.py | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 test/_sunos.py (limited to 'test/_sunos.py') diff --git a/test/_sunos.py b/test/_sunos.py deleted file mode 100644 index 3d54ccd8..00000000 --- a/test/_sunos.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Sun OS specific tests. These are implicitly run by test_psutil.py.""" - -import sys -import os - -from test_psutil import SUNOS, sh, unittest -import psutil - - -@unittest.skipUnless(SUNOS, "not a SunOS system") -class SunOSSpecificTestCase(unittest.TestCase): - - def test_swap_memory(self): - out = sh('env PATH=/usr/sbin:/sbin:%s swap -l -k' % os.environ['PATH']) - lines = out.strip().split('\n')[1:] - if not lines: - raise ValueError('no swap device(s) configured') - total = free = 0 - for line in lines: - line = line.split() - t, f = line[-2:] - t = t.replace('K', '') - f = f.replace('K', '') - total += int(int(t) * 1024) - free += int(int(f) * 1024) - used = total - free - - psutil_swap = psutil.swap_memory() - self.assertEqual(psutil_swap.total, total) - self.assertEqual(psutil_swap.used, used) - self.assertEqual(psutil_swap.free, free) - - -def main(): - test_suite = unittest.TestSuite() - test_suite.addTest(unittest.makeSuite(SunOSSpecificTestCase)) - result = unittest.TextTestRunner(verbosity=2).run(test_suite) - return result.wasSuccessful() - -if __name__ == '__main__': - if not main(): - sys.exit(1) -- cgit v1.2.1 From 931432d83e203e757d0c6668c02386d7f762ea66 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 4 Jun 2015 03:59:48 +0200 Subject: Revert "#629: rename test/_linux.py (and others) to test/test_pslinux.py in order to ease test discovery for nose and pytest" This reverts commit 870e00f71c15ef39f8259ff16b682e495ea5d6eb. --- test/_sunos.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/_sunos.py (limited to 'test/_sunos.py') diff --git a/test/_sunos.py b/test/_sunos.py new file mode 100644 index 00000000..3d54ccd8 --- /dev/null +++ b/test/_sunos.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Sun OS specific tests. These are implicitly run by test_psutil.py.""" + +import sys +import os + +from test_psutil import SUNOS, sh, unittest +import psutil + + +@unittest.skipUnless(SUNOS, "not a SunOS system") +class SunOSSpecificTestCase(unittest.TestCase): + + def test_swap_memory(self): + out = sh('env PATH=/usr/sbin:/sbin:%s swap -l -k' % os.environ['PATH']) + lines = out.strip().split('\n')[1:] + if not lines: + raise ValueError('no swap device(s) configured') + total = free = 0 + for line in lines: + line = line.split() + t, f = line[-2:] + t = t.replace('K', '') + f = f.replace('K', '') + total += int(int(t) * 1024) + free += int(int(f) * 1024) + used = total - free + + psutil_swap = psutil.swap_memory() + self.assertEqual(psutil_swap.total, total) + self.assertEqual(psutil_swap.used, used) + self.assertEqual(psutil_swap.free, free) + + +def main(): + test_suite = unittest.TestSuite() + test_suite.addTest(unittest.makeSuite(SunOSSpecificTestCase)) + result = unittest.TextTestRunner(verbosity=2).run(test_suite) + return result.wasSuccessful() + +if __name__ == '__main__': + if not main(): + sys.exit(1) -- cgit v1.2.1