feat(yandexweather): add yandexweather api
This commit is contained in:
+15
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user