mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-13 07:12:27 +00:00
The pages describing this code lived in lancedb/docs, a repository with ten stars that neither contributing guide mentioned. A user who hit a wrong page while reading the source had to find a separate, near-invisible repository to fix it. These 102 pages now sit beside the code, and a documentation fix is a pull request in the repository the reader already had open. `docs/web` is a complete Mintlify site: `cd docs/web && mint dev` serves it with no other checkout. Enterprise pages stay private and are merged in when the published site is assembled, so links into them do not resolve here — every open-source page does. `docs/web-tests` holds the tests the code examples are extracted from. They ran against a published wheel before; here they can run against this repository's own SDK, so an example that stops compiling fails the pull request that broke it rather than being noticed later. Both directories sit beside `docs/src` and are invisible to it: mkdocs reads `docs_dir: src`, so the SDK reference builds and deploys exactly as before.
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import lancedb
|
|
import pytest
|
|
import pytest_asyncio
|
|
from lancedb.db import AsyncConnection, DBConnection
|
|
|
|
|
|
class DatabasePathFactory:
|
|
"""Create per-test database directories and ensure they get removed."""
|
|
|
|
def __init__(self, base_dir: Path) -> None:
|
|
self._base_dir = base_dir
|
|
self._created: list[Path] = []
|
|
|
|
def __call__(self, name: str) -> Path:
|
|
safe_name = name.replace("/", "_")
|
|
path = self._base_dir / safe_name
|
|
if path.exists():
|
|
shutil.rmtree(path, ignore_errors=True)
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
self._created.append(path)
|
|
return path
|
|
|
|
def cleanup(self) -> None:
|
|
for path in reversed(self._created):
|
|
shutil.rmtree(path, ignore_errors=True)
|
|
self._created.clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def db_path_factory(tmp_path: Path):
|
|
factory = DatabasePathFactory(tmp_path)
|
|
yield factory
|
|
factory.cleanup()
|
|
|
|
|
|
@pytest.fixture
|
|
def mem_db() -> DBConnection:
|
|
return lancedb.connect("memory://")
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_db(db_path_factory) -> DBConnection:
|
|
"""Create a temporary database connection for testing."""
|
|
db_path = db_path_factory("tmp_db")
|
|
return lancedb.connect(str(db_path))
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def mem_db_async() -> AsyncConnection:
|
|
return await lancedb.connect_async("memory://")
|