mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	More str/bytes goodness.
This commit is contained in:
		
							parent
							
								
									f6db40994f
								
							
						
					
					
						commit
						bb839ef8ac
					
				
					 2 changed files with 10 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -553,8 +553,8 @@ def __init__(self, args, bufsize=0, executable=None,
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
    def _translate_newlines(self, data):
 | 
			
		||||
        data = data.replace("\r\n", "\n")
 | 
			
		||||
        data = data.replace("\r", "\n")
 | 
			
		||||
        data = data.replace(b"\r\n", b"\n")
 | 
			
		||||
        data = data.replace(b"\r", b"\n")
 | 
			
		||||
        return str(data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,7 +118,7 @@ def test_stdin_pipe(self):
 | 
			
		|||
        p = subprocess.Popen([sys.executable, "-c",
 | 
			
		||||
                         'import sys; sys.exit(sys.stdin.read() == "pear")'],
 | 
			
		||||
                        stdin=subprocess.PIPE)
 | 
			
		||||
        p.stdin.write("pear")
 | 
			
		||||
        p.stdin.write(b"pear")
 | 
			
		||||
        p.stdin.close()
 | 
			
		||||
        p.wait()
 | 
			
		||||
        self.assertEqual(p.returncode, 1)
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +138,7 @@ def test_stdin_filedes(self):
 | 
			
		|||
    def test_stdin_fileobj(self):
 | 
			
		||||
        # stdin is set to open file object
 | 
			
		||||
        tf = tempfile.TemporaryFile()
 | 
			
		||||
        tf.write("pear")
 | 
			
		||||
        tf.write(b"pear")
 | 
			
		||||
        tf.seek(0)
 | 
			
		||||
        p = subprocess.Popen([sys.executable, "-c",
 | 
			
		||||
                         'import sys; sys.exit(sys.stdin.read() == "pear")'],
 | 
			
		||||
| 
						 | 
				
			
			@ -254,7 +254,8 @@ def test_cwd(self):
 | 
			
		|||
                         stdout=subprocess.PIPE,
 | 
			
		||||
                         cwd=tmpdir)
 | 
			
		||||
        normcase = os.path.normcase
 | 
			
		||||
        self.assertEqual(normcase(p.stdout.read()), bytes(normcase(tmpdir)))
 | 
			
		||||
        self.assertEqual(normcase(p.stdout.read().decode("utf-8")),
 | 
			
		||||
                         normcase(tmpdir))
 | 
			
		||||
 | 
			
		||||
    def test_env(self):
 | 
			
		||||
        newenv = os.environ.copy()
 | 
			
		||||
| 
						 | 
				
			
			@ -270,7 +271,7 @@ def test_communicate_stdin(self):
 | 
			
		|||
        p = subprocess.Popen([sys.executable, "-c",
 | 
			
		||||
                              'import sys; sys.exit(sys.stdin.read() == "pear")'],
 | 
			
		||||
                             stdin=subprocess.PIPE)
 | 
			
		||||
        p.communicate("pear")
 | 
			
		||||
        p.communicate(b"pear")
 | 
			
		||||
        self.assertEqual(p.returncode, 1)
 | 
			
		||||
 | 
			
		||||
    def test_communicate_stdout(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -289,7 +290,7 @@ def test_communicate_stderr(self):
 | 
			
		|||
        self.assertEqual(stdout, None)
 | 
			
		||||
        # When running with a pydebug build, the # of references is outputted
 | 
			
		||||
        # to stderr, so just check if stderr at least started with "pinapple"
 | 
			
		||||
        self.assert_(stderr.startswith("pineapple"))
 | 
			
		||||
        self.assert_(stderr.startswith(b"pineapple"))
 | 
			
		||||
 | 
			
		||||
    def test_communicate(self):
 | 
			
		||||
        p = subprocess.Popen([sys.executable, "-c",
 | 
			
		||||
| 
						 | 
				
			
			@ -343,8 +344,8 @@ def test_writes_before_communicate(self):
 | 
			
		|||
                         stdin=subprocess.PIPE,
 | 
			
		||||
                         stdout=subprocess.PIPE,
 | 
			
		||||
                         stderr=subprocess.PIPE)
 | 
			
		||||
        p.stdin.write("banana")
 | 
			
		||||
        (stdout, stderr) = p.communicate("split")
 | 
			
		||||
        p.stdin.write(b"banana")
 | 
			
		||||
        (stdout, stderr) = p.communicate(b"split")
 | 
			
		||||
        self.assertEqual(stdout, b"bananasplit")
 | 
			
		||||
        self.assertEqual(remove_stderr_debug_decorations(stderr), "")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue