Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
djcopley committed May 13, 2024
1 parent fc30481 commit 33f697a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ def tmp_shelloracle_home(monkeypatch, tmp_path):
def set_config(monkeypatch, tmp_shelloracle_home):
config_path = tmp_shelloracle_home / "config.toml"

def setter(config: dict) -> Configuration:
def _set_config(config: dict) -> Configuration:
with config_path.open("w") as f:
tomlkit.dump(config, f)
configuration = Configuration(config_path)
monkeypatch.setattr("shelloracle.config._config", configuration)
return configuration

yield setter
yield _set_config

config_path.unlink()

14 changes: 6 additions & 8 deletions tests/providers/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from unittest.mock import MagicMock

import openai
import openai.resources
import pytest


Expand Down Expand Up @@ -31,15 +29,15 @@ async def __anext__(self):
if self.answer_index < len(self.answer_deltas):
answer_chunk = self.answer_deltas[self.answer_index]
self.answer_index += 1
choice = MagicMock()
choice.delta.content = answer_chunk
chunk = MagicMock()
chunk.delta.content = answer_chunk
answer = MagicMock()
answer.choices = [chunk]
return answer
chunk.choices = [choice]
return chunk
else:
raise StopAsyncIteration

async def mock_acreate(*args, **kwargs):
return AsyncChatCompletionIterator("cat test.py")
return AsyncChatCompletionIterator("head -c 100 /dev/urandom | hexdump -C")

monkeypatch.setattr(openai.resources.chat.AsyncCompletions, "create", mock_acreate)
monkeypatch.setattr("openai.resources.chat.AsyncCompletions.create", mock_acreate)
2 changes: 1 addition & 1 deletion tests/providers/test_localai.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ async def test_generate(self, mock_asyncopenai, localai_instance):
result = ""
async for response in localai_instance.generate(""):
result += response
assert result == "cat test.py"
assert result == "head -c 100 /dev/urandom | hexdump -C"
2 changes: 1 addition & 1 deletion tests/providers/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ async def test_generate(self, mock_asyncopenai, openai_instance):
result = ""
async for response in openai_instance.generate(""):
result += response
assert result == "cat test.py"
assert result == "head -c 100 /dev/urandom | hexdump -C"

0 comments on commit 33f697a

Please sign in to comment.