Skip to content

Commit

Permalink
Add test_shelloracle.py
Browse files Browse the repository at this point in the history
  • Loading branch information
djcopley committed Jan 14, 2024
1 parent a8d4400 commit 679cda5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_shelloracle.py
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()

0 comments on commit 679cda5

Please sign in to comment.