-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/optimal-test-suite' into feat/v0.4
- Loading branch information
Showing
30 changed files
with
1,367 additions
and
263 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
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
Empty file.
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,32 @@ | ||
from collections import defaultdict | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
if TYPE_CHECKING: | ||
from pytest_mock import MockerFixture | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def llm_event_spy(agentops_client, mocker: "MockerFixture") -> dict[str, "MockerFixture"]: | ||
""" | ||
Fixture that provides spies on both providers' response handling | ||
These fixtures are reset on each test run (function scope). To use it, | ||
simply pass it as an argument to the test function. Example: | ||
``` | ||
def test_my_test(llm_event_spy): | ||
# test code here | ||
llm_event_spy["litellm"].assert_called_once() | ||
``` | ||
""" | ||
from agentops.llms.providers.anthropic import AnthropicProvider | ||
from agentops.llms.providers.litellm import LiteLLMProvider | ||
from agentops.llms.providers.openai import OpenAiProvider | ||
|
||
return { | ||
"litellm": mocker.spy(LiteLLMProvider(agentops_client), "handle_response"), | ||
"openai": mocker.spy(OpenAiProvider(agentops_client), "handle_response"), | ||
"anthropic": mocker.spy(AnthropicProvider(agentops_client), "handle_response"), | ||
} |
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,26 @@ | ||
import builtins | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def hide_available_pkg(monkeypatch): | ||
""" | ||
Hide the availability of a package by mocking the __import__ function. | ||
Usage: | ||
@pytest.mark.usefixtures('hide_available_pkg') | ||
def test_message(): | ||
with pytest.raises(ImportError, match='Install "pkg" to use test_function'): | ||
foo('test_function') | ||
Source: | ||
https://stackoverflow.com/questions/60227582/making-a-python-test-think-an-installed-package-is-not-available | ||
""" | ||
import_orig = builtins.__import__ | ||
|
||
def mocked_import(name, *args, **kwargs): | ||
if name == "pkg": | ||
raise ImportError() | ||
return import_orig(name, *args, **kwargs) | ||
|
||
monkeypatch.setattr(builtins, "__import__", mocked_import) |
Oops, something went wrong.