From bc3a53cb7b146dfb52f2ac9a39fce998b26e7cce Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Mon, 5 Dec 2011 23:38:19 +0000 Subject: [PATCH] Improve subprocess2 stdin tests. No significant code change. R=dpranke@chromium.org TEST= BUG= Review URL: http://codereview.chromium.org/8801019 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@113062 0039d316-1c4b-4281-b951-d872f2087c98 --- tests/subprocess2_test.py | 52 +++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/tests/subprocess2_test.py b/tests/subprocess2_test.py index 1a413e587..467d6fb4a 100755 --- a/tests/subprocess2_test.py +++ b/tests/subprocess2_test.py @@ -380,6 +380,42 @@ class S2Test(BaseTestCase): pass self._run_test(fn) + def test_stdin(self): + def fn(c, e, un): + stdin = '0123456789' + res = subprocess2.communicate( + e + ['--read'], + stdin=stdin, + universal_newlines=un) + self._check_res(res, None, None, 10) + self._run_test(fn) + + def test_stdin_unicode(self): + def fn(c, e, un): + stdin = u'0123456789' + res = subprocess2.communicate( + e + ['--read'], + stdin=stdin, + universal_newlines=un) + self._check_res(res, None, None, 10) + self._run_test(fn) + + def test_stdin_void(self): + res = subprocess2.communicate(self.exe + ['--read'], stdin=VOID) + self._check_res(res, None, None, 0) + + def test_stdin_void_stdout_timeout(self): + # Make sure a mix of VOID, PIPE and timeout works. + def fn(c, e, un): + res = subprocess2.communicate( + e + ['--stdout', '--read'], + stdin=VOID, + stdout=PIPE, + timeout=10, + universal_newlines=un) + self._check_res(res, c('A\nBB\nCCC\n'), None, 0) + self._run_test(fn) + def test_stdout_void(self): def fn(c, e, un): res = subprocess2.communicate( @@ -435,21 +471,26 @@ class S2Test(BaseTestCase): def test_tee_stdin(self): def fn(c, e, un): + # Mix of stdin input and stdout callback. stdout = [] stdin = '0123456789' res = subprocess2.communicate( - e + ['--stdout', '--read'], stdin=stdin, stdout=stdout.append, + e + ['--stdout', '--read'], + stdin=stdin, + stdout=stdout.append, universal_newlines=un) self.assertEquals(c('A\nBB\nCCC\n'), ''.join(stdout)) - self._check_res(res, None, None, 0) + self._check_res(res, None, None, 10) self._run_test(fn) def test_tee_throw(self): def fn(c, e, un): + # Make sure failure still returns stderr completely. stderr = [] try: subprocess2.check_output( - e + ['--stderr', '--fail'], stderr=stderr.append, + e + ['--stderr', '--fail'], + stderr=stderr.append, universal_newlines=un) self.fail() except subprocess2.CalledProcessError, e: @@ -580,9 +621,10 @@ def child_main(args): string = '0123456789abcdef' * (8*1024) sys.stdout.write(string) if options.read: + assert options.return_value is 0 try: - while sys.stdin.read(): - pass + while sys.stdin.read(1): + options.return_value += 1 except OSError: pass if options.sleep_last: