OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for subprocess2.py.""" | 6 """Unit tests for subprocess2.py.""" |
7 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 'stderr': subprocess2.STDOUT, | 129 'stderr': subprocess2.STDOUT, |
130 } | 130 } |
131 self.assertEquals(expected, results) | 131 self.assertEquals(expected, results) |
132 | 132 |
133 def test_timeout(self): | 133 def test_timeout(self): |
134 # It'd be better to not discard stdout. | 134 # It'd be better to not discard stdout. |
135 out, returncode = subprocess2.call( | 135 out, returncode = subprocess2.call( |
136 self.exe + ['--sleep', '--stdout'], | 136 self.exe + ['--sleep', '--stdout'], |
137 timeout=0.01, | 137 timeout=0.01, |
138 stdout=subprocess2.PIPE) | 138 stdout=subprocess2.PIPE) |
139 self.assertEquals(-9, returncode) | 139 self.assertEquals(subprocess2.TIMED_OUT, returncode) |
140 self.assertEquals(['', None], out) | 140 self.assertEquals(['', None], out) |
141 | 141 |
142 def test_void(self): | 142 def test_void(self): |
143 out = subprocess2.check_output( | 143 out = subprocess2.check_output( |
144 self.exe + ['--stdout', '--stderr'], | 144 self.exe + ['--stdout', '--stderr'], |
145 stdout=subprocess2.VOID) | 145 stdout=subprocess2.VOID) |
146 self.assertEquals(None, out) | 146 self.assertEquals(None, out) |
147 out = subprocess2.check_output( | 147 out = subprocess2.check_output( |
148 self.exe + ['--stdout', '--stderr'], | 148 self.exe + ['--stdout', '--stderr'], |
149 universal_newlines=True, | 149 universal_newlines=True, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 do('CCC') | 196 do('CCC') |
197 if options.sleep: | 197 if options.sleep: |
198 time.sleep(10) | 198 time.sleep(10) |
199 return options.return_value | 199 return options.return_value |
200 | 200 |
201 | 201 |
202 if __name__ == '__main__': | 202 if __name__ == '__main__': |
203 if len(sys.argv) > 1 and sys.argv[1] == '--child': | 203 if len(sys.argv) > 1 and sys.argv[1] == '--child': |
204 sys.exit(child_main(sys.argv[2:])) | 204 sys.exit(child_main(sys.argv[2:])) |
205 unittest.main() | 205 unittest.main() |
OLD | NEW |