Skip to content

Commit 6b5ccf3

Browse files
GSK-2902 GSK-2418 Add a method to execute test suite and upload result to Hub programmatically + result cleanup (Giskard-AI#1818)
* GSK-2418 Add a method to execute test suite and upload result to Hub programmatically * GSK-2418 Date format identical to Hub one * GSK-2418 Updated DTO * GSK-2418 Handle debugging * GSK-2418 Handle debugging * GSK-2418 Handle exception in test suite execution * GSK-2418 Made metric optional and added test for download and upload * GSK-2418 Updated test * GSK-2418 Added link to the ref doc * GSK-2418 Added todo * GSK-2902 Cleanup TestResult information that are sent to the Hub * GSK-2902 Updated communication tests * Fix suite_id in _test_result_to_dto * GSK-2418 Fixed uuid serialization * GSK-2418 Added test * GSK-2418 Fixed issue when sending wrong id * GSK-2418 Fixed issue when sending wrong id * GSK-2418 Updated save suite execution method to send configuration * GSK-2418 Fixed issue when test has error * GSK-2418 Fixed tests * Fix dto format --------- Co-authored-by: Hartorn <bazire@giskard.ai> Co-authored-by: Hartorn <hartorn.github@gmail.com>
1 parent 543fe15 commit 6b5ccf3

File tree

13 files changed

+331
-344
lines changed

13 files changed

+331
-344
lines changed

‎docs/reference/suite/index.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ Test suite
2121

2222
.. autoclass:: giskard.core.suite.TestSuiteResult
2323

24+
.. automethod:: upload
25+
2426
.. autoclass:: giskard.core.test_result.TestResult

‎giskard/client/dtos.py‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from typing import Any, Dict, List, Optional
22

3+
from enum import Enum
4+
35
from pydantic import Field
46

7+
from giskard.core.core import TestResultStatusEnum
58
from giskard.core.validation import ConfiguredBaseModel
9+
from giskard.utils.artifacts import serialize_parameter
610

711

812
class TestInputDTO(ConfiguredBaseModel):
@@ -13,9 +17,16 @@ class TestInputDTO(ConfiguredBaseModel):
1317
is_alias: bool = False
1418
is_default_value: bool = False
1519

20+
@classmethod
21+
def from_inputs_dict(cls, inputs: Dict[str, Any]) -> List["TestInputDTO"]:
22+
return [
23+
cls(name=name, value=str(serialize_parameter(value)), type=type(value).__qualname__)
24+
for name, value in inputs.items()
25+
]
26+
1627

1728
class SuiteTestDTO(ConfiguredBaseModel):
18-
id: int
29+
id: Optional[int]
1930
testUuid: str
2031
functionInputs: Dict[str, TestInputDTO]
2132
displayName: Optional[str] = None
@@ -28,6 +39,56 @@ class TestSuiteDTO(ConfiguredBaseModel):
2839
function_inputs: List[TestInputDTO]
2940

3041

42+
class TestSuiteExecutionResult(str, Enum):
43+
IN_PROGRESS = "IN_PROGRESS"
44+
CANCELLED = "CANCELLED"
45+
PASSED = "PASSED"
46+
FAILED = "FAILED"
47+
ERROR = "ERROR"
48+
49+
50+
class MLWorkerWSTestMessageType(str, Enum):
51+
ERROR = "ERROR"
52+
INFO = "INFO"
53+
54+
55+
class TestResultMessageDTO(ConfiguredBaseModel):
56+
type: MLWorkerWSTestMessageType
57+
text: str
58+
59+
60+
class SaveSuiteTestExecutionDetailsDTO(ConfiguredBaseModel):
61+
inputs: Dict[str, List[str]]
62+
outputs: List[str]
63+
results: List[TestResultStatusEnum]
64+
metadata: Dict[str, List[str]]
65+
66+
67+
class SaveSuiteTestExecutionDTO(ConfiguredBaseModel):
68+
suiteTest: SuiteTestDTO
69+
testUuid: str
70+
displayName: str
71+
inputs: Dict[str, str]
72+
arguments: Dict[str, TestInputDTO]
73+
messages: List[TestResultMessageDTO]
74+
status: TestResultStatusEnum
75+
metric: Optional[float]
76+
metricName: str
77+
failedIndexes: Dict[str, List[int]]
78+
details: Optional[SaveSuiteTestExecutionDetailsDTO]
79+
80+
81+
class SaveSuiteExecutionDTO(ConfiguredBaseModel):
82+
suiteId: Optional[int]
83+
label: str
84+
inputs: List[TestInputDTO]
85+
result: TestSuiteExecutionResult
86+
message: str
87+
results: List[SaveSuiteTestExecutionDTO]
88+
executionDate: str
89+
completionDate: str
90+
91+
3192
class ServerInfo(ConfiguredBaseModel):
3293
instanceId: Optional[str] = None
3394
serverVersion: Optional[str] = None
@@ -51,7 +112,6 @@ class SuiteInfo(ConfiguredBaseModel):
51112
# The following inputs are never used and are here only for
52113
# coherence with backend
53114
id: int
54-
functionInputs: List
55115
projectKey: str
56116

57117

‎giskard/client/giskard_client.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
from requests_toolbelt import sessions
1616

1717
import giskard
18-
from giskard.client.dtos import DatasetMetaInfo, ModelMetaInfo, ServerInfo, SuiteInfo, TestSuiteDTO
18+
from giskard.client.dtos import (
19+
DatasetMetaInfo,
20+
ModelMetaInfo,
21+
SaveSuiteExecutionDTO,
22+
ServerInfo,
23+
SuiteInfo,
24+
TestSuiteDTO,
25+
)
1926
from giskard.client.io_utils import GiskardJSONSerializer
2027
from giskard.client.project import Project
2128
from giskard.client.python_utils import warning
@@ -418,3 +425,6 @@ def save_test_suite(self, dto: TestSuiteDTO):
418425

419426
def update_test_suite(self, suite_id: int, dto: TestSuiteDTO):
420427
return self._session.put(f"testing/project/{dto.project_key}/suite/{suite_id}", json=dto.dict()).json()
428+
429+
def save_test_suite_execution_result(self, project_key: str, dto: SaveSuiteExecutionDTO):
430+
return self._session.post(f"testing/project/{project_key}/executions", json=dto.dict()).json()

‎giskard/core/core.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,9 @@ class ComparisonClauseDTO:
546546
comparisonType: ComparisonType
547547
columnDtype: str
548548
value: Optional[str]
549+
550+
551+
class TestResultStatusEnum(str, Enum):
552+
ERROR = "ERROR"
553+
PASSED = "PASSED"
554+
FAILED = "FAILED"

0 commit comments

Comments
 (0)