-
Notifications
You must be signed in to change notification settings - Fork 0
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
41 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,41 @@ | ||
from io import StringIO | ||
from unittest.mock import patch | ||
import argparse | ||
import os | ||
|
||
|
||
from ..ask import main | ||
from ..input import InputInterrupt | ||
|
||
|
||
@patch("google.generativeai.GenerativeModel") | ||
@patch.dict(os.environ, {"GEMINI_API_KEY": "mock-api-key"}) | ||
def test_ask_gemini(GenerativeModel): | ||
inputs = ["what is 1 + 1"] | ||
|
||
def get_input(): | ||
if len(inputs) == 0: | ||
raise InputInterrupt() | ||
|
||
return inputs.pop() | ||
|
||
def parse_args(): | ||
return argparse.Namespace( | ||
dry=False, | ||
inputs=[], | ||
line_target=0, | ||
no_markdown=True, | ||
no_transcribe=True, | ||
template=None, | ||
) | ||
|
||
mock = GenerativeModel() | ||
mock.start_chat().send_message().text = "mock-response" | ||
|
||
with patch("sys.stdout", new=StringIO()) as captured_output: | ||
main(inputter=get_input, parse_args=parse_args) | ||
lines = [line for line in captured_output.getvalue().split("\n") if line] | ||
assert lines[0] == " -) ... ..." | ||
assert lines[1] == "mock-response" | ||
assert lines[-1] == "Bye ..." | ||
assert len(lines) == 3 |