diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_ui.py b/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_ui.py index 132da3704f7..bf02f5d0c60 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_ui.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_ui.py @@ -278,3 +278,31 @@ def test_plotly_show_sends_events( assert params["title"] == "" assert params["is_plot"] assert params["height"] == 0 + + +def test_is_not_plot_url_events( + shell: PositronShell, + ui_comm: DummyComm, +) -> None: + """ + Test that opening a URL that is not a plot sends the expected UI events. + Checks that the `is_plot` parameter is not sent or is `False`. + """ + shell.run_cell( + """\ +import webbrowser +# Only enable the positron viewer browser; avoids system browsers opening during tests. +webbrowser._tryorder = ["positron_viewer"] + +webbrowser.open("http://127.0.0.1:8000") +webbrowser.open("file://file.html") +""" + ) + assert len(ui_comm.messages) == 2 + params = ui_comm.messages[0]["data"]["params"] + assert params["url"] == "http://127.0.0.1:8000" + assert "is_plot" not in params + + params = ui_comm.messages[1]["data"]["params"] + assert params["path"] == "file.html" if sys.platform == "win32" else "file://file.html" + assert params["is_plot"] is False diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/ui.py b/extensions/positron-python/python_files/positron/positron_ipykernel/ui.py index 24fd6ee232b..577a92183e3 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/ui.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/ui.py @@ -210,18 +210,19 @@ def open(self, url, new=0, autoraise=True) -> bool: return False @staticmethod - def _is_module_function(module_name: str, function_name: str = None) -> bool: + def _is_module_function(module_name: str, function_name: Union[str, None] = None) -> bool: module = sys.modules.get(module_name) if module: - if function_name: - for frame_info in inspect.stack(): + for frame_info in inspect.stack(): + if function_name: if ( inspect.getmodule(frame_info.frame, frame_info.filename) == module and frame_info.function == function_name ): return True - else: - return True + else: + if inspect.getmodule(frame_info.frame) == module: + return True return False def _send_show_html_event(self, url: str, is_plot: bool) -> bool: