Skip to content

Commit 5ce6147

Browse files
authored
Merge pull request #365 from simvue-io/hotfix/add-category-to-artifacts-as-files
Added missing 'category' option to `get_artifacts_as_files`
2 parents 1f634fc + 27cdec9 commit 5ce6147

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

simvue/client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,12 @@ def list_artifacts(self, run_id: str) -> list[dict[str, typing.Any]]:
547547
)
548548
return json_response
549549

550-
def _retrieve_artifact_from_server(self, run_id: str, name: str):
551-
params: dict[str, str] = {"name": name}
550+
def _retrieve_artifact_from_server(
551+
self,
552+
run_id: str,
553+
name: str,
554+
) -> typing.Union[dict, list]:
555+
params: dict[str, str | None] = {"name": name}
552556

553557
response = requests.get(
554558
f"{self._url}/api/runs/{run_id}/artifacts",
@@ -707,6 +711,7 @@ def _assemble_artifact_downloads(
707711
def get_artifacts_as_files(
708712
self,
709713
run_id: str,
714+
category: typing.Optional[typing.Literal["input", "output", "code"]] = None,
710715
path: typing.Optional[str] = None,
711716
startswith: typing.Optional[str] = None,
712717
contains: typing.Optional[str] = None,
@@ -733,9 +738,12 @@ def get_artifacts_as_files(
733738
RuntimeError
734739
if there was a failure retrieving artifacts from the server
735740
"""
741+
params: dict[str, typing.Optional[str]] = {"category": category}
736742

737743
response: requests.Response = requests.get(
738-
f"{self._url}/api/runs/{run_id}/artifacts", headers=self._headers
744+
f"{self._url}/api/runs/{run_id}/artifacts",
745+
headers=self._headers,
746+
params=params,
739747
)
740748

741749
self._get_json_from_response(

tests/refactor/test_client.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,23 @@ def test_get_artifact_as_file(
107107

108108
@pytest.mark.dependency
109109
@pytest.mark.client
110-
def test_get_artifacts_as_files(create_test_run: tuple[sv_run.Run, dict]) -> None:
110+
@pytest.mark.parametrize("category", (None, "code", "input", "output"))
111+
def test_get_artifacts_as_files(
112+
create_test_run: tuple[sv_run.Run, dict],
113+
category: typing.Literal["code", "input", "output"],
114+
) -> None:
111115
with tempfile.TemporaryDirectory() as tempd:
112116
client = svc.Client()
113-
client.get_artifacts_as_files(create_test_run[1]["run_id"], path=tempd)
117+
client.get_artifacts_as_files(
118+
create_test_run[1]["run_id"], category=category, path=tempd
119+
)
114120
files = [os.path.basename(i) for i in glob.glob(os.path.join(tempd, "*"))]
115-
assert create_test_run[1]["file_1"] in files
116-
assert create_test_run[1]["file_2"] in files
121+
if not category or category == "input":
122+
assert create_test_run[1]["file_1"] in files
123+
if not category or category == "output":
124+
assert create_test_run[1]["file_2"] in files
125+
if not category or category == "code":
126+
assert create_test_run[1]["file_3"] in files
117127

118128

119129
@pytest.mark.dependency
@@ -140,7 +150,7 @@ def test_get_folder(create_test_run: tuple[sv_run.Run, dict]) -> None:
140150

141151

142152
@pytest.mark.dependency
143-
@pytest.mark.client
153+
@pytest.mark.client
144154
def test_get_metrics_names(create_test_run: tuple[sv_run.Run, dict]) -> None:
145155
client = svc.Client()
146156
time.sleep(1)

0 commit comments

Comments
 (0)