Skip to content

Commit

Permalink
pythongh-69201: Separate stdout and stderr stream in test_pdb (python…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian authored Mar 28, 2024
1 parent 6702d2b commit efcc968
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2603,12 +2603,12 @@ def _run_pdb(self, pdb_args, commands,
cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
env = {**env, 'PYTHONIOENCODING': 'utf-8'}
) as proc:
stdout, stderr = proc.communicate(str.encode(commands))
stdout = stdout and bytes.decode(stdout)
stderr = stderr and bytes.decode(stderr)
stdout = bytes.decode(stdout) if isinstance(stdout, bytes) else stdout
stderr = bytes.decode(stderr) if isinstance(stderr, bytes) else stderr
self.assertEqual(
proc.returncode,
expected_returncode,
Expand Down Expand Up @@ -2756,7 +2756,7 @@ def test_issue7964(self):
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
)
self.addCleanup(proc.stdout.close)
stdout, stderr = proc.communicate(b'quit\n')
Expand Down Expand Up @@ -2840,7 +2840,7 @@ def start_pdb():
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
env={**os.environ, 'PYTHONIOENCODING': 'utf-8'}
)
self.addCleanup(proc.stdout.close)
Expand Down Expand Up @@ -2870,7 +2870,7 @@ def start_pdb():
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'}
)
self.addCleanup(proc.stdout.close)
Expand All @@ -2886,10 +2886,10 @@ def test_issue16180(self):
stdout, stderr = self.run_pdb_script(
script, commands
)
self.assertIn(expected, stdout,
self.assertIn(expected, stderr,
'\n\nExpected:\n{}\nGot:\n{}\n'
'Fail to handle a syntax error in the debuggee.'
.format(expected, stdout))
.format(expected, stderr))

def test_issue84583(self):
# A syntax error from ast.literal_eval should not make pdb exit.
Expand All @@ -2900,11 +2900,12 @@ def test_issue84583(self):
quit
"""
stdout, stderr = self.run_pdb_script(script, commands)
# The code should appear 3 times in the stdout:
# 1. when pdb starts
# 2. when the exception is raised, in trackback
# 3. in where command
self.assertEqual(stdout.count("ast.literal_eval('')"), 3)
# The code should appear 3 times in the stdout/stderr:
# 1. when pdb starts (stdout)
# 2. when the exception is raised, in trackback (stderr)
# 3. in where command (stdout)
self.assertEqual(stdout.count("ast.literal_eval('')"), 2)
self.assertEqual(stderr.count("ast.literal_eval('')"), 1)

def test_issue26053(self):
# run command of pdb prompt echoes the correct args
Expand Down Expand Up @@ -3133,9 +3134,9 @@ def test_dir_as_script(self):

def test_invalid_cmd_line_options(self):
stdout, stderr = self._run_pdb(["-c"], "", expected_returncode=2)
self.assertIn(f"pdb: error: argument -c/--command: expected one argument", stdout.split('\n')[1])
self.assertIn(f"pdb: error: argument -c/--command: expected one argument", stderr.split('\n')[1])
stdout, stderr = self._run_pdb(["--spam", "-m", "pdb"], "", expected_returncode=2)
self.assertIn(f"pdb: error: unrecognized arguments: --spam", stdout.split('\n')[1])
self.assertIn(f"pdb: error: unrecognized arguments: --spam", stderr.split('\n')[1])

def test_blocks_at_first_code_line(self):
script = """
Expand Down Expand Up @@ -3190,7 +3191,7 @@ def test_file_modified_after_execution_with_multiple_instances(self):
cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'},
) as proc:
stdout, _ = proc.communicate(str.encode(commands))
Expand Down

0 comments on commit efcc968

Please sign in to comment.