Skip to content
Open
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
7 changes: 6 additions & 1 deletion duckdb/query_graph/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,12 @@ def main() -> None: # noqa: D103
)
parser.add_argument("--profile_input", help="profile input in json")
parser.add_argument("--out", required=False, default=False)
parser.add_argument("--open", required=False, action="store_true", default=True)
parser.add_argument(
"--open",
action=argparse.BooleanOptionalAction,
default=True,
help="Open the generated HTML in the browser (default: enabled).",
)
args = parser.parse_args()

input = args.profile_input
Expand Down
30 changes: 30 additions & 0 deletions tests/fast/test_query_graph_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
from unittest.mock import Mock

import pytest

from duckdb.query_graph import __main__ as query_graph


@pytest.mark.parametrize(
("options", "opens_browser"),
[((), True), (("--open",), True), (("--no-open",), False)],
)
def test_query_graph_browser_option(monkeypatch, tmp_path, options, opens_browser):
source = str(tmp_path / "profile.json")
output = tmp_path / "profile.html"
profile = Mock()
profiling_info = Mock(return_value=profile)
open_browser = Mock()
monkeypatch.setattr(query_graph, "ProfilingInfo", profiling_info)
monkeypatch.setattr(query_graph.webbrowser, "open", open_browser)
monkeypatch.setattr(sys, "argv", ["query_graph", "--profile_input", source, *options])

query_graph.main()

profiling_info.assert_called_once_with(from_file=source)
profile.to_html.assert_called_once_with(output_file=str(output))
if opens_browser:
open_browser.assert_called_once_with(output.as_uri(), new=2)
else:
open_browser.assert_not_called()