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 logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import sys | 11 import sys |
12 import time | 12 import time |
13 import unittest | 13 import unittest |
14 | 14 |
| 15 try: |
| 16 import fcntl |
| 17 except ImportError: |
| 18 fcntl = None |
| 19 |
15 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
16 sys.path.insert(0, ROOT_DIR) | 21 sys.path.insert(0, ROOT_DIR) |
17 | 22 |
18 import subprocess2 | 23 import subprocess2 |
19 | 24 |
20 # Method could be a function | 25 # Method could be a function |
21 # pylint: disable=R0201 | 26 # pylint: disable=R0201 |
22 | 27 |
23 | 28 |
24 def convert_to_crlf(string): | 29 def convert_to_crlf(string): |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 self.fail() | 180 self.fail() |
176 except TypeError: | 181 except TypeError: |
177 pass | 182 pass |
178 | 183 |
179 | 184 |
180 class S2Test(unittest.TestCase): | 185 class S2Test(unittest.TestCase): |
181 def setUp(self): | 186 def setUp(self): |
182 super(S2Test, self).setUp() | 187 super(S2Test, self).setUp() |
183 self.exe_path = __file__ | 188 self.exe_path = __file__ |
184 self.exe = [sys.executable, self.exe_path, '--child'] | 189 self.exe = [sys.executable, self.exe_path, '--child'] |
| 190 self.states = {} |
| 191 if fcntl: |
| 192 for v in (sys.stdin, sys.stdout, sys.stderr): |
| 193 fileno = v.fileno() |
| 194 self.states[fileno] = fcntl.fcntl(fileno, fcntl.F_GETFL) |
| 195 |
| 196 def tearDown(self): |
| 197 for fileno, fl in self.states.iteritems(): |
| 198 self.assertEquals(fl, fcntl.fcntl(fileno, fcntl.F_GETFL)) |
| 199 super(S2Test, self).tearDown() |
185 | 200 |
186 def _run_test(self, function): | 201 def _run_test(self, function): |
187 """Runs tests in 6 combinations: | 202 """Runs tests in 6 combinations: |
188 - LF output with universal_newlines=False | 203 - LF output with universal_newlines=False |
189 - CR output with universal_newlines=False | 204 - CR output with universal_newlines=False |
190 - CRLF output with universal_newlines=False | 205 - CRLF output with universal_newlines=False |
191 - LF output with universal_newlines=True | 206 - LF output with universal_newlines=True |
192 - CR output with universal_newlines=True | 207 - CR output with universal_newlines=True |
193 - CRLF output with universal_newlines=True | 208 - CRLF output with universal_newlines=True |
194 | 209 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 return options.return_value | 450 return options.return_value |
436 | 451 |
437 | 452 |
438 if __name__ == '__main__': | 453 if __name__ == '__main__': |
439 logging.basicConfig(level= | 454 logging.basicConfig(level= |
440 [logging.WARNING, logging.INFO, logging.DEBUG][ | 455 [logging.WARNING, logging.INFO, logging.DEBUG][ |
441 min(2, sys.argv.count('-v'))]) | 456 min(2, sys.argv.count('-v'))]) |
442 if len(sys.argv) > 1 and sys.argv[1] == '--child': | 457 if len(sys.argv) > 1 and sys.argv[1] == '--child': |
443 sys.exit(child_main(sys.argv[2:])) | 458 sys.exit(child_main(sys.argv[2:])) |
444 unittest.main() | 459 unittest.main() |
OLD | NEW |