-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
from shelloracle.shelloracle import get_query_from_pipe | ||
|
||
|
||
def test_get_query_from_pipe(monkeypatch): | ||
# Is a TTY | ||
monkeypatch.setattr(os, "isatty", lambda _: True) | ||
assert get_query_from_pipe() is None | ||
|
||
# Not a TTY and no lines in the pipe | ||
monkeypatch.setattr(os, "isatty", lambda _: False) | ||
monkeypatch.setattr(sys.stdin, "readlines", lambda: []) | ||
assert get_query_from_pipe() is None | ||
|
||
# Not TTY and one line in the pipe | ||
monkeypatch.setattr(sys.stdin, "readlines", lambda: ["what is up"]) | ||
assert get_query_from_pipe() == "what is up" | ||
|
||
# Not a TTY and multiple lines in the pipe | ||
monkeypatch.setattr(sys.stdin, "readlines", lambda: ["what is up", "what is down"]) | ||
with pytest.raises(ValueError): | ||
get_query_from_pipe() |