Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_subprocess.py @ 49200:bdb660dca74d
Issue #3782: os.write() must not accept unicode strings
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Mon, 15 Sep 2008 23:02:56 +0000 |
| parents | bb65f9b76c1f |
| children | c1bf037feefe 024a9897c651 |
line wrap: on
line diff
--- a/Lib/test/test_subprocess.py Mon Sep 15 01:31:40 2008 +0000 +++ b/Lib/test/test_subprocess.py Mon Sep 15 23:02:56 2008 +0000 @@ -128,7 +128,7 @@ # stdin is set to open file descriptor tf = tempfile.TemporaryFile() d = tf.fileno() - os.write(d, "pear") + os.write(d, b"pear") os.lseek(d, 0, 0) p = subprocess.Popen([sys.executable, "-c", 'import sys; sys.exit(sys.stdin.read() == "pear")'], @@ -237,7 +237,7 @@ def test_stdout_filedes_of_stdout(self): # stdout is set to 1 (#1531862). - cmd = r"import sys, os; sys.exit(os.write(sys.stdout.fileno(), '.\n'))" + cmd = r"import sys, os; sys.exit(os.write(sys.stdout.fileno(), b'.\n'))" rc = subprocess.call([sys.executable, "-c", cmd], stdout=1) self.assertEquals(rc, 2) @@ -548,11 +548,12 @@ def test_args_string(self): # args is a string - f, fname = self.mkstemp() - os.write(f, "#!/bin/sh\n") - os.write(f, "exec '%s' -c 'import sys; sys.exit(47)'\n" % - sys.executable) - os.close(f) + fd, fname = self.mkstemp() + # reopen in text mode + with open(fd, "w") as fobj: + fobj.write("#!/bin/sh\n") + fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" % + sys.executable) os.chmod(fname, 0o700) p = subprocess.Popen(fname) p.wait() @@ -590,11 +591,12 @@ def test_call_string(self): # call() function with string argument on UNIX - f, fname = self.mkstemp() - os.write(f, "#!/bin/sh\n") - os.write(f, "exec '%s' -c 'import sys; sys.exit(47)'\n" % - sys.executable) - os.close(f) + fd, fname = self.mkstemp() + # reopen in text mode + with open(fd, "w") as fobj: + fobj.write("#!/bin/sh\n") + fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" % + sys.executable) os.chmod(fname, 0o700) rc = subprocess.call(fname) os.remove(fname)
