Skip to content

Commit

Permalink
✅ Add test for Gemini invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhomer committed Sep 21, 2024
1 parent 945712f commit 37101d3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ask/tests/test_ask_gemini.py
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

0 comments on commit 37101d3

Please sign in to comment.