Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: third_party/psutil/test/_linux.py

Issue 8919026: Remove psutil from tree, install via install-build-deps.sh (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Sort package list. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/psutil/test/_bsd.py ('k') | third_party/psutil/test/_osx.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # $Id: _linux.py 1142 2011-10-05 18:45:49Z g.rodola $
4 #
5 # Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
6 # Use of this source code is governed by a BSD-style license that can be
7 # found in the LICENSE file.
8
9 """Linux specific tests. These are implicitly run by test_psutil.py."""
10
11 import unittest
12 import subprocess
13 import sys
14
15 from test_psutil import sh
16 import psutil
17
18
19 class LinuxSpecificTestCase(unittest.TestCase):
20
21 def test_cached_phymem(self):
22 # test psutil.cached_phymem against "cached" column of free
23 # command line utility
24 p = subprocess.Popen("free", shell=1, stdout=subprocess.PIPE)
25 output = p.communicate()[0].strip()
26 if sys.version_info >= (3,):
27 output = str(output, sys.stdout.encoding)
28 free_cmem = int(output.split('\n')[1].split()[6])
29 psutil_cmem = psutil.cached_phymem() / 1024
30 self.assertEqual(free_cmem, psutil_cmem)
31
32 def test_phymem_buffers(self):
33 # test psutil.phymem_buffers against "buffers" column of free
34 # command line utility
35 p = subprocess.Popen("free", shell=1, stdout=subprocess.PIPE)
36 output = p.communicate()[0].strip()
37 if sys.version_info >= (3,):
38 output = str(output, sys.stdout.encoding)
39 free_cmem = int(output.split('\n')[1].split()[5])
40 psutil_cmem = psutil.phymem_buffers() / 1024
41 self.assertEqual(free_cmem, psutil_cmem)
42
43 def test_disks(self):
44 # test psutil.disk_usage() and psutil.disk_partitions()
45 # against "df -a"
46 def df(path):
47 out = sh('df -P -B 1 "%s"' % path).strip()
48 lines = out.split('\n')
49 lines.pop(0)
50 line = lines.pop(0)
51 dev, total, used, free = line.split()[:4]
52 if dev == 'none':
53 dev = ''
54 total, used, free = int(total), int(used), int(free)
55 return dev, total, used, free
56
57 for part in psutil.disk_partitions(all=False):
58 usage = psutil.disk_usage(part.mountpoint)
59 dev, total, used, free = df(part.mountpoint)
60 self.assertEqual(part.device, dev)
61 self.assertEqual(usage.total, total)
62 # 10 MB tollerance
63 if abs(usage.free - free) > 10 * 1024 * 1024:
64 self.fail("psutil=%s, df=%s" % usage.free, free)
65 if abs(usage.used - used) > 10 * 1024 * 1024:
66 self.fail("psutil=%s, df=%s" % usage.used, used)
67
68
69 if __name__ == '__main__':
70 test_suite = unittest.TestSuite()
71 test_suite.addTest(unittest.makeSuite(LinuxSpecificTestCase))
72 unittest.TextTestRunner(verbosity=2).run(test_suite)
OLDNEW
« no previous file with comments | « third_party/psutil/test/_bsd.py ('k') | third_party/psutil/test/_osx.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698