Build file-backed read-only CachingStore instances for tests.
(
tmp_path: Path,
)
| 33 | |
| 34 | @pytest.fixture |
| 35 | def cached_store_factory( |
| 36 | tmp_path: Path, |
| 37 | ) -> Generator[_CachedStoreFactory, None, None]: |
| 38 | """Build file-backed read-only CachingStore instances for tests.""" |
| 39 | stores: list[CachingStore] = [] |
| 40 | |
| 41 | def make( |
| 42 | manpages: Sequence[ParsedManpage], |
| 43 | *, |
| 44 | max_cache_bytes: int | None = None, |
| 45 | max_entry_bytes: int | None = None, |
| 46 | max_entries: int | None = None, |
| 47 | ) -> CachingStore: |
| 48 | db_path = tmp_path / f"cache-{len(stores)}.db" |
| 49 | writable = Store.create(str(db_path)) |
| 50 | for manpage in manpages: |
| 51 | writable.add_manpage(manpage, _make_raw()) |
| 52 | writable.close() |
| 53 | |
| 54 | kwargs: dict[str, int] = {} |
| 55 | if max_cache_bytes is not None: |
| 56 | kwargs["max_cache_bytes"] = max_cache_bytes |
| 57 | if max_entry_bytes is not None: |
| 58 | kwargs["max_entry_bytes"] = max_entry_bytes |
| 59 | if max_entries is not None: |
| 60 | kwargs["max_entries"] = max_entries |
| 61 | |
| 62 | cached = CachingStore(str(db_path), **kwargs) |
| 63 | stores.append(cached) |
| 64 | return cached |
| 65 | |
| 66 | yield make |
| 67 | |
| 68 | for cached in stores: |
| 69 | cached.close() |
| 70 | |
| 71 | |
| 72 | def _make_manpage( |
no test coverage detected