Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: tests/subprocess2_test.py

Issue 8695003: Add more subprocess2 tests with stderr=subproces2.STDOUT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fix comment Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 (out, err), code = subprocess2.communicate( 248 (out, err), code = subprocess2.communicate(
249 e + ['--stdout', '--stderr'], 249 e + ['--stdout', '--stderr'],
250 stdout=subprocess2.PIPE, 250 stdout=subprocess2.PIPE,
251 stderr=subprocess2.VOID, 251 stderr=subprocess2.VOID,
252 universal_newlines=un) 252 universal_newlines=un)
253 self.assertEquals(c('A\nBB\nCCC\n'), out) 253 self.assertEquals(c('A\nBB\nCCC\n'), out)
254 self.assertEquals(None, err) 254 self.assertEquals(None, err)
255 self.assertEquals(0, code) 255 self.assertEquals(0, code)
256 self._run_test(fn) 256 self._run_test(fn)
257 257
258 def test_check_output_redirect_stderr_to_stdout_pipe(self):
259 def fn(c, e, un):
260 (out, err), code = subprocess2.communicate(
261 e + ['--stderr'],
262 stdout=subprocess2.PIPE,
263 stderr=subprocess2.STDOUT,
264 universal_newlines=un)
265 # stderr output into stdout.
266 self.assertEquals(c('a\nbb\nccc\n'), out)
267 self.assertEquals(None, err)
268 self.assertEquals(0, code)
269 self._run_test(fn)
270
271 def test_check_output_redirect_stderr_to_stdout(self):
272 def fn(c, e, un):
273 (out, err), code = subprocess2.communicate(
274 e + ['--stderr'],
275 stderr=subprocess2.STDOUT,
276 universal_newlines=un)
277 # stderr output into stdout but stdout is not piped.
278 self.assertEquals(None, out)
279 self.assertEquals(None, err)
280 self.assertEquals(0, code)
281 self._run_test(fn)
282
258 def test_check_output_throw_stdout(self): 283 def test_check_output_throw_stdout(self):
259 def fn(c, e, un): 284 def fn(c, e, un):
260 try: 285 try:
261 subprocess2.check_output( 286 subprocess2.check_output(
262 e + ['--fail', '--stdout'], universal_newlines=un) 287 e + ['--fail', '--stdout'], universal_newlines=un)
263 self.fail() 288 self.fail()
264 except subprocess2.CalledProcessError, e: 289 except subprocess2.CalledProcessError, e:
265 self.assertEquals(c('A\nBB\nCCC\n'), e.stdout) 290 self.assertEquals(c('A\nBB\nCCC\n'), e.stdout)
266 self.assertEquals(None, e.stderr) 291 self.assertEquals(None, e.stderr)
267 self.assertEquals(64, e.returncode) 292 self.assertEquals(64, e.returncode)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return options.return_value 397 return options.return_value
373 398
374 399
375 if __name__ == '__main__': 400 if __name__ == '__main__':
376 logging.basicConfig(level= 401 logging.basicConfig(level=
377 [logging.WARNING, logging.INFO, logging.DEBUG][ 402 [logging.WARNING, logging.INFO, logging.DEBUG][
378 min(2, sys.argv.count('-v'))]) 403 min(2, sys.argv.count('-v'))])
379 if len(sys.argv) > 1 and sys.argv[1] == '--child': 404 if len(sys.argv) > 1 and sys.argv[1] == '--child':
380 sys.exit(child_main(sys.argv[2:])) 405 sys.exit(child_main(sys.argv[2:]))
381 unittest.main() 406 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698