-
-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/autocompletion
- Loading branch information
Showing
8 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import subprocess | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
import typer | ||
|
||
url = "http://example.com" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"system, command", | ||
[ | ||
("Darwin", "open"), | ||
("Linux", "xdg-open"), | ||
("FreeBSD", "xdg-open"), | ||
], | ||
) | ||
def test_launch_url_unix(system: str, command: str): | ||
with patch("platform.system", return_value=system), patch( | ||
"shutil.which", return_value=True | ||
), patch("subprocess.Popen") as mock_popen: | ||
typer.launch(url) | ||
|
||
mock_popen.assert_called_once_with( | ||
[command, url], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT | ||
) | ||
|
||
|
||
def test_launch_url_windows(): | ||
with patch("platform.system", return_value="Windows"), patch( | ||
"webbrowser.open" | ||
) as mock_webbrowser_open: | ||
typer.launch(url) | ||
|
||
mock_webbrowser_open.assert_called_once_with(url) | ||
|
||
|
||
def test_launch_url_no_xdg_open(): | ||
with patch("platform.system", return_value="Linux"), patch( | ||
"shutil.which", return_value=None | ||
), patch("webbrowser.open") as mock_webbrowser_open: | ||
typer.launch(url) | ||
|
||
mock_webbrowser_open.assert_called_once_with(url) | ||
|
||
|
||
def test_calls_original_launch_when_not_passing_urls(): | ||
with patch("typer.main.click.launch", return_value=0) as launch_mock: | ||
typer.launch("not a url") | ||
|
||
launch_mock.assert_called_once_with("not a url") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters