diff --git a/scope3ai/api/client.py b/scope3ai/api/client.py index 5c37615..6d22d9c 100644 --- a/scope3ai/api/client.py +++ b/scope3ai/api/client.py @@ -194,52 +194,3 @@ async def execute_request( if response_model: return response_model.model_validate(response.json()) return response.json() - - -if __name__ == "__main__": - from .types import Model - - funcs_to_test = [ - ["model", {}], - ["model", {"family": Family.claud}], - ["gpu", {}], - ["node", {}], - ["node", {"cloud": CloudProvider.aws}], - # ["node", {"service": ManagedServiceProvider.azure_ml}], - ["impact", {"rows": []}], - [ - "impact", - { - "rows": [ - ImpactRow( - model=Model(id="gpt_4o"), - input_tokens=1000, - output_tokens=200, - ) - ] - }, - ], - ] - - def test_sync_client(): - print("Testing synchronous client") - client = Client() - for name, kwargs in funcs_to_test: - print(f"- testing {name} with kwargs {kwargs}") - func = getattr(client, name) - result = func(**kwargs) - print(f"{result}") - - async def test_async_client(): - print("Testing asynchronous client") - client = AsyncClient() - for name, kwargs in funcs_to_test: - print(f"- testing {name}(**{kwargs})") - func = getattr(client, name) - result = await func(**kwargs) - print(f"{result}") - - import asyncio - - test_sync_client() - asyncio.run(test_async_client()) diff --git a/tests/conftest.py b/tests/conftest.py index 04499d4..e6617fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,3 +77,23 @@ def tracer_with_sync_init(docker_api_info): yield scope3 finally: scope3.close() + + +@pytest.fixture +def api_client(docker_api_info): + from scope3ai.api.client import Client + + yield Client( + api_key=docker_api_info["api_key"], + api_url=docker_api_info["api_url"], + ) + + +@pytest.fixture +def async_api_client(docker_api_info): + from scope3ai.api.client import AsyncClient + + yield AsyncClient( + api_key=docker_api_info["api_key"], + api_url=docker_api_info["api_url"], + ) diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..b333914 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,40 @@ +import pytest + + +def test_api_node(api_client): + response = api_client.node() + assert response is not None + assert len(response.nodes) + + +@pytest.mark.asyncio +async def test_async_api_node(async_api_client): + response = await async_api_client.node() + assert response is not None + assert len(response.nodes) + + +def test_api_gpu(api_client): + response = api_client.gpu() + assert response is not None + assert len(response.gpus) + + +@pytest.mark.asyncio +async def test_async_api_gpu(async_api_client): + response = await async_api_client.gpu() + assert response is not None + assert len(response.gpus) + + +def test_api_model(api_client): + response = api_client.model() + assert response is not None + assert len(response.models) + + +@pytest.mark.asyncio +async def test_async_api_model(async_api_client): + response = await async_api_client.model() + assert response is not None + assert len(response.models)