Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
timtmok committed Oct 9, 2024
1 parent 0244402 commit 2f06a2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,32 @@ 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://file.html"
assert params["is_plot"] is False

Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ def _is_module_function(module_name: str, function_name: str = None) -> bool:
else:
if inspect.getmodule(frame_info.frame) == module:
return True
else:
return True
return False

def _send_show_html_event(self, url: str, is_plot: bool) -> bool:
Expand Down

0 comments on commit 2f06a2d

Please sign in to comment.