fix: respect ModelScope model page limit
This commit is contained in:
41
tests/test_modelscope_discovery.py
Normal file
41
tests/test_modelscope_discovery.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user