test_sunos.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 psutil
  8. from psutil import SUNOS
  9. from psutil.tests import PsutilTestCase
  10. from psutil.tests import pytest
  11. from psutil.tests import sh
  12. @pytest.mark.skipif(not SUNOS, reason="SUNOS only")
  13. class SunOSSpecificTestCase(PsutilTestCase):
  14. def test_swap_memory(self):
  15. out = sh(f"env PATH=/usr/sbin:/sbin:{os.environ['PATH']} swap -l")
  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. assert psutil_swap.total == total
  27. assert psutil_swap.used == used
  28. assert psutil_swap.free == free
  29. def test_cpu_count(self):
  30. out = sh("/usr/sbin/psrinfo")
  31. assert psutil.cpu_count() == len(out.split('\n'))