Spaces:
Paused
Paused
File size: 1,332 Bytes
0523c2e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Shared fixtures for the RCA workbench tests.
The full diagnostic battery per planted cause is computed once per session
(it is deterministic), and the API tests run against an isolated runs/rca
root in a tmp dir.
"""
from __future__ import annotations
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from sensorflow.rca import diagnostics as dg, scoring, store
from sensorflow.rca.models import ROOT_CAUSES
from sensorflow.rca.scenario import generate_scenario
SEED = 7
@pytest.fixture(scope="session")
def batteries():
"""{cause: (bundle, battery, scoreboard, tree)} computed once."""
out = {}
for cause in ROOT_CAUSES:
bundle = generate_scenario(cause, seed=SEED)
battery = dg.run_all(bundle)
board = scoring.build_scoreboard(bundle, battery=battery)
tree = scoring.evaluate_decision_tree(bundle, battery=battery)
out[cause] = (bundle, battery, board, tree)
return out
@pytest.fixture()
def rca_client(tmp_path):
store.set_rca_root(str(tmp_path / "rca"))
from sensorflow.rca import api as rca_api
rca_api._battery_cache.clear()
app = FastAPI()
app.include_router(rca_api.router)
with TestClient(app) as client:
yield client
store.set_rca_root("runs/rca")
rca_api._battery_cache.clear()
|