From: Peter Astrand Date: Tue, 30 Nov 2004 21:04:45 +0000 (+0000) Subject: Raise TypeError if bufsize argument is not an integer. Patch 1071755, slightly modified. X-Git-Tag: v2.5a0~2338 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=738131d39130563ad75e73ed544e2a3edbae64f2;p=python Raise TypeError if bufsize argument is not an integer. Patch 1071755, slightly modified. --- diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 8d0204e25d..9e326fbea4 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -504,6 +504,9 @@ class Popen(object): """Create new Popen instance.""" _cleanup() + if not isinstance(bufsize, (int, long)): + raise TypeError("bufsize must be an integer") + if mswindows: if preexec_fn is not None: raise ValueError("preexec_fn is not supported on Windows " diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 9f7184f057..b26d40cb29 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -394,6 +394,17 @@ class ProcessTestCase(unittest.TestCase): # Subsequent invocations should just return the returncode self.assertEqual(p.wait(), 0) + + def test_invalid_bufsize(self): + # an invalid type of the bufsize argument should raise + # TypeError. + try: + subprocess.Popen([sys.executable, "-c", "pass"], "orange") + except TypeError: + pass + else: + self.fail("Expected TypeError") + # # POSIX tests #