Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Urls always opening in Plots view #4966

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading