-
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.
* test: add `__init__` to make `tests/` a package * test: add llm_event_spy fixture for tests * test: add VCR.py fixture for HTTP interaction recording * deps: group integration-testing * test: add fixture to mock package availability in tests * test: Add integration tests for OpenAI provider and features * test: add tests for concurrent API requests handling * Improve vcr.py configuration Signed-off-by: Teo <teocns@gmail.com> * ruff Signed-off-by: Teo <teocns@gmail.com> * chore(pyproject): update pytest options and loop scope * chore(tests): update vcr.py ignore_hosts and options * pyproject.toml Signed-off-by: Teo <teocns@gmail.com> * centralize teardown in conftest.py (clear singletons, end all sessions) Signed-off-by: Teo <teocns@gmail.com> * change vcr_config scope to session Signed-off-by: Teo <teocns@gmail.com> * integration: auto start agentops session Signed-off-by: Teo <teocns@gmail.com> * Move unit tests to dedicated folder (tests/unit) Signed-off-by: Teo <teocns@gmail.com> * Isolate vcr_config import into tests/integration Signed-off-by: Teo <teocns@gmail.com> * configure pytest to run only unit tests by default, and include integration tests only when explicitly specified. Signed-off-by: Teo <teocns@gmail.com> * ci(python-tests): separate job between unit-integration tests * set python-tests timeout to 5 minutes Signed-off-by: Teo <teocns@gmail.com> * ruff Signed-off-by: Teo <teocns@gmail.com> * Implement jwt fixture, centralized reusable mock_req into conftest.py Signed-off-by: Teo <teocns@gmail.com> reauthorize Signed-off-by: Teo <teocns@gmail.com> * ci(python-tests): simplify env management, remove cov from integration-teests Signed-off-by: Teo <teocns@gmail.com> * ruff Signed-off-by: Teo <teocns@gmail.com> * fix: cassette for test_concurrent_api_requests Signed-off-by: Teo <teocns@gmail.com> * Cleanup vcr.py comments Signed-off-by: Teo <teocns@gmail.com> * add a `TODO` for removing `vcrpy` git version after its release * refactor openai assistants response handling for easier testing * add more keys for different llm providers * add integration tests for other providers * remove openai version limitation * add providers as deps * chore: add mistralai to test dependencies * remove `mistral` from dependency since its incorrect * ruff * re-record cassettes * tests/fixtures/providers: fallback to `test-api-key` if no provider is found all provider fixtures will: Use the actual API key if it's set in the environment Fall back to "test-api-key" if no environment variable is found Signed-off-by: Teo <teocns@gmail.com> * set keys for `litellm` * Improve tests/integration/test_llm_providers.py openai assistants Signed-off-by: Teo <teocns@gmail.com> * Make integration tests appropriately skip, regenerate x1 cassette Signed-off-by: Teo <teocns@gmail.com> * explicit tests/integration/conftest finxtures import Signed-off-by: Teo <teocns@gmail.com> * deps: improve dev packages versionings * Make integration tests run with python 3.12 Signed-off-by: Teo <teocns@gmail.com> * add uv.lock Signed-off-by: Teo <teocns@gmail.com> * test concurrent api requests: remove matcher on method, possibly causing contingent error Signed-off-by: Teo <teocns@gmail.com> * Run static-analysis with python 3.12.2 Signed-off-by: Teo <teocns@gmail.com> --------- Signed-off-by: Teo <teocns@gmail.com> Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
- Loading branch information
Showing
41 changed files
with
7,335 additions
and
330 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 @@ | ||
uv.lock binary |
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
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.