(case_setup_dap)
| 820 | |
| 821 | |
| 822 | def test_case_throw_exc_reason(case_setup_dap): |
| 823 | |
| 824 | def check_test_suceeded_msg(self, stdout, stderr): |
| 825 | return "TEST SUCEEDED" in "".join(stderr) |
| 826 | |
| 827 | def additional_output_checks(writer, stdout, stderr): |
| 828 | assert "raise RuntimeError('TEST SUCEEDED')" in stderr |
| 829 | assert "raise RuntimeError from e" in stderr |
| 830 | assert "raise Exception('another while handling')" in stderr |
| 831 | |
| 832 | with case_setup_dap.test_file( |
| 833 | "_debugger_case_raise_with_cause.py", |
| 834 | EXPECTED_RETURNCODE=1, |
| 835 | check_test_suceeded_msg=check_test_suceeded_msg, |
| 836 | additional_output_checks=additional_output_checks, |
| 837 | ) as writer: |
| 838 | json_facade = JsonFacade(writer) |
| 839 | |
| 840 | json_facade.write_launch(justMyCode=False) |
| 841 | json_facade.write_set_exception_breakpoints(["uncaught"]) |
| 842 | json_facade.write_make_initial_run() |
| 843 | |
| 844 | json_hit = json_facade.wait_for_thread_stopped( |
| 845 | reason="exception", line=writer.get_line_index_with_content("raise RuntimeError from e") |
| 846 | ) |
| 847 | |
| 848 | exc_info_request = json_facade.write_request( |
| 849 | pydevd_schema.ExceptionInfoRequest(pydevd_schema.ExceptionInfoArguments(json_hit.thread_id)) |
| 850 | ) |
| 851 | exc_info_response = json_facade.wait_for_response(exc_info_request) |
| 852 | |
| 853 | stack_frames = json_hit.stack_trace_response.body.stackFrames |
| 854 | # Note that the additional context doesn't really appear in the stack |
| 855 | # frames, only in the details. |
| 856 | assert [x["name"] for x in stack_frames] == [ |
| 857 | "foobar", |
| 858 | "<module>", |
| 859 | "[Chained Exc: another while handling] foobar", |
| 860 | "[Chained Exc: another while handling] handle", |
| 861 | "[Chained Exc: TEST SUCEEDED] foobar", |
| 862 | "[Chained Exc: TEST SUCEEDED] method", |
| 863 | "[Chained Exc: TEST SUCEEDED] method2", |
| 864 | ] |
| 865 | |
| 866 | body = exc_info_response.body |
| 867 | assert body.exceptionId.endswith("RuntimeError") |
| 868 | assert body.description == "another while handling" |
| 869 | assert normcase(body.details.kwargs["source"]) == normcase(writer.TEST_FILE) |
| 870 | |
| 871 | # Check that we have all the lines (including the cause/context) in the stack trace. |
| 872 | import re |
| 873 | |
| 874 | lines_and_names = re.findall(r",\sline\s(\d+),\sin\s(\[Chained Exception\]\s)?([\w|<|>]+)", body.details.stackTrace) |
| 875 | assert lines_and_names == [ |
| 876 | ("16", "", "foobar"), |
| 877 | ("6", "", "method"), |
| 878 | ("2", "", "method2"), |
| 879 | ("18", "", "foobar"), |
nothing calls this directly
no test coverage detected