Spaces:
Sleeping
Sleeping
Download tests/conftest.py from mjpsm/activity-progression-api: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/spaces/mjpsm/activity-progression-api/resolve/main/tests/conftest.py
- Command line
-
hf download hf://spaces/mjpsm/activity-progression-api/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/mjpsm/activity-progression-api/resolve/main/tests/conftest.py
1.86 kB
| import json | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| from app import main | |
| from app.model_runtime import Completion | |
| VALID_REQUEST = { | |
| "version": "v1", | |
| "knowledge_submission": "I completed the task.", | |
| "wisdom": { | |
| "content": "I learned something before.", | |
| "chapterTitle": "Past learning", | |
| "BookTypeName": "Testimony", | |
| "BookType": "Personal Record", | |
| }, | |
| "village_goal": "Learn the skill", | |
| "previous_activity_title": "Practice the skill", | |
| } | |
| VALID_OUTPUT = { | |
| "progression": { | |
| "knowledge_state": "COMPLETED", | |
| "demonstrated_state": ["Completed the task"], | |
| "next_gap": "Apply it in a new setting", | |
| "activity_plan": { | |
| "action": "Apply", | |
| "target": "A new setting", | |
| "avoid_repeating": ["Completing the same task"], | |
| }, | |
| } | |
| } | |
| class FakeRuntime: | |
| """Stands in for ModelRuntime so tests never load the GGUF.""" | |
| def __init__(self) -> None: | |
| self.is_ready = True | |
| self.output = json.dumps(VALID_OUTPUT) | |
| self.prompts: list[str] = [] | |
| async def start(self) -> None: | |
| pass | |
| async def stop(self) -> None: | |
| pass | |
| def ready(self) -> bool: | |
| return self.is_ready | |
| async def complete(self, prompt: str) -> Completion: | |
| self.prompts.append(prompt) | |
| return Completion( | |
| text=self.output, | |
| input_tokens=len(prompt.split()), | |
| output_tokens=len(self.output.split()), | |
| ) | |
| def fake_runtime(monkeypatch): | |
| fake = FakeRuntime() | |
| monkeypatch.setattr(main, "runtime", fake) | |
| return fake | |
| def client(fake_runtime): | |
| with TestClient(main.app) as test_client: | |
| yield test_client | |
| def valid_request(): | |
| return json.loads(json.dumps(VALID_REQUEST)) | |