Files
submmit/tests/test_modelscope_discovery.py
2026-08-02 16:03:44 +08:00

42 lines
1.2 KiB
Python

from __future__ import annotations
import sys
import unittest
from pathlib import Path
PACKAGE_DIR = Path(__file__).resolve().parents[1] / "modelhub_submmit_api"
if str(PACKAGE_DIR) in sys.path:
sys.path.remove(str(PACKAGE_DIR))
sys.path.insert(0, str(PACKAGE_DIR))
from hf_discovery import HuggingFaceDiscovery # noqa: E402
class RecordingHttpClient:
def __init__(self) -> None:
self.queries: list[dict] = []
def request_json(self, _method: str, _path: str, *, query: dict) -> dict:
self.queries.append(query)
return {"success": True, "data": {"models": []}}
class ModelScopeDiscoveryTests(unittest.TestCase):
def test_openapi_page_size_never_exceeds_platform_limit(self) -> None:
http_client = RecordingHttpClient()
discovery = HuggingFaceDiscovery(http_client=http_client) # type: ignore[arg-type]
models = discovery.list_recent_models(
pipeline_tags=["text-generation"],
limit=1000,
min_downloads=0,
)
self.assertEqual([], models)
self.assertEqual(50, http_client.queries[0]["page_size"])
if __name__ == "__main__":
unittest.main()