Skip to content
Myr

🐛 Ensure that `typer.launch` forwards correctly when launching a file (#1708)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sofie Van Landeghem · committed by GitHub · parent f0a6ee8 · Browse files · 3 files+21 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>

Diff stats

3 files+21 added−2 removed

  • tests:+20 added−1 removed
  • other:+1 added−1 removed

3 files+21 added−2 removed

modified:tests/test_launch.py+17 added-1 removed
2 unmodified lines
34import pytest5import typer67from tests.utils import needs_windows89url = "http://example.com"101112@pytest.mark.parametrize(
41 unmodified lines
54def test_calls_original_launch_when_not_passing_urls():55 with patch("typer.main.click.launch", return_value=0) as launch_mock:56 typer.launch("not a url")5756 launch_mock.assert_called_once_with("not a url")58 launch_mock.assert_called_once_with("not a url", wait=False, locate=False)596061@needs_windows62def test_launch_file():63 with (64 patch("click._termui_impl.sys.platform", "win32"),65 patch("click._termui_impl.WIN", True),66 patch("click._termui_impl.CYGWIN", False),67 patch("subprocess.call", return_value=0) as call_mock,68 ):69 result = typer.launch("C:/tmp/file.txt", locate=True)7071 assert result == 072 call_mock.assert_called_once_with(["explorer", "/select,C:/tmp/file.txt"])
modified:tests/utils.py+3 added
7 unmodified lines
89needs_linux = pytest.mark.skipif(10 not sys.platform.startswith("linux"), reason="Test requires Linux"11)12needs_windows = pytest.mark.skipif(13 not sys.platform.startswith("win"), reason="Test requires Windows"14)1516needs_rich = pytest.mark.skipif(not HAS_RICH, reason="Test requires Rich")1718shell = _get_shell_name()
27 unmodified lines
modified:typer/main.py+1 added-1 removed
2008 unmodified lines
20092010 return 020112012 else:2013 return click.launch(url)2013 return click.launch(url, wait=wait, locate=locate)