Skip to content

Commit d955cd4

Browse files
committed
Added runs sorting test
1 parent 27a5131 commit d955cd4

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

simvue/api/objects/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def check_column(cls, column: str) -> str:
4747
and column != "name"
4848
and not column.startswith("metrics")
4949
and not column.startswith("metadata.")
50+
and column not in ("created", "started", "endtime", "modified")
5051
):
51-
raise ValueError(f"Invalid sort column for runs '{column}")
52+
raise ValueError(f"Invalid sort column for runs '{column}'")
5253

5354
return column
5455

simvue/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def get_runs(
182182
count_limit: pydantic.PositiveInt | None = 100,
183183
start_index: pydantic.NonNegativeInt = 0,
184184
show_shared: bool = False,
185+
sort_by_columns: list[tuple[str, bool]] | None = None,
185186
) -> DataFrame | typing.Generator[tuple[str, Run], None, None] | None:
186187
"""Retrieve all runs matching filters.
187188
@@ -210,6 +211,10 @@ def get_runs(
210211
the index from which to count entries. Default is 0.
211212
show_shared : bool, optional
212213
whether to include runs shared with the current user. Default is False.
214+
sort_by_columns : list[tuple[str, bool]], optional
215+
sort by columns in the order given,
216+
list of tuples in the form (column_name: str, sort_descending: bool),
217+
default is None.
213218
214219
Returns
215220
-------
@@ -236,6 +241,9 @@ def get_runs(
236241
return_alerts=alerts,
237242
return_system=system,
238243
return_metadata=metadata,
244+
sorting=[dict(zip(("column", "descending"), a)) for a in sort_by_columns]
245+
if sort_by_columns
246+
else None,
239247
)
240248

241249
if output_format == "objects":

tests/functional/test_client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,19 @@ def test_get_artifacts_as_files(
200200

201201
@pytest.mark.dependency
202202
@pytest.mark.client
203-
@pytest.mark.parametrize("output_format", ("dict", "dataframe", "objects"))
204-
def test_get_runs(create_test_run: tuple[sv_run.Run, dict], output_format: str) -> None:
203+
@pytest.mark.parametrize(
204+
"output_format,sorting",
205+
[
206+
("dict", None),
207+
("dataframe", [("created", True), ("started", True)]),
208+
("objects", [("metadata.test_identifier", True)]),
209+
],
210+
ids=("dict-unsorted", "dataframe-datesorted", "objects-metasorted")
211+
)
212+
def test_get_runs(create_test_run: tuple[sv_run.Run, dict], output_format: str, sorting: list[tuple[str, bool]] | None) -> None:
205213
client = svc.Client()
206214

207-
_result = client.get_runs(filters=None, output_format=output_format, count_limit=10)
215+
_result = client.get_runs(filters=None, output_format=output_format, count_limit=10, sort_by_columns=sorting)
208216

209217
if output_format == "dataframe":
210218
assert not _result.empty

0 commit comments

Comments
 (0)