Spaces:
Running
Running
feat(linux_appimage): real x86_64 AppImage via pinned Neutralinojs + appimagetool (Hosted Wrapper)
7f84efa Download backend/tests/test_provider.py from 2Btainment/spaceforge: direct link, hf CLI and curl.
- Browser
- Download file 3.77 kB
-
https://huggingface.co/spaces/2Btainment/spaceforge/resolve/main/backend/tests/test_provider.py
- Command line
-
hf download hf://spaces/2Btainment/spaceforge/backend/tests/test_provider.py
-
curl -L -o test_provider.py https://huggingface.co/spaces/2Btainment/spaceforge/resolve/main/backend/tests/test_provider.py
3.77 kB
| import pytest | |
| from backend.app.providers.huggingface import ( | |
| SpaceProviderError, | |
| classify_compatibility, | |
| parse_space_url, | |
| ) | |
| def test_invalid_url_empty(): | |
| with pytest.raises(SpaceProviderError) as ei: | |
| parse_space_url("") | |
| assert ei.value.code == "invalid_url" | |
| def test_invalid_url_external(): | |
| with pytest.raises(SpaceProviderError) as ei: | |
| parse_space_url("https://example.com/spaces/foo/bar") | |
| assert ei.value.code == "invalid_url" | |
| def test_parse_full_url(): | |
| assert parse_space_url("https://huggingface.co/spaces/gradio/hello_world") == ( | |
| "gradio", | |
| "hello_world", | |
| ) | |
| def test_parse_repo_id(): | |
| assert parse_space_url("gradio/hello_world") == ("gradio", "hello_world") | |
| def test_classify_gpu_and_unknown(): | |
| info = { | |
| "sdk": "unknown", | |
| "needs_gpu": True, | |
| "private": False, | |
| "repo_id": "x/y", | |
| } | |
| c = classify_compatibility(info) | |
| assert any("GPU" in w for w in c["warnings"]) | |
| assert c["targets"][0]["id"] == "html_widget" | |
| stubs = [t for t in c["targets"] if t.get("stub")] | |
| assert [t["id"] for t in stubs] == ["windows_portable"] # AppImage/PKGBUILD/MCP are real now | |
| assert all(not t["available"] for t in stubs) | |
| android = next(t for t in c["targets"] if t["id"] == "android") | |
| assert android["available"] is True | |
| assert android["stub"] is False | |
| assert android["mode"] == "hosted_wrapper" | |
| assert android["compat"]["project"] == "ok" | |
| assert android["compat"]["apk"] in {"ok", "warn"} | |
| assert android["compat"]["gpu_local"] == "no" # needs_gpu True in this test | |
| def test_classify_static_local_full(): | |
| c = classify_compatibility({"sdk": "static", "needs_gpu": False, "private": False}) | |
| assert c["local_offline_full"] is True | |
| def test_classify_gradio_not_local_full(): | |
| c = classify_compatibility({"sdk": "gradio", "needs_gpu": False, "private": False}) | |
| assert c["local_offline_full"] is False | |
| def test_normalize_hardware_dict(): | |
| """HF returns runtime.hardware as an object — API must expose a string.""" | |
| from backend.app.providers import huggingface as hf | |
| assert isinstance( | |
| # exercise the same logic via a tiny inline helper mirror | |
| ( | |
| lambda hw_raw: ( | |
| (hw_raw.get("current") or hw_raw.get("requested") or "unknown") | |
| if isinstance(hw_raw, dict) | |
| else (str(hw_raw) if hw_raw else "unknown") | |
| ) | |
| )({"current": "cpu-basic", "requested": "cpu-basic"}), | |
| str, | |
| ) | |
| # Also ensure needs_gpu scan works on stringified values | |
| info = { | |
| "sdk": "gradio", | |
| "needs_gpu": False, | |
| "private": False, | |
| "hardware": "cpu-basic", | |
| } | |
| c = classify_compatibility(info) | |
| assert c["hybrid_ok"] is True | |
| def test_android_compat_no_gpu(): | |
| c = classify_compatibility({"sdk": "gradio", "needs_gpu": False, "private": False}) | |
| android = next(t for t in c["targets"] if t["id"] == "android") | |
| assert android["available"] is True | |
| assert android["mode"] == "hosted_wrapper" | |
| assert android["compat"]["gpu_local"] == "warn" | |
| assert "Hosted Wrapper" in android["reason"] or "project" in android["reason"].lower() or "APK" in android["reason"] | |
| def test_new_targets_listed(): | |
| c = classify_compatibility({"sdk": "gradio", "needs_gpu": False, "private": False}) | |
| ids = [t["id"] for t in c["targets"]] | |
| for tid in ("linux_appimage", "arch_pkgbuild", "mcp"): | |
| assert tid in ids | |
| t = next(x for x in c["targets"] if x["id"] == tid) | |
| assert t["stub"] is False and t["mode"] == "hosted_wrapper" | |
| # new targets are listed above the remaining disabled stub | |
| assert ids.index("mcp") < ids.index("windows_portable") | |