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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 self.assertEquals(expected, results) | 118 self.assertEquals(expected, results) |
119 | 119 |
120 def test_check_output_defaults(self): | 120 def test_check_output_defaults(self): |
121 results = self._fake_call() | 121 results = self._fake_call() |
122 # It's discarding 'stderr' because it assumes stderr=subprocess2.STDOUT but | 122 # It's discarding 'stderr' because it assumes stderr=subprocess2.STDOUT but |
123 # fake_call() doesn't 'implement' that. | 123 # fake_call() doesn't 'implement' that. |
124 self.assertEquals('stdout', subprocess2.check_output(['foo'], a=True)) | 124 self.assertEquals('stdout', subprocess2.check_output(['foo'], a=True)) |
125 expected = { | 125 expected = { |
126 'args': ['foo'], | 126 'args': ['foo'], |
127 'a':True, | 127 'a':True, |
| 128 'stdin': subprocess2.VOID, |
128 'stdout': subprocess2.PIPE, | 129 'stdout': subprocess2.PIPE, |
129 'stderr': subprocess2.STDOUT, | 130 'stderr': subprocess2.STDOUT, |
130 } | 131 } |
131 self.assertEquals(expected, results) | 132 self.assertEquals(expected, results) |
132 | 133 |
133 def test_timeout(self): | 134 def test_timeout(self): |
134 # It'd be better to not discard stdout. | 135 # It'd be better to not discard stdout. |
135 out, returncode = subprocess2.call( | 136 out, returncode = subprocess2.call( |
136 self.exe + ['--sleep', '--stdout'], | 137 self.exe + ['--sleep', '--stdout'], |
137 timeout=0.01, | 138 timeout=0.01, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 do('CCC') | 197 do('CCC') |
197 if options.sleep: | 198 if options.sleep: |
198 time.sleep(10) | 199 time.sleep(10) |
199 return options.return_value | 200 return options.return_value |
200 | 201 |
201 | 202 |
202 if __name__ == '__main__': | 203 if __name__ == '__main__': |
203 if len(sys.argv) > 1 and sys.argv[1] == '--child': | 204 if len(sys.argv) > 1 and sys.argv[1] == '--child': |
204 sys.exit(child_main(sys.argv[2:])) | 205 sys.exit(child_main(sys.argv[2:])) |
205 unittest.main() | 206 unittest.main() |
OLD | NEW |