OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import psutil | 5 import chrome_helper |
6 | |
7 import path_resolver | 6 import path_resolver |
8 | 7 |
9 | 8 |
10 def VerifyProcesses(processes): | 9 def VerifyProcesses(processes): |
11 """Verifies that the running processes match the expectation dictionaries. | 10 """Verifies that the running processes match the expectation dictionaries. |
12 | 11 |
13 This method will throw an AssertionError if process state doesn't match the | 12 This method will throw an AssertionError if process state doesn't match the |
14 provided expectation. | 13 provided expectation. |
15 | 14 |
16 Args: | 15 Args: |
17 processes: A dictionary whose keys are paths to processes and values are | 16 processes: A dictionary whose keys are paths to processes and values are |
18 expectation dictionaries. An expectation dictionary is a dictionary with | 17 expectation dictionaries. An expectation dictionary is a dictionary with |
19 the following key and value: | 18 the following key and value: |
20 'running' a boolean indicating whether the process should be | 19 'running' a boolean indicating whether the process should be |
21 running. | 20 running. |
22 """ | 21 """ |
23 # Create a list of paths of all running processes. | 22 # Create a list of paths of all running processes. |
24 running_process_paths = [] | 23 running_process_paths = [] |
Mathieu
2013/08/30 19:34:10
running_process_paths = map(lambda t: t[1],
sukolsak
2013/08/30 20:06:07
Done.
| |
25 for process in psutil.process_iter(): | 24 for _, process_path in chrome_helper.GetProcessIDAndPathPairs(): |
26 try: | 25 running_process_paths.append(process_path) |
27 running_process_paths.append(process.exe) | |
28 except psutil.AccessDenied: | |
29 pass | |
30 | 26 |
31 for process_path, expectation in processes.iteritems(): | 27 for process_path, expectation in processes.iteritems(): |
32 process_resolved_path = path_resolver.ResolvePath(process_path) | 28 process_resolved_path = path_resolver.ResolvePath(process_path) |
33 is_running = process_resolved_path in running_process_paths | 29 is_running = process_resolved_path in running_process_paths |
34 assert expectation['running'] == is_running, \ | 30 assert expectation['running'] == is_running, \ |
35 ('Process %s is running' % process_path) if is_running else \ | 31 ('Process %s is running' % process_path) if is_running else \ |
36 ('Process %s is not running' % process_path) | 32 ('Process %s is not running' % process_path) |
OLD | NEW |