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
20 changes: 11 additions & 9 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@


@pytest.mark.parametrize(
"system, command",
"system, sys_platform, command",
[
("Darwin", "open"),
("Linux", "xdg-open"),
("FreeBSD", "xdg-open"),
("Darwin", "darwin", "open"),
("Linux", "linux", "xdg-open"),
("FreeBSD", "freebsd8", "xdg-open"),
],
)
def test_launch_url_unix(system: str, command: str):
def test_launch_url_unix(system: str, sys_platform: str, command: str):
with patch("platform.system", return_value=system), patch(
"shutil.which", return_value=True
), patch("subprocess.Popen") as mock_popen:
"sys.platform", sys_platform
), patch("shutil.which", return_value=True), patch(
"subprocess.Popen"
) as mock_popen:
typer.launch(url)

mock_popen.assert_called_once_with(
Expand All @@ -27,7 +29,7 @@ def test_launch_url_unix(system: str, command: str):


def test_launch_url_windows():
with patch("platform.system", return_value="Windows"), patch(
with patch("sys.platform", "windows"), patch(
"webbrowser.open"
) as mock_webbrowser_open:
typer.launch(url)
Expand All @@ -36,7 +38,7 @@ def test_launch_url_windows():


def test_launch_url_no_xdg_open():
with patch("platform.system", return_value="Linux"), patch(
with patch("sys.platform", "linux"), patch(
"shutil.which", return_value=None
), patch("webbrowser.open") as mock_webbrowser_open:
typer.launch(url)
Expand Down
7 changes: 4 additions & 3 deletions typer/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import inspect
import os
import platform
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -1072,13 +1071,15 @@ def run(function: Callable[..., Any]) -> None:


def _is_macos() -> bool:
return platform.system() == "Darwin"
return sys.platform == "darwin"


def _is_linux_or_bsd() -> bool:
if platform.system() == "Linux":
if sys.platform == "linux":
return True

import platform

return "BSD" in platform.system()


Expand Down
Loading