(case_setup)
| 2096 | |
| 2097 | @pytest.mark.skipif(IS_JYTHON, reason="Not working on Jython (needs to be investigated).") |
| 2098 | def test_case_handled_exceptions1(case_setup): |
| 2099 | # Stop multiple times for the same handled exception. |
| 2100 | def get_environ(self): |
| 2101 | env = os.environ.copy() |
| 2102 | |
| 2103 | env["IDE_PROJECT_ROOTS"] = os.path.dirname(self.TEST_FILE) |
| 2104 | return env |
| 2105 | |
| 2106 | with case_setup.test_file("_debugger_case_exceptions.py", get_environ=get_environ) as writer: |
| 2107 | writer.write_add_exception_breakpoint_with_policy( |
| 2108 | "IndexError", |
| 2109 | notify_on_handled_exceptions=1, # Notify multiple times |
| 2110 | notify_on_unhandled_exceptions=0, |
| 2111 | ignore_libraries=1, |
| 2112 | ) |
| 2113 | writer.write_make_initial_run() |
| 2114 | |
| 2115 | def check(hit): |
| 2116 | writer.write_get_frame(hit.thread_id, hit.frame_id) |
| 2117 | writer.wait_for_message(accept_message=lambda msg: "__exception__" in msg and "IndexError" in msg, unquote_msg=False) |
| 2118 | writer.write_get_current_exception(hit.thread_id) |
| 2119 | msg = writer.wait_for_message( |
| 2120 | accept_message=lambda msg: "IndexError" in msg and 'exc_type="' in msg and 'exc_desc="' in msg, unquote_msg=False |
| 2121 | ) |
| 2122 | assert msg.thread["exc_desc"] == "foo" |
| 2123 | assert unquote(msg.thread["exc_type"]) in ( |
| 2124 | "<type 'exceptions.IndexError'>", # py2 |
| 2125 | "<class 'IndexError'>", # py3 |
| 2126 | ) |
| 2127 | |
| 2128 | assert unquote(unquote(msg.thread.frame[0]["file"])).endswith("_debugger_case_exceptions.py") |
| 2129 | writer.write_run_thread(hit.thread_id) |
| 2130 | |
| 2131 | hit = writer.wait_for_breakpoint_hit(REASON_CAUGHT_EXCEPTION, line=writer.get_line_index_with_content("raise indexerror line")) |
| 2132 | check(hit) |
| 2133 | |
| 2134 | hit = writer.wait_for_breakpoint_hit(REASON_CAUGHT_EXCEPTION, line=writer.get_line_index_with_content("reraise on method2")) |
| 2135 | check(hit) |
| 2136 | |
| 2137 | hit = writer.wait_for_breakpoint_hit(REASON_CAUGHT_EXCEPTION, line=writer.get_line_index_with_content("handle on method1")) |
| 2138 | check(hit) |
| 2139 | |
| 2140 | writer.finished_ok = True |
| 2141 | |
| 2142 | |
| 2143 | def test_case_handled_exceptions2(case_setup): |
nothing calls this directly
no test coverage detected