Forge
pythonf8555a15
1"""Integration tests for native ctypes backend (skip if witdb.dll missing)."""
2
3from __future__ import annotations
4
5import tempfile
6from pathlib import Path
7
8import pytest
9
10from pywitdb._native.db import native_available, open_native
11from pywitdb._native.lib import load_native_lib
12
13
14pytestmark = pytest.mark.skipif(
15 not native_available(), reason="libwitdb not built or not on PATH"
16)
17
18
19def test_abi_version() -> None:
20 lib = load_native_lib()
21 assert lib is not None
22 assert lib.dll.witdb_abi_version() == 1
23
24
25def test_kv_roundtrip() -> None:
26 with tempfile.TemporaryDirectory() as tmp:
27 path = str(Path(tmp) / "test.witdb")
28 db = open_native(path, create=True)
29 try:
30 db.put(b"meta:fv", b"94266")
31 assert db.get(b"meta:fv") == b"94266"
32 assert db.get(b"missing") is None
33 assert db.delete(b"meta:fv") is True
34 assert db.get(b"meta:fv") is None
35 finally:
36 db.close()
37
38
39def test_public_open_native_backend() -> None:
40 import pywitdb
41
42 with tempfile.TemporaryDirectory() as tmp:
43 path = str(Path(tmp) / "via_api.witdb")
44 with pywitdb.open(path, backend="native") as db:
45 db.put(b"k", b"v")
46 assert db.get(b"k") == b"v"
47
View only · write via MCP/CIDE