Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python tests model classes #19

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f50fa34
Created model classes for SDK python tests
rquidute Nov 6, 2023
6a77265
Added parser implementation to python test
rquidute Nov 8, 2023
d54d375
Changed init from sdk_tests
rquidute Nov 8, 2023
790c528
Merge branch 'main' into feature/74_phase3-add_python_tests_model_cla…
rquidute Nov 8, 2023
1985230
Minor changes
rquidute Nov 8, 2023
91fdbf9
Disable support to list python test cases
rquidute Nov 8, 2023
df0e129
Reverted minor changes
rquidute Nov 8, 2023
fe24421
Added Unit tests
rquidute Nov 8, 2023
e8c6ef7
Minor change
rquidute Nov 8, 2023
e6871e0
Merge with main
rquidute Nov 8, 2023
b682e0d
Fix merge conflict
rquidute Nov 8, 2023
1b8e180
Fix CI issues
rquidute Nov 8, 2023
6b1bc86
Fix mypy and flake violations
rquidute Nov 8, 2023
ba061c2
Fix mypy and flake violations
rquidute Nov 9, 2023
817f72a
Fix mypy and flake violations
rquidute Nov 9, 2023
beb46b3
Fixed unit tests
rquidute Nov 9, 2023
8da8227
Add iniial code for Python Test runner
rquidute Nov 10, 2023
879b7de
Fix code violation and add code to chip_tool for python runner
rquidute Nov 10, 2023
5872265
Fix code violation
rquidute Nov 10, 2023
8a89c18
Changes after code review
rquidute Nov 13, 2023
118cc89
Removed unsued code
rquidute Nov 13, 2023
b914e19
Few tweeks based on observation running end to end.
gladystonfranca Nov 13, 2023
939bf15
Merge branch 'main' into feature/74_phase3-add_python_tests_model_cla…
rquidute Nov 14, 2023
ba9c21e
Created top level classes for test models
rquidute Nov 14, 2023
8f5f77c
Fix code violation
rquidute Nov 14, 2023
e0dc0da
Code changes after review
rquidute Nov 16, 2023
bfa0725
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
rquidute Nov 17, 2023
352f80b
Code changes after code review
rquidute Nov 22, 2023
7f34cbf
Putting back .version_information
rquidute Nov 22, 2023
1502f2e
Putting back .version_information
rquidute Nov 22, 2023
10ac46b
Fixed mypy violations
rquidute Nov 22, 2023
17ec11a
Removed unused imports
rquidute Nov 22, 2023
77cf574
adding rpc client code and mounting new volumes on sdk container
gladystonfranca Nov 27, 2023
63e39e2
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
rquidute Nov 27, 2023
2135ffd
Fixing sdk rpc file path
gladystonfranca Nov 27, 2023
cee194f
Code changed after code review
rquidute Nov 29, 2023
01d9d57
Update app/tests/python_tests/test_python_test_suite.py
rquidute Nov 29, 2023
030da70
Code changes after review
rquidute Nov 29, 2023
de0c0c4
Remove whitespace from a blank line
rquidute Nov 29, 2023
e78a09d
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
rquidute Nov 30, 2023
0a769fb
Add support for PICS in python tests
ccruzagralopes Nov 30, 2023
c7ad322
Update some unit tests
ccruzagralopes Nov 30, 2023
edcf2cd
Merge pull request #1 from ccruzagralopes/add_support_for_PICS_in_pyt…
rquidute Nov 30, 2023
5904c9d
Get python test parameters from project config
rquidute Dec 1, 2023
3198ecd
Fix Unit tests
rquidute Dec 1, 2023
f35d043
Updated unit tests
rquidute Dec 4, 2023
9bb424f
Removed unused test files
rquidute Dec 4, 2023
e5dfd63
Code updated due to code review
rquidute Dec 5, 2023
1e1ae77
Make PICS optional for python tests
rquidute Dec 6, 2023
890cf2e
Added SDKPythonTestResult class in order to handle the python test re…
rquidute Dec 6, 2023
8a116d1
Create SDKPythonTestResultBase and make subclass for each result
rquidute Dec 6, 2023
eceb15b
Make default attribute type set in SDKPythonTestResultBase subclasses
rquidute Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,91 @@
# 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, Literal, 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 SDKPythonTestResultBase(BaseModel):
type: SDKPythonTestResultEnum
rquidute marked this conversation as resolved.
Show resolved Hide resolved

def params_dict(self) -> dict:
return self.dict(exclude={"type"})


class SDKPythonTestResultStart(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.START]
ccruzagralopes marked this conversation as resolved.
Show resolved Hide resolved
count: int


class SDKPythonTestResultStop(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STOP]
duration: int


class SDKPythonTestResultTestStart(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.TEST_START]
filename: Optional[str]
name: Optional[str]
count: Optional[int]


class SDKPythonTestResultTestStop(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.TEST_STOP]
duration: Optional[str]
exception: Any


class SDKPythonTestResultStepSkipped(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STEP_SKIPPED]
name: Optional[str]
expression: Optional[str]


class SDKPythonTestResultStepStart(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STEP_START]
name: Optional[str]


class SDKPythonTestResultStepSuccess(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STEP_SUCCESS]
logger: Any
logs: Any
duration: int
request: Any


class SDKPythonTestResultStepFailure(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STEP_FAILURE]
logger: Any
logs: Any
duration: int
request: Any
received: Any


class SDKPythonTestResultStepUnknown(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STEP_UNKNOWN]


class SDKPythonTestResultStepManual(SDKPythonTestResultBase):
type: Literal[SDKPythonTestResultEnum.STEP_MANUAL]


class SDKPythonTestRunnerHooks(TestRunnerHooks):
Expand All @@ -38,58 +119,85 @@ def is_finished(self) -> bool:
return SDKPythonTestRunnerHooks.finished

def start(self, count: int) -> None:
self.results.put({"start": {"count": count}})
self.results.put(
SDKPythonTestResultStart(type=SDKPythonTestResultEnum.START, count=count)
ccruzagralopes marked this conversation as resolved.
Show resolved Hide resolved
)

def stop(self, duration: int) -> None:
self.results.put({"stop": {"duration": duration}})
self.results.put(
SDKPythonTestResultStop(
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}}
SDKPythonTestResultTestStart(
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(
SDKPythonTestResultTestStop(
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}})
def SDKPythonTestResultStepSkipped(self, name: str, expression: str) -> None:
self.results.put(
SDKPythonTestResultStepSkipped(
type=SDKPythonTestResultEnum.STEP_SKIPPED, expression=expression
)
)

def step_start(self, name: str) -> None:
self.results.put({"step_start": {"name": name}})
self.results.put(
SDKPythonTestResultStepStart(
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,
}
}
SDKPythonTestResultStepSuccess(
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,
}
}
SDKPythonTestResultStepFailure(
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(
SDKPythonTestResultStepUnknown(type=SDKPythonTestResultEnum.STEP_UNKNOWN)
)

def step_manual(self) -> None:
self.results.put({"step_manual": {}})
self.results.put(
SDKPythonTestResultStepManual(type=SDKPythonTestResultEnum.STEP_MANUAL)
)

def step_start_list(self) -> None:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
from app.test_engine.models import TestCase, TestStep

from .python_test_models import PythonTest
from .python_testing_hooks_proxy import SDKPythonTestRunnerHooks
from .python_testing_hooks_proxy import (
SDKPythonTestResultBase,
SDKPythonTestRunnerHooks,
)

# Custom type variable used to annotate the factory method in PythonTestCase.
T = TypeVar("T", bound="PythonTestCase")
Expand Down Expand Up @@ -83,6 +86,7 @@ def step_failure(
self, logger: Any, logs: str, duration: int, request: Any, received: Any
) -> None:
# TODO Handle Logs properly
self.mark_step_failure("Python test step failure")
self.next_step()

def step_unknown(self) -> None:
Expand Down Expand Up @@ -178,14 +182,13 @@ async def execute(self) -> None:
finally:
pass

def __handle_update(self, update: dict) -> None:
for func_name, kwargs in update.items():
self.__call_function_from_name(self, func_name, kwargs)
def __handle_update(self, update: SDKPythonTestResultBase) -> None:
self.__call_function_from_name(update.type.value, update.params_dict())

def __call_function_from_name(self, obj, func_name, kwargs) -> None: # type: ignore
func = getattr(obj, func_name, None)
def __call_function_from_name(self, func_name: str, kwargs: Any) -> None:
func = getattr(self, func_name, None)
if not func:
raise AttributeError(f"{func_name} is not a method of {obj}")
raise AttributeError(f"{func_name} is not a method of {self}")
if not callable(func):
raise TypeError(f"{func_name} is not callable")
func(**kwargs)
Expand Down
Loading