test_sunos.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Sun OS specific tests."""
  6. import os
  7. import unittest
  8. import psutil
  9. from psutil import SUNOS
  10. from psutil.tests import PsutilTestCase
  11. from psutil.tests import sh
  12. @unittest.skipIf(not SUNOS, "SUNOS only")
  13. class SunOSSpecificTestCase(PsutilTestCase):
  14. def test_swap_memory(self):
  15. out = sh('env PATH=/usr/sbin:/sbin:%s swap -l' % os.environ['PATH'])
  16. lines = out.strip().split('\n')[1:]
  17. if not lines:
  18. raise ValueError('no swap device(s) configured')
  19. total = free = 0
  20. for line in lines:
  21. fields = line.split()
  22. total = int(fields[3]) * 512
  23. free = int(fields[4]) * 512
  24. used = total - free
  25. psutil_swap = psutil.swap_memory()
  26. self.assertEqual(psutil_swap.total, total)
  27. self.assertEqual(psutil_swap.used, used)
  28. self.assertEqual(psutil_swap.free, free)
  29. def test_cpu_count(self):
  30. out = sh("/usr/sbin/psrinfo")
  31. self.assertEqual(psutil.cpu_count(), len(out.split('\n')))
  32. if __name__ == '__main__':
  33. from psutil.tests.runner import run_from_name
  34. run_from_name(__file__)