From 679cda5eb36f35979d71936306909b007ec5a5e1 Mon Sep 17 00:00:00 2001 From: Daniel Copley Date: Sat, 13 Jan 2024 23:51:46 -0500 Subject: [PATCH] Add test_shelloracle.py --- tests/test_shelloracle.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/test_shelloracle.py diff --git a/tests/test_shelloracle.py b/tests/test_shelloracle.py new file mode 100644 index 0000000..b40a45f --- /dev/null +++ b/tests/test_shelloracle.py @@ -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()