OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # $Id: _posix.py 1142 2011-10-05 18:45:49Z g.rodola $ | 3 # $Id: _posix.py 1204 2011-10-24 19:19:01Z g.rodola $ |
4 # | 4 # |
5 # Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. | 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 | 6 # Use of this source code is governed by a BSD-style license that can be |
7 # found in the LICENSE file. | 7 # found in the LICENSE file. |
8 | 8 |
9 """POSIX specific tests. These are implicitly run by test_psutil.py.""" | 9 """POSIX specific tests. These are implicitly run by test_psutil.py.""" |
10 | 10 |
11 import unittest | 11 import unittest |
12 import subprocess | 12 import subprocess |
13 import time | 13 import time |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 pids_ps = [] | 127 pids_ps = [] |
128 for pid in output.split('\n'): | 128 for pid in output.split('\n'): |
129 if pid: | 129 if pid: |
130 pids_ps.append(int(pid.strip())) | 130 pids_ps.append(int(pid.strip())) |
131 # remove ps subprocess pid which is supposed to be dead in meantime | 131 # remove ps subprocess pid which is supposed to be dead in meantime |
132 pids_ps.remove(p.pid) | 132 pids_ps.remove(p.pid) |
133 pids_psutil = psutil.get_pid_list() | 133 pids_psutil = psutil.get_pid_list() |
134 pids_ps.sort() | 134 pids_ps.sort() |
135 pids_psutil.sort() | 135 pids_psutil.sort() |
136 | 136 |
| 137 # on OSX ps doesn't show pid 0 |
| 138 if OSX and 0 not in pids_ps: |
| 139 pids_ps.insert(0, 0) |
| 140 |
137 if pids_ps != pids_psutil: | 141 if pids_ps != pids_psutil: |
138 difference = [x for x in pids_psutil if x not in pids_ps] + \ | 142 difference = [x for x in pids_psutil if x not in pids_ps] + \ |
139 [x for x in pids_ps if x not in pids_psutil] | 143 [x for x in pids_ps if x not in pids_psutil] |
140 self.fail("difference: " + str(difference)) | 144 self.fail("difference: " + str(difference)) |
| 145 |
| 146 def test_nic_names(self): |
| 147 p = subprocess.Popen("ifconfig -a", shell=1, stdout=subprocess.PIPE) |
| 148 output = p.communicate()[0].strip() |
| 149 if sys.version_info >= (3,): |
| 150 output = str(output, sys.stdout.encoding) |
| 151 for nic in psutil.network_io_counters(pernic=True).keys(): |
| 152 for line in output.split(): |
| 153 if line.startswith(nic): |
| 154 break |
| 155 else: |
| 156 self.fail("couldn't find %s nic in 'ifconfig -a' output" % nic) |
141 | 157 |
142 | 158 |
143 if __name__ == '__main__': | 159 if __name__ == '__main__': |
144 test_suite = unittest.TestSuite() | 160 test_suite = unittest.TestSuite() |
145 test_suite.addTest(unittest.makeSuite(PosixSpecificTestCase)) | 161 test_suite.addTest(unittest.makeSuite(PosixSpecificTestCase)) |
146 unittest.TextTestRunner(verbosity=2).run(test_suite) | 162 unittest.TextTestRunner(verbosity=2).run(test_suite) |
147 | 163 |
148 | 164 |
OLD | NEW |