Spaces:
Sleeping
Sleeping
Download tests/test_app.py from Jplayz/peerpixel-runner: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/Jplayz/peerpixel-runner/resolve/main/tests/test_app.py
- Command line
-
hf download hf://spaces/Jplayz/peerpixel-runner/tests/test_app.py
-
curl -L -o test_app.py https://huggingface.co/spaces/Jplayz/peerpixel-runner/resolve/main/tests/test_app.py
1.69 kB
| import app | |
| class FakeClient: | |
| def __init__(self): | |
| self.state = "disconnected" | |
| self.device_id = "dev" | |
| self.claims = 0 | |
| self.uploaded = False | |
| def connect(self, key): self.state = "waiting" | |
| def claim(self): | |
| self.claims += 1 | |
| if self.claims == 1: | |
| self.state = "reserved" | |
| return {"id": "j", "assignmentToken": "a"} | |
| return None | |
| def source(self): return None | |
| def upload(self, result): self.uploaded = True; self.state = "waiting" | |
| def complete_enhancement(self, prompt): self.enhanced = prompt; self.state = "waiting" | |
| def release(self, reason): self.state = "waiting" | |
| def test_session_allocates_only_after_claim(monkeypatch): | |
| client = FakeClient() | |
| gpu_calls = [] | |
| monkeypatch.setattr(app, "make_client", lambda: client) | |
| monkeypatch.setattr(app, "render_task", lambda task, source: gpu_calls.append(task) or {"images": []}) | |
| events = list(app.run_once("ppw_test")) | |
| assert gpu_calls == [{"id": "j", "assignmentToken": "a"}] | |
| assert client.uploaded | |
| assert events[0][0] == "Waiting for a PeerPixel task" | |
| assert events[-1][1] == 1 | |
| def test_enhancement_task_uses_cpu_enhancer_not_gpu(monkeypatch): | |
| client = FakeClient() | |
| task = {"id": "j", "stage": "enhance", "prompt": "fox", "assignmentToken": "a"} | |
| monkeypatch.setattr(app, "enhance_prompt", lambda prompt: "a detailed fox") | |
| monkeypatch.setattr(app, "render_task", lambda *_: (_ for _ in ()).throw(AssertionError("GPU called"))) | |
| status, completed = app.handle_task(client, task, 0) | |
| assert client.enhanced == "a detailed fox" | |
| assert completed == 0 | |
| assert "Enhanced" in status | |