OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # $Id: _linux.py 707 2010-10-19 18:16:08Z g.rodola $ |
| 4 # |
| 5 |
| 6 import unittest |
| 7 import subprocess |
| 8 import sys |
| 9 |
| 10 import psutil |
| 11 |
| 12 |
| 13 class LinuxSpecificTestCase(unittest.TestCase): |
| 14 |
| 15 def test_cached_phymem(self): |
| 16 # test psutil.cached_phymem against "cached" column of free |
| 17 # command line utility |
| 18 p = subprocess.Popen("free", shell=1, stdout=subprocess.PIPE) |
| 19 output = p.communicate()[0].strip() |
| 20 if sys.version_info >= (3,): |
| 21 output = str(output, sys.stdout.encoding) |
| 22 free_cmem = int(output.split('\n')[1].split()[6]) |
| 23 psutil_cmem = psutil.cached_phymem() / 1024 |
| 24 self.assertEqual(free_cmem, psutil_cmem) |
| 25 |
| 26 def test_phymem_buffers(self): |
| 27 # test psutil.phymem_buffers against "buffers" column of free |
| 28 # command line utility |
| 29 p = subprocess.Popen("free", shell=1, stdout=subprocess.PIPE) |
| 30 output = p.communicate()[0].strip() |
| 31 if sys.version_info >= (3,): |
| 32 output = str(output, sys.stdout.encoding) |
| 33 free_cmem = int(output.split('\n')[1].split()[5]) |
| 34 psutil_cmem = psutil.phymem_buffers() / 1024 |
| 35 self.assertEqual(free_cmem, psutil_cmem) |
| 36 |
| 37 |
| 38 if __name__ == '__main__': |
| 39 test_suite = unittest.TestSuite() |
| 40 test_suite.addTest(unittest.makeSuite(LinuxSpecificTestCase)) |
| 41 unittest.TextTestRunner(verbosity=2).run(test_suite) |
| 42 |
| 43 |
| 44 |
| 45 |
OLD | NEW |