Spaces:
Sleeping
Sleeping
Download tests/test_runner.py from Jplayz/peerpixel-runner: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/Jplayz/peerpixel-runner/resolve/main/tests/test_runner.py
- Command line
-
hf download hf://spaces/Jplayz/peerpixel-runner/tests/test_runner.py
-
curl -L -o test_runner.py https://huggingface.co/spaces/Jplayz/peerpixel-runner/resolve/main/tests/test_runner.py
1.62 kB
| import io | |
| from PIL import Image | |
| import runner | |
| class FakePipeline: | |
| def __init__(self): | |
| self.calls = [] | |
| def __call__(self, **kwargs): | |
| self.calls.append(kwargs) | |
| seed = kwargs["generator"].initial_seed() | |
| return type("Output", (), {"images": [Image.new("RGB", (kwargs["width"], kwargs["height"]), (seed % 255, 40, 90))]})() | |
| class SafeClassifier: | |
| def __call__(self, image): | |
| return [{"label": "normal", "score": 0.999}, {"label": "nsfw", "score": 0.001}] | |
| def test_grid_uses_coordinator_controls_and_distinct_seeds(monkeypatch): | |
| pipe = FakePipeline() | |
| monkeypatch.setattr(runner, "PIPELINE", pipe) | |
| monkeypatch.setattr(runner, "SAFETY", SafeClassifier()) | |
| task = {"id": "j", "prompt": "rat", "operation": "grid", "seed": 10, | |
| "outputCount": 4, "width": 512, "height": 512, "steps": 16, | |
| "assignmentToken": "a"} | |
| result = runner.render_task(task, None) | |
| assert len(result["images"]) == 4 | |
| assert len({call["generator"].initial_seed() for call in pipe.calls}) == 4 | |
| assert all(call["num_inference_steps"] == 16 for call in pipe.calls) | |
| grid = Image.open(io.BytesIO(result["grid"]["bytes"])) | |
| assert grid.size == (1024, 1024) | |
| assert result["grid"]["localSafety"]["unsafe"] is False | |
| def test_gpu_duration_is_bounded(): | |
| assert runner.gpu_duration({"operation": "grid", "outputCount": 4, "steps": 16}) > runner.gpu_duration({"outputCount": 1, "steps": 16}) | |
| assert runner.gpu_duration({"outputCount": 1, "steps": 16}, b"source") >= 60 | |
| assert runner.gpu_duration({"outputCount": 99, "steps": 999}) <= 300 | |