Skip to content

Commit dca5673

Browse files
[core] feat: FakeApiClient supports reading data from remote storage
1 parent 3508cce commit dca5673

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libs/core/garf_core/api_clients.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import csv
2121
import json
2222
import os
23-
import pathlib
2423
from collections.abc import Sequence
2524
from typing import Any, Union
2625

2726
import pydantic
2827
import requests
28+
import smart_open
2929
from typing_extensions import TypeAlias, override
3030

3131
from garf_core import exceptions, query_editor
@@ -124,7 +124,7 @@ def from_json(cls, file_location: str | os.PathLike[str]) -> FakeApiClient:
124124
GarfApiError: When file with data not found.
125125
"""
126126
try:
127-
with pathlib.Path.open(file_location, 'r', encoding='utf-8') as f:
127+
with smart_open.open(file_location, 'r', encoding='utf-8') as f:
128128
data = json.load(f)
129129
return FakeApiClient(data)
130130
except FileNotFoundError as e:
@@ -144,7 +144,7 @@ def from_csv(cls, file_location: str | os.PathLike[str]) -> FakeApiClient:
144144
GarfApiError: When file with data not found.
145145
"""
146146
try:
147-
with pathlib.Path.open(file_location, 'r', encoding='utf-8') as f:
147+
with smart_open.open(file_location, 'r', encoding='utf-8') as f:
148148
reader = csv.DictReader(f)
149149
data = []
150150
for row in reader:

0 commit comments

Comments
 (0)