eat(yandexweather): add yandexweather api

This commit is contained in:
2026-08-24 21:37:55 +03:00
parent a92b63b855
commit 23d38b8d6e
32 changed files with 505 additions and 73 deletions
+15 -2
View File
@@ -1,6 +1,8 @@
from pathlib import Path
from typing import TypeVar
from gallery.sketch.source import ApiSource
from gallery.sketch.api import Api, S
from gallery.sketch.source import DEFAULT_REQUEST_MODE, ApiSource, RequestMode
class MockSource(ApiSource):
@@ -10,8 +12,19 @@ class MockSource(ApiSource):
self._path = path
self._mapping = mapping
async def request(self, endpoint: str) -> str:
async def request(self, endpoint: str, /, mode: RequestMode = DEFAULT_REQUEST_MODE) -> str:
for pattern, filename in self._mapping.items():
if pattern in endpoint:
return (self._path / filename).read_text()
raise ValueError(endpoint)
API = Api[S]
A = TypeVar("A", bound=API)
def create_mock_api(api_type: type[A], mock_source: MockSource) -> A:
api = api_type()
# pylint: disable=protected-access
api._build_source = lambda: mock_source
return api