Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
laixintao committed Oct 4, 2023
1 parent 70cc842 commit ef75c0b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/test_cli_click.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from click.testing import CliRunner
from flameshow.main import main, ensure_tty
from unittest.mock import patch, Mock
from unittest.mock import patch, MagicMock


def test_print_version():
Expand All @@ -26,11 +26,14 @@ def test_run_app(mock_os, data_dir):
@patch("flameshow.main.os")
def test_ensure_tty_when_its_not(mock_os, mock_sys):
mock_os.isatty.return_value = False
ensure_tty()
opened_fd = object()
mock_os.fdopen.return_value = opened_fd

fake_stdin = Mock()
fake_stdin = MagicMock()
mock_sys.stdin = fake_stdin

ensure_tty()

fake_stdin.close.assert_called()
assert hasattr(mock_sys, "stdin")
assert mock_sys.stdin.fileno == 2
assert mock_sys.stdin is opened_fd

0 comments on commit ef75c0b

Please sign in to comment.