Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions scope3ai/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
40 changes: 40 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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)
Loading