zerodb-pytest 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tests/__init__.py ADDED
File without changes
@@ -0,0 +1,80 @@
1
+ """Tests for zerodb-pytest fixtures package. Refs #2459.
2
+
3
+ MockZeroDBClient's methods are async (remember/recall/search/close) to
4
+ mirror the real ZeroDBClient's interface -- that's the whole point of a
5
+ mock: a consumer writes `await zerodb_client.remember(...)` in their own
6
+ test exactly as they would against the real client. The original version
7
+ of this file called these methods synchronously and asserted a bare list
8
+ return, which never matched the implementation OR this package's own
9
+ documented README quick-start (`@pytest.mark.asyncio` + `await ...` +
10
+ `result["count"]`). Rewritten to match the real, documented contract.
11
+ """
12
+
13
+ import pytest
14
+
15
+ from zerodb_pytest.fixtures import MockZeroDBClient, MockZeroDBProject
16
+
17
+
18
+ class TestMockZeroDBClient:
19
+ @pytest.mark.asyncio
20
+ async def test_remember_stores_memory(self):
21
+ client = MockZeroDBClient()
22
+ await client.remember("User likes dark mode", namespace="prefs")
23
+ result = await client.recall("dark mode", namespace="prefs")
24
+ assert result["count"] > 0
25
+ assert "dark mode" in result["results"][0]["content"]
26
+
27
+ @pytest.mark.asyncio
28
+ async def test_recall_returns_matching(self):
29
+ client = MockZeroDBClient()
30
+ await client.remember("likes cats", namespace="n1")
31
+ await client.remember("likes dogs", namespace="n1")
32
+ result = await client.recall("cats", namespace="n1")
33
+ assert any("cats" in m["content"] for m in result["results"])
34
+
35
+ @pytest.mark.asyncio
36
+ async def test_search_returns_results(self):
37
+ client = MockZeroDBClient()
38
+ await client.remember("test data", namespace="ns")
39
+ result = await client.search("test", namespace="ns")
40
+ assert isinstance(result["results"], list)
41
+ assert result["count"] == 1
42
+
43
+ @pytest.mark.asyncio
44
+ async def test_reset_clears_all(self):
45
+ client = MockZeroDBClient()
46
+ await client.remember("data1", namespace="ns")
47
+ await client.remember("data2", namespace="ns")
48
+ client.reset()
49
+ result = await client.recall("data", namespace="ns")
50
+ assert result["count"] == 0
51
+
52
+ @pytest.mark.asyncio
53
+ async def test_health_returns_ok(self):
54
+ client = MockZeroDBClient()
55
+ result = await client.health()
56
+ assert result["status"] == "ok"
57
+
58
+ @pytest.mark.asyncio
59
+ async def test_close_is_a_noop_that_does_not_raise(self):
60
+ client = MockZeroDBClient()
61
+ await client.close()
62
+
63
+
64
+ class TestMockZeroDBProject:
65
+ def test_namespace_management(self):
66
+ project = MockZeroDBProject(project_id="test-proj")
67
+ assert project.project_id == "test-proj"
68
+ project.add_namespace("custom")
69
+ assert "custom" in project.namespaces
70
+
71
+ def test_project_defaults(self):
72
+ # MockZeroDBProject has no .client/._client attribute -- it was
73
+ # never part of the documented design (README's own Quick Start and
74
+ # the zerodb_project fixture's docstring only ever exercise
75
+ # project_id, add_namespace(), and namespaces). The prior version of
76
+ # this test asserted a feature that was never built or promised.
77
+ project = MockZeroDBProject(project_id="p1")
78
+ assert project.project_id == "p1"
79
+ assert project.name == "Test Project"
80
+ assert project.namespaces == ["default"]
@@ -0,0 +1,18 @@
1
+ """ZeroDB pytest fixtures and helpers - Refs #1501"""
2
+
3
+ from zerodb_pytest.fixtures import (
4
+ MockZeroDBClient,
5
+ MockZeroDBProject,
6
+ zerodb_client,
7
+ zerodb_memory,
8
+ zerodb_project,
9
+ )
10
+
11
+ __all__ = [
12
+ "MockZeroDBClient",
13
+ "MockZeroDBProject",
14
+ "zerodb_client",
15
+ "zerodb_memory",
16
+ "zerodb_project",
17
+ ]
18
+ __version__ = "0.1.0"
@@ -0,0 +1,13 @@
1
+ """Auto-loaded conftest with common ZeroDB fixtures - Refs #1501
2
+
3
+ This module is automatically discovered by pytest when zerodb-pytest is installed,
4
+ providing zerodb_client, zerodb_memory, and zerodb_project fixtures.
5
+ """
6
+
7
+ from zerodb_pytest.fixtures import ( # noqa: F401
8
+ MockZeroDBClient,
9
+ MockZeroDBProject,
10
+ zerodb_client,
11
+ zerodb_memory,
12
+ zerodb_project,
13
+ )
@@ -0,0 +1,136 @@
1
+ """Pytest fixtures for ZeroDB testing - Refs #1501"""
2
+
3
+ from typing import Any, Dict, List, Optional
4
+ from unittest.mock import AsyncMock
5
+
6
+ import pytest
7
+
8
+
9
+ class MockZeroDBClient:
10
+ """Mock ZeroDB client for testing without real API calls."""
11
+
12
+ def __init__(self, project_id: str = "test-project", api_key: str = "test-key"):
13
+ self.project_id = project_id
14
+ self.api_key = api_key
15
+ self.base_url = "https://api.ainative.studio"
16
+ self._memories: List[Dict[str, Any]] = []
17
+ self._call_log: List[Dict[str, Any]] = []
18
+
19
+ async def health(self) -> dict:
20
+ """Return mock health status."""
21
+ self._call_log.append({"method": "health"})
22
+ return {"status": "ok", "service": "zerodb", "mock": True}
23
+
24
+ async def remember(
25
+ self,
26
+ content: str,
27
+ namespace: str = "default",
28
+ metadata: Optional[dict] = None,
29
+ ) -> dict:
30
+ """Store a memory in the mock store."""
31
+ memory_id = f"mem_{len(self._memories)}"
32
+ entry = {
33
+ "id": memory_id,
34
+ "content": content,
35
+ "namespace": namespace,
36
+ "metadata": metadata or {},
37
+ "project_id": self.project_id,
38
+ }
39
+ self._memories.append(entry)
40
+ self._call_log.append({"method": "remember", "content": content, "namespace": namespace})
41
+ return {"id": memory_id, "status": "stored"}
42
+
43
+ async def recall(
44
+ self,
45
+ query: str,
46
+ namespace: str = "default",
47
+ top_k: int = 5,
48
+ ) -> dict:
49
+ """Recall memories matching the query from mock store."""
50
+ self._call_log.append({"method": "recall", "query": query, "namespace": namespace})
51
+ matches = [
52
+ m for m in self._memories
53
+ if m["namespace"] == namespace and query.lower() in m["content"].lower()
54
+ ]
55
+ return {
56
+ "results": matches[:top_k],
57
+ "count": len(matches[:top_k]),
58
+ }
59
+
60
+ async def search(
61
+ self,
62
+ query: str,
63
+ namespace: str = "default",
64
+ top_k: int = 10,
65
+ ) -> dict:
66
+ """Search memories from mock store."""
67
+ self._call_log.append({"method": "search", "query": query, "namespace": namespace})
68
+ matches = [
69
+ m for m in self._memories
70
+ if m["namespace"] == namespace
71
+ ]
72
+ return {
73
+ "results": matches[:top_k],
74
+ "count": len(matches[:top_k]),
75
+ }
76
+
77
+ async def close(self):
78
+ """No-op for mock client."""
79
+ self._call_log.append({"method": "close"})
80
+
81
+ def reset(self):
82
+ """Clear all stored memories and call logs."""
83
+ self._memories.clear()
84
+ self._call_log.clear()
85
+
86
+
87
+ class MockZeroDBProject:
88
+ """Mock project context for ZeroDB testing."""
89
+
90
+ def __init__(self, project_id: str = "test-project", name: str = "Test Project"):
91
+ self.project_id = project_id
92
+ self.name = name
93
+ self.namespaces: List[str] = ["default"]
94
+
95
+ def add_namespace(self, namespace: str):
96
+ """Add a namespace to the mock project."""
97
+ if namespace not in self.namespaces:
98
+ self.namespaces.append(namespace)
99
+
100
+
101
+ @pytest.fixture
102
+ def zerodb_client():
103
+ """Provide a mock ZeroDB client for testing.
104
+
105
+ Usage:
106
+ def test_something(zerodb_client):
107
+ await zerodb_client.remember("hello")
108
+ result = await zerodb_client.recall("hello")
109
+ assert result["count"] == 1
110
+ """
111
+ client = MockZeroDBClient()
112
+ yield client
113
+ client.reset()
114
+
115
+
116
+ @pytest.fixture
117
+ def zerodb_memory():
118
+ """Provide a mock ZeroDB client pre-configured for memory operations.
119
+
120
+ Alias for zerodb_client with a memory-focused name.
121
+ """
122
+ client = MockZeroDBClient()
123
+ yield client
124
+ client.reset()
125
+
126
+
127
+ @pytest.fixture
128
+ def zerodb_project():
129
+ """Provide a mock ZeroDB project context for testing.
130
+
131
+ Usage:
132
+ def test_project(zerodb_project):
133
+ assert zerodb_project.project_id == "test-project"
134
+ zerodb_project.add_namespace("custom")
135
+ """
136
+ return MockZeroDBProject()
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: zerodb-pytest
3
+ Version: 0.1.0
4
+ Summary: Pytest fixtures and mocks for ZeroDB testing
5
+ Home-page: https://github.com/AINative-Studio/core
6
+ Author: AINative Studio
7
+ Author-email: AINative Studio <dev@ainative.studio>
8
+ License: MIT
9
+ Project-URL: Homepage, https://ainative.studio/products/zerodb
10
+ Project-URL: Repository, https://github.com/AINative-Studio/core
11
+ Project-URL: Bug Tracker, https://github.com/AINative-Studio/core/issues
12
+ Keywords: zerodb,pytest,testing,fixtures,ainative,vector-database,python
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Framework :: Pytest
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: pytest>=7.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
22
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
23
+ Dynamic: author
24
+ Dynamic: home-page
25
+ Dynamic: requires-python
26
+
27
+ # zerodb-pytest
28
+
29
+ Pytest fixtures and helpers for testing ZeroDB integrations.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install zerodb-pytest
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ Once installed, fixtures are auto-registered via the `pytest11` entry point. Just use them in your tests:
40
+
41
+ ```python
42
+ import pytest
43
+
44
+ @pytest.mark.asyncio
45
+ async def test_memory_storage(zerodb_client):
46
+ await zerodb_client.remember("Important fact about Python")
47
+ result = await zerodb_client.recall("Python")
48
+ assert result["count"] == 1
49
+
50
+ @pytest.mark.asyncio
51
+ async def test_with_project(zerodb_project):
52
+ assert zerodb_project.project_id == "test-project"
53
+ zerodb_project.add_namespace("custom")
54
+ assert "custom" in zerodb_project.namespaces
55
+ ```
56
+
57
+ ## Available Fixtures
58
+
59
+ ### `zerodb_client`
60
+
61
+ A `MockZeroDBClient` instance with in-memory storage. Supports `remember()`, `recall()`, `search()`, and `health()`. Automatically reset after each test.
62
+
63
+ ### `zerodb_memory`
64
+
65
+ Alias for `zerodb_client` for memory-focused test code.
66
+
67
+ ### `zerodb_project`
68
+
69
+ A `MockZeroDBProject` with a default project ID and namespace management.
70
+
71
+ ## Mock Classes
72
+
73
+ You can also import mock classes directly:
74
+
75
+ ```python
76
+ from zerodb_pytest import MockZeroDBClient, MockZeroDBProject
77
+
78
+ client = MockZeroDBClient(project_id="custom-id")
79
+ ```
80
+
81
+ ## License
82
+
83
+ MIT
@@ -0,0 +1,10 @@
1
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ tests/test_zerodb_pytest.py,sha256=f9vqjemXOLLO478fVBKYIxTcQ09WUTcOtv7iUpZW_pg,3314
3
+ zerodb_pytest/__init__.py,sha256=zhqYMhFIddsjDGelhRyEvqxuKJx8Mzm3Ml7cyyr3XaY,347
4
+ zerodb_pytest/conftest.py,sha256=8yrvKjgkUKRpvIgw0cEIewtIkNfgP_qVp8WWynoxma8,379
5
+ zerodb_pytest/fixtures.py,sha256=L5SZ4qvM0g8ByjdnM2KUNJTkis9hraGiUuPhYHWeI2M,4075
6
+ zerodb_pytest-0.1.0.dist-info/METADATA,sha256=dGUL91jasiMfMR7VmjtMJIlOdh6eXLl-QjZaNgTUHkI,2264
7
+ zerodb_pytest-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ zerodb_pytest-0.1.0.dist-info/entry_points.txt,sha256=vtAmVXepOUKxRXpzAIUy9D6U2EAaXHfPFuoaByNdNJQ,43
9
+ zerodb_pytest-0.1.0.dist-info/top_level.txt,sha256=dW2P6Y8NxBo2aqS2fmJzsFaY3ywWyTiwsjEVvGApUBw,20
10
+ zerodb_pytest-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ zerodb = zerodb_pytest.conftest
@@ -0,0 +1,2 @@
1
+ tests
2
+ zerodb_pytest