bit-atlas / tests /conftest.py
Bit-Trading-Company's picture
CI deploy local
15ff349 verified
Raw
History Blame Contribute Delete
3.67 kB
"""Shared fixtures.
Every test in this suite runs offline with no credentials. CI runs the suite
in a job that has no secrets in scope, so a test that needed a token could not
gate a deploy -- which would defeat the point of having the gate.
"""
from __future__ import annotations
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent # space/
REPO = ROOT.parent # repo root
# The vendored bit-ui submodule, plus the space and repo roots.
VENDOR = ROOT / "vendor" / "bit-ui"
for path in (str(VENDOR), str(ROOT), str(REPO)):
if path not in sys.path:
sys.path.insert(0, path)
if not (VENDOR / "bit_ui").exists(): # pragma: no cover
raise RuntimeError(
"space/vendor/bit-ui is empty -- the submodule was not checked out.\n"
" git submodule update --init --recursive")
@pytest.fixture(autouse=True)
def _no_credentials(monkeypatch):
"""Guarantee no test can accidentally reach the Hub with a real token."""
for name in ("HF_TOKEN", "HF_WRITE_TOKEN", "HUGGING_FACE_HUB_TOKEN"):
monkeypatch.delenv(name, raising=False)
def make_row(model_id, **overrides):
"""One index row with sensible defaults, overridable per test."""
row = {
"id": model_id,
"author": model_id.split("/")[0],
"task": "sentiment",
"asset_class": "general",
"relevant": "yes",
"license": "apache-2.0",
"license_bucket": "permissive",
"downloads": 1000,
"downloads_30d": 100,
"likes": 10,
"created": "2024-01-01T00:00:00+00:00",
"last_modified": "2026-06-01T00:00:00+00:00",
"library": "transformers",
"pipeline_tag": "text-classification",
"params": "110M",
"has_weights": True,
"gated": False,
"base_model": "",
"adapter_family": "",
"training_data_summary": "Some corpus.",
"maintained": True,
"has_eval": True,
"red_flags": [],
"auto_classified": True,
"verified": False,
"indexed_at": "2026-08-20T06:14:00+00:00",
}
row.update(overrides)
return row
@pytest.fixture
def rows():
"""A small index: 3 maintained, 2 unmaintained, one verified."""
return [
make_row("ProsusAI/finbert", verified=True, downloads_30d=4755781,
likes=1221, license="", license_bucket="none",
red_flags=["no license declared"]),
make_row("yiyanghkust/finbert-tone", base_model="ProsusAI/finbert",
downloads_30d=731455, likes=412, asset_class="equities",
license="cc-by-nc-4.0", license_bucket="restricted"),
make_row("amazon/chronos-t5-small", task="forecasting",
asset_class="macro", adapter_family="chronos",
downloads_30d=986500, likes=731),
make_row("fx-research/forex-lstm-eurusd", task="forecasting",
asset_class="forex", maintained=False, has_eval=False,
training_data_summary="", license="", license_bucket="none",
last_modified="2023-01-01T00:00:00+00:00",
red_flags=["training window overlaps evaluation window"]),
make_row("dead-lab/old-stock-bert", maintained=False, has_eval=False,
training_data_summary="",
last_modified="2022-05-01T00:00:00+00:00"),
]
@pytest.fixture
def index(rows):
import pandas as pd
from src import atlas
built = atlas.Index(pd.DataFrame(rows))
built.dataset_repo = "Bit-Trading-Company/bit-finance-atlas"
return built