| 1 | """Cross-lang contract: C# fixtures → Python bridge reads.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import subprocess |
| 6 | from pathlib import Path |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from pywitdb._bridge.client import bridge_available |
| 11 | |
| 12 | FIXTURES_DIR = Path(__file__).resolve().parent / "fixtures" / "generated" |
| 13 | FIXTURES_PROJECT = ( |
| 14 | Path(__file__).resolve().parent / "fixtures" / "cs" / "WitDbFixtures" / "WitDbFixtures.csproj" |
| 15 | ) |
| 16 | |
| 17 | |
| 18 | def _ensure_fixtures() -> None: |
| 19 | FIXTURES_DIR.mkdir(parents=True, exist_ok=True) |
| 20 | subprocess.run( |
| 21 | ["dotnet", "run", "--project", str(FIXTURES_PROJECT), "-c", "Release", "--", str(FIXTURES_DIR)], |
| 22 | check=True, |
| 23 | capture_output=True, |
| 24 | text=True, |
| 25 | ) |
| 26 | |
| 27 | |
| 28 | @pytest.fixture(scope="module") |
| 29 | def fixtures() -> Path: |
| 30 | try: |
| 31 | _ensure_fixtures() |
| 32 | except (subprocess.CalledProcessError, FileNotFoundError) as exc: |
| 33 | pytest.skip(f"cannot generate C# fixtures: {exc}") |
| 34 | return FIXTURES_DIR |
| 35 | |
| 36 | |
| 37 | @pytest.mark.skipif(not bridge_available(), reason="witdb-bridge not built") |
| 38 | def test_t1a_plain_btree_reads_cs_fixture(fixtures: Path) -> None: |
| 39 | import pywitdb |
| 40 | |
| 41 | path = str(fixtures / "t1a-plain-btree.witdb") |
| 42 | with pywitdb.open(path, backend="bridge", create=False) as db: |
| 43 | assert db.get(b"contract:t1a") == b"plain-btree" |
| 44 | |
| 45 | |
| 46 | @pytest.mark.skipif(not bridge_available(), reason="witdb-bridge not built") |
| 47 | def test_t1b_aes_intercom_like(fixtures: Path) -> None: |
| 48 | import pywitdb |
| 49 | |
| 50 | path = str(fixtures / "t1b-aes-intercom-like.witdb") |
| 51 | with pywitdb.open(path, password="fixture-secret", backend="bridge", create=False) as db: |
| 52 | assert db.get(b"contract:t1b") == b"aes-gcm" |
| 53 | |