Spaces:
Running on Zero
Running on Zero
| """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 | |
| # --------------------------------------------------------------------------- | |
| 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"], | |
| } | |
| 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"]} | |