Download tests/conftest.py from SmaugC137/toaster: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/SmaugC137/toaster/resolve/main/tests/conftest.py
- Command line
-
hf download hf://spaces/SmaugC137/toaster/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/SmaugC137/toaster/resolve/main/tests/conftest.py
1.45 kB
| """Shared fixtures: synthetic clouds and a small schema. No GUI involved.""" | |
| from __future__ import annotations | |
| import numpy as np | |
| import pytest | |
| from toaster.core import LabelClass, LabelSchema, PointCloud | |
| def isolate_toaster_config(tmp_path_factory, monkeypatch): | |
| """Point ``$HOME`` at a throwaway dir so no test reads or writes the user's | |
| real ``~/.config/toaster/session.json``. ``AnnotationService`` persists the | |
| session (recent files, session channel) there, so without this a stale local | |
| session would leak into tests (and tests would clobber the developer's own). | |
| """ | |
| home = tmp_path_factory.mktemp("home") | |
| monkeypatch.setenv("HOME", str(home)) | |
| monkeypatch.setattr("pathlib.Path.home", lambda: home) | |
| def schema() -> LabelSchema: | |
| return LabelSchema( | |
| classes=[ | |
| LabelClass(0, "unlabeled", (0, 0, 0)), | |
| LabelClass(1, "a", (255, 0, 0)), | |
| LabelClass(2, "b", (0, 255, 0)), | |
| ], | |
| unlabeled_id=0, | |
| ) | |
| def two_clusters() -> PointCloud: | |
| """Two tight, well-separated blobs of 50 points each (no noise).""" | |
| rng = np.random.default_rng(0) | |
| a = rng.normal((0.0, 0.0, 0.0), 0.08, (50, 3)) | |
| b = rng.normal((10.0, 0.0, 0.0), 0.08, (50, 3)) | |
| xyz = np.vstack([a, b]).astype(np.float32) | |
| return PointCloud(xyz=xyz, features={"intensity": rng.random(100).astype(np.float32)}) | |