Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 #!/usr/bin/env python
3 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """Sun OS specific tests. These are implicitly run by test_psutil.py."""
9 import psutil
10 from test_psutil import *
13 class SunOSSpecificTestCase(unittest.TestCase):
15 def test_swap_memory(self):
16 out = sh('swap -l -k')
17 lines = out.strip().split('\n')[1:]
18 if not lines:
19 raise ValueError('no swap device(s) configured')
20 total = free = 0
21 for line in lines:
22 line = line.split()
23 t, f = line[-2:]
24 t = t.replace('K', '')
25 f = f.replace('K', '')
26 total += int(int(t) * 1024)
27 free += int(int(f) * 1024)
28 used = total - free
30 psutil_swap = psutil.swap_memory()
31 self.assertEqual(psutil_swap.total, total)
32 self.assertEqual(psutil_swap.used, used)
33 self.assertEqual(psutil_swap.free, free)
36 def test_main():
37 test_suite = unittest.TestSuite()
38 test_suite.addTest(unittest.makeSuite(SunOSSpecificTestCase))
39 result = unittest.TextTestRunner(verbosity=2).run(test_suite)
40 return result.wasSuccessful()
42 if __name__ == '__main__':
43 if not test_main():
44 sys.exit(1)