Skip to content

Commit 405bcd8

Browse files
committed
Keep output message when program exit in PDBTool.
Copy from #122, thanks Marc :)
1 parent a6abf8d commit 405bcd8

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

debug_gym/gym/tools/pdb.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,11 @@ def use(self, environment, command: str) -> Observation:
181181
# into self.last_eval_output, and remove them from the output
182182
if "The program exited via sys.exit()." in output:
183183
# end index is the last occurrence of the program exited (from the \n after)
184-
end_index = (
185-
output.find("\n", output.rfind("The program exited via sys.exit()."))
186-
+ 1
187-
)
184+
start_index = output.rfind("The program exited via sys.exit().")
185+
end_index = output.find("\n", start_index) + 1
188186
output = (
189-
"Reached the end of the file. Restarting the debugging session.\n"
187+
output[:start_index]
188+
+ "\nReached the end of the program. Restarting the debugging session.\n"
190189
+ output[end_index:]
191190
)
192191
obs = "\n".join([_warning, output]).strip() + "\n"

tests/gym/tools/test_pdb.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ def test_pdb_use(tmp_path, setup_test_repo):
7777
assert """The pytest entry point.""" in output
7878
assert "(Pdb)" not in output
7979
output = pdb.use(environment, command="c").observation
80-
assert "1 failed, 1 passed" in pdb.pdb_obs
81-
assert "test_fail.py::test_fail FAILED" in pdb.pdb_obs
82-
assert "test_pass.py::test_pass PASSED" in pdb.pdb_obs
83-
assert "Reached the end of the file. Restarting the debugging session." in output
80+
assert "1 failed, 1 passed" in output
81+
assert "test_fail.py::test_fail FAILED" in output
82+
assert "test_pass.py::test_pass PASSED" in output
83+
assert "Reached the end of the program. Restarting the debugging session." in output
84+
assert "pytest/__main__.py" in output
85+
assert '-> """The pytest entry point."""' in output
86+
assert 'Context around the current frame:\n1 -> """The pytest entry point.""""'
8487
assert "(Pdb)" not in output
8588

8689

@@ -152,10 +155,13 @@ def test_pdb_use_default_environment_entrypoint(tmp_path, setup_test_repo):
152155
assert "(Pdb)" not in output
153156

154157
output = pdb.use(environment, command="c").observation
155-
assert "1 failed, 1 passed" in pdb.pdb_obs
156-
assert "test_fail.py::test_fail" in pdb.pdb_obs
157-
assert "test_pass.py::test_pass" not in pdb.pdb_obs
158-
assert "Reached the end of the file. Restarting the debugging session." in output
158+
assert "1 failed, 1 passed" in output
159+
assert "test_fail.py::test_fail" in output
160+
assert "test_pass.py::test_pass" not in output
161+
assert "Reached the end of the program. Restarting the debugging session." in output
162+
assert "pytest/__main__.py" in output
163+
assert '-> """The pytest entry point."""' in output
164+
assert 'Context around the current frame:\n1 -> """The pytest entry point.""""'
159165
assert "(Pdb)" not in output
160166

161167

@@ -182,10 +188,13 @@ def test_pdb_use_docker_terminal(tmp_path, setup_test_repo):
182188
assert "(Pdb)" not in output
183189

184190
output = pdb.use(environment, command="c").observation
185-
assert "1 failed, 1 passed" in pdb.pdb_obs
186-
assert "test_fail.py::test_fail FAILED" in pdb.pdb_obs
187-
assert "test_pass.py::test_pass PASSED" in pdb.pdb_obs
188-
assert "Reached the end of the file. Restarting the debugging session." in output
191+
assert "1 failed, 1 passed" in output
192+
assert "test_fail.py::test_fail FAILED" in output
193+
assert "test_pass.py::test_pass PASSED" in output
194+
assert "Reached the end of the program. Restarting the debugging session." in output
195+
assert "pytest/__main__.py" in output
196+
assert '-> """The pytest entry point."""' in output
197+
assert 'Context around the current frame:\n1 -> """The pytest entry point.""""'
189198
assert "(Pdb)" not in output
190199

191200

0 commit comments

Comments
 (0)