Spaces:
Running
Running
Download tests/test_gridstack_nextjs_caps.py from acecalisto3/SignalMesh: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/spaces/acecalisto3/SignalMesh/resolve/main/tests/test_gridstack_nextjs_caps.py
- Command line
-
hf download hf://spaces/acecalisto3/SignalMesh/tests/test_gridstack_nextjs_caps.py
-
curl -L -o test_gridstack_nextjs_caps.py https://huggingface.co/spaces/acecalisto3/SignalMesh/resolve/main/tests/test_gridstack_nextjs_caps.py
1.95 kB
| from importlib.util import module_from_spec, spec_from_file_location | |
| from pathlib import Path | |
| import tempfile | |
| import unittest | |
| ROOT = Path(__file__).resolve().parents[1] | |
| SPEC = spec_from_file_location("signalmesh_gridstack", ROOT / "signalmesh_gridstack.py") | |
| if SPEC is None or SPEC.loader is None: | |
| raise RuntimeError("could not load signalmesh_gridstack.py") | |
| grid = module_from_spec(SPEC) | |
| SPEC.loader.exec_module(grid) | |
| class GridStackNextJsCapabilityTests(unittest.TestCase): | |
| def test_harvests_app_router_function_and_const_handlers(self): | |
| with tempfile.TemporaryDirectory() as tmp: | |
| root = Path(tmp) | |
| route = root / "app" / "api" / "mesh" / "[...path]" / "route.ts" | |
| route.parent.mkdir(parents=True) | |
| route.write_text( | |
| "export async function GET() { return Response.json({ ok: true }); }\n" | |
| "export const POST = async () => Response.json({ ok: true });\n" | |
| ) | |
| caps = grid._harvest_route_caps(root) | |
| names = {item["name"] for item in caps} | |
| self.assertIn("GET /api/mesh/[...path]", names) | |
| self.assertIn("POST /api/mesh/[...path]", names) | |
| def test_route_groups_do_not_change_public_path_and_reexports_are_found(self): | |
| with tempfile.TemporaryDirectory() as tmp: | |
| root = Path(tmp) | |
| route = root / "src" / "app" / "(admin)" / "api" / "operator" / "[id]" / "route.ts" | |
| route.parent.mkdir(parents=True) | |
| route.write_text( | |
| "const handler = async () => new Response();\n" | |
| "export { handler as PATCH, handler as DELETE };\n" | |
| ) | |
| caps = grid._harvest_route_caps(root) | |
| names = {item["name"] for item in caps} | |
| self.assertIn("DELETE /api/operator/[id]", names) | |
| self.assertIn("PATCH /api/operator/[id]", names) | |
| if __name__ == "__main__": | |
| unittest.main() | |