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

Unified Diff: tests/subprocess2_test.py

Issue 8801019: Improve subprocess2 stdin tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/subprocess2_test.py
diff --git a/tests/subprocess2_test.py b/tests/subprocess2_test.py
index 1a413e587aad964f3c8857b68e03ed0df12f6c7f..467d6fb4a5ac5bbf22ba71295dd289325f976330 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:
« 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