|
| 1 | +# tests/sdk/test_client.py |
| 2 | +import pytest |
| 3 | +from pageindex.client import PageIndexClient, LocalClient, CloudClient |
| 4 | + |
| 5 | + |
| 6 | +def test_local_client_is_pageindex_client(tmp_path): |
| 7 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 8 | + assert isinstance(client, PageIndexClient) |
| 9 | + |
| 10 | + |
| 11 | +def test_cloud_client_is_pageindex_client(): |
| 12 | + client = CloudClient(api_key="pi-test") |
| 13 | + assert isinstance(client, PageIndexClient) |
| 14 | + |
| 15 | + |
| 16 | +def test_collection_default_name(tmp_path): |
| 17 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 18 | + col = client.collection() |
| 19 | + assert col.name == "default" |
| 20 | + |
| 21 | + |
| 22 | +def test_collection_custom_name(tmp_path): |
| 23 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 24 | + col = client.collection("papers") |
| 25 | + assert col.name == "papers" |
| 26 | + |
| 27 | + |
| 28 | +def test_list_collections_empty(tmp_path): |
| 29 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 30 | + assert client.list_collections() == [] |
| 31 | + |
| 32 | + |
| 33 | +def test_list_collections_after_create(tmp_path): |
| 34 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 35 | + client.collection("papers") |
| 36 | + assert "papers" in client.list_collections() |
| 37 | + |
| 38 | + |
| 39 | +def test_delete_collection(tmp_path): |
| 40 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 41 | + client.collection("papers") |
| 42 | + client.delete_collection("papers") |
| 43 | + assert "papers" not in client.list_collections() |
| 44 | + |
| 45 | + |
| 46 | +def test_register_parser(tmp_path): |
| 47 | + client = LocalClient(model="gpt-4o", storage_path=str(tmp_path / "pi")) |
| 48 | + class FakeParser: |
| 49 | + def supported_extensions(self): return [".txt"] |
| 50 | + def parse(self, file_path, **kwargs): pass |
| 51 | + client.register_parser(FakeParser()) |
0 commit comments