-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SDKPythonTestResult class in order to handle the python test re…
…sponses
- Loading branch information
Showing
2 changed files
with
93 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,39 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from enum import Enum | ||
from queue import Empty, Queue | ||
from typing import Any, Union | ||
from typing import Any, Optional, Union | ||
|
||
from matter_yamltests.hooks import TestRunnerHooks | ||
from pydantic import BaseModel | ||
|
||
|
||
class SDKPythonTestResultEnum(str, Enum): | ||
START = "start" | ||
STOP = "stop" | ||
TEST_START = "test_start" | ||
TEST_STOP = "test_stop" | ||
STEP_SKIPPED = "step_skipped" | ||
STEP_START = "step_start" | ||
STEP_SUCCESS = "step_success" | ||
STEP_FAILURE = "step_failure" | ||
STEP_UNKNOWN = "step_unknown" | ||
STEP_MANUAL = "step_manual" | ||
|
||
|
||
class SDKPythonTestResult(BaseModel): | ||
type: SDKPythonTestResultEnum | ||
count: Optional[int] | ||
duration: Optional[str] | ||
name: Optional[str] | ||
filename: Optional[str] | ||
exception: Any | ||
expression: Optional[str] | ||
logger: Any | ||
logs: Any | ||
request: Any | ||
received: Any | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mikaelhm
Contributor
|
||
|
||
|
||
class SDKPythonTestRunnerHooks(TestRunnerHooks): | ||
|
@@ -38,58 +67,77 @@ def is_finished(self) -> bool: | |
return SDKPythonTestRunnerHooks.finished | ||
|
||
def start(self, count: int) -> None: | ||
self.results.put({"start": {"count": count}}) | ||
self.results.put( | ||
SDKPythonTestResult(type=SDKPythonTestResultEnum.START, count=count) | ||
) | ||
|
||
def stop(self, duration: int) -> None: | ||
self.results.put({"stop": {"duration": duration}}) | ||
self.results.put( | ||
SDKPythonTestResult(type=SDKPythonTestResultEnum.STOP, duration=duration) | ||
) | ||
SDKPythonTestRunnerHooks.finished = True | ||
|
||
def test_start(self, filename: str, name: str, count: int) -> None: | ||
self.results.put( | ||
{"test_start": {"filename": filename, "name": name, "count": count}} | ||
SDKPythonTestResult( | ||
type=SDKPythonTestResultEnum.TEST_START, | ||
filename=filename, | ||
name=name, | ||
count=count, | ||
) | ||
) | ||
|
||
def test_stop(self, exception: Exception, duration: int) -> None: | ||
self.results.put({"test_stop": {"exception": exception, "duration": duration}}) | ||
self.results.put( | ||
SDKPythonTestResult( | ||
type=SDKPythonTestResultEnum.TEST_STOP, | ||
exception=exception, | ||
duration=duration, | ||
) | ||
) | ||
|
||
def step_skipped(self, name: str, expression: str) -> None: | ||
self.results.put({"step_skipped": {"name": name, "expression": expression}}) | ||
self.results.put( | ||
SDKPythonTestResult( | ||
type=SDKPythonTestResultEnum.STEP_SKIPPED, expression=expression | ||
) | ||
) | ||
|
||
def step_start(self, name: str) -> None: | ||
self.results.put({"step_start": {"name": name}}) | ||
self.results.put( | ||
SDKPythonTestResult(type=SDKPythonTestResultEnum.STEP_START, name=name) | ||
) | ||
|
||
def step_success(self, logger: Any, logs: Any, duration: int, request: Any) -> None: | ||
self.results.put( | ||
{ | ||
"step_success": { | ||
"logger": logger, | ||
"logs": logs, | ||
"duration": duration, | ||
"request": request, | ||
} | ||
} | ||
SDKPythonTestResult( | ||
type=SDKPythonTestResultEnum.STEP_SUCCESS, | ||
logger=logger, | ||
logs=logs, | ||
duration=duration, | ||
request=request, | ||
) | ||
) | ||
|
||
def step_failure( | ||
self, logger: Any, logs: Any, duration: int, request: Any, received: Any | ||
) -> None: | ||
self.results.put( | ||
{ | ||
"step_failure": { | ||
"logger": logger, | ||
"logs": logs, | ||
"duration": duration, | ||
"request": request, | ||
"received": received, | ||
} | ||
} | ||
SDKPythonTestResult( | ||
type=SDKPythonTestResultEnum.STEP_FAILURE, | ||
logger=logger, | ||
logs=logs, | ||
duration=duration, | ||
request=request, | ||
received=received, | ||
) | ||
) | ||
|
||
def step_unknown(self) -> None: | ||
self.results.put({"step_unknown": {}}) | ||
self.results.put(SDKPythonTestResult(type=SDKPythonTestResultEnum.STEP_UNKNOWN)) | ||
|
||
def step_manual(self) -> None: | ||
self.results.put({"step_manual": {}}) | ||
self.results.put(SDKPythonTestResult(type=SDKPythonTestResultEnum.STEP_MANUAL)) | ||
|
||
def step_start_list(self) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think it would be helpful to have a subclass for each type with the specific properties needed, instead of a flat structure with optionals.
Also, don't we have specific types for these: