Spaces:
Running on Zero
Running on Zero
File size: 1,658 Bytes
3beba17 | 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 | """Module-level mocking for app.py import-time side effects."""
import tempfile
from unittest.mock import patch
import pytest
# ---------------------------------------------------------------------------
# Module-level patches — applied BEFORE any test file can `import app`.
#
# app_config.py executes on import:
# 1. snapshot_download(...) → needs HF_TOKEN + network
# 2. os.environ.setdefault(...) → safe, no mock needed
# app.py executes on import:
# 1. base64-encode caliby_transparent.png → file exists in repo, no mock
# 2. @spaces.GPU decorator → no-op when SPACES_ZERO_GPU unset
# ---------------------------------------------------------------------------
_FAKE_WEIGHTS_DIR = tempfile.mkdtemp(prefix="caliby_test_weights_")
patch("huggingface_hub.snapshot_download", return_value=_FAKE_WEIGHTS_DIR).start()
# ---------------------------------------------------------------------------
# Shared fixtures
# ---------------------------------------------------------------------------
@pytest.fixture
def sample_outputs():
"""Mock outputs dict matching caliby's CalibyModel.sample() return format."""
return {
"example_id": ["1YCR", "1YCR"],
"out_pdb": ["/tmp/out/1YCR_sample0.cif", "/tmp/out/1YCR_sample1.cif"],
"U": [-142.38, -139.92],
"input_seq": ["NATIVE_SEQ", "NATIVE_SEQ"],
"seq": ["MTEEQWAQ", "VSEQQWAQ"],
}
@pytest.fixture
def sample_outputs_with_out_pdbs(sample_outputs):
"""Outputs dict with the 'out_pdbs' key that app.py's _format_outputs actually reads."""
return {**sample_outputs, "out_pdbs": sample_outputs["out_pdb"]}
|