Skip to content

Commit

Permalink
Support user input for python tests in TH (#32299)
Browse files Browse the repository at this point in the history
* Add supporting functions

* Update TC-RVCOPSTATE-2.4

* Fix linting errors

* Restyled by isort

* Update src/python_testing/matter_testing_support.py

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
ccruzagralopes and restyled-commits authored Feb 26, 2024
1 parent dbfd4b5 commit 2e35d01
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
11 changes: 11 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional

from .parser import TestStep


Expand Down Expand Up @@ -213,6 +215,15 @@ async def step_manual(self):
"""
pass

def show_prompt(self,
msg: str,
placeholder: Optional[str] = None,
default_value: Optional[str] = None) -> None:
"""
This method is called when the step needs to ask the user to perform some action or provide some value.
"""
pass


class WebSocketRunnerHooks():
def connecting(self, url: str):
Expand Down
20 changes: 12 additions & 8 deletions src/python_testing/TC_RVCOPSTATE_2_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,47 +119,51 @@ async def test_TC_RVCOPSTATE_2_4(self):
self.write_to_app_pipe('{"Name": "Reset"}')

if self.check_pics("RVCOPSTATE.S.M.ST_ERROR"):
self.print_step(2, "Manually put the device in the ERROR operational state")
step_name = "Manually put the device in the ERROR operational state"
self.print_step(2, step_name)
if self.is_ci:
self.write_to_app_pipe('{"Name": "ErrorEvent", "Error": "UnableToStartOrResume"}')
else:
input("Press Enter when done.\n")
self.wait_for_user_input(step_name)

await self.read_operational_state_with_check(3, op_states.kError)

await self.send_go_home_cmd_with_check(4, op_errors.kCommandInvalidInState)

if self.check_pics("RVCOPSTATE.S.M.ST_CHARGING"):
self.print_step(5, "Manually put the device in the CHARGING operational state")
step_name = "Manually put the device in the CHARGING operational state"
self.print_step(5, step_name)
if self.is_ci:
self.write_to_app_pipe('{"Name": "Reset"}')
self.write_to_app_pipe('{"Name": "Docked"}')
self.write_to_app_pipe('{"Name": "Charging"}')
else:
input("Press Enter when done.\n")
self.wait_for_user_input(step_name)

await self.read_operational_state_with_check(6, rvc_op_states.kCharging)

await self.send_go_home_cmd_with_check(7, op_errors.kCommandInvalidInState)

if self.check_pics("RVCOPSTATE.S.M.ST_DOCKED"):
self.print_step(8, "Manually put the device in the DOCKED operational state")
step_name = "Manually put the device in the DOCKED operational state"
self.print_step(8, step_name)
if self.is_ci:
self.write_to_app_pipe('{"Name": "Charged"}')
else:
input("Press Enter when done.\n")
self.wait_for_user_input(step_name)

await self.read_operational_state_with_check(9, rvc_op_states.kDocked)

await self.send_go_home_cmd_with_check(10, op_errors.kCommandInvalidInState)

if self.check_pics("PICS_M_ST_SEEKING_CHARGER"):
self.print_step(8, "Manually put the device in the SEEKING CHARGER operational state")
step_name = "Manually put the device in the SEEKING CHARGER operational state"
self.print_step(8, step_name)
if self.is_ci:
await self.send_run_change_to_mode_cmd(rvc_app_run_mode_cleaning)
await self.send_run_change_to_mode_cmd(rvc_app_run_mode_idle)
else:
input("Press Enter when done.\n")
self.wait_for_user_input(step_name)

await self.read_operational_state_with_check(9, rvc_op_states.kSeekingCharger)

Expand Down
28 changes: 28 additions & 0 deletions src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ def step_unknown(self):
"""
pass

def show_prompt(self,
msg: str,
placeholder: Optional[str] = None,
default_value: Optional[str] = None) -> None:
pass


@dataclass
class MatterTestConfig:
Expand Down Expand Up @@ -1091,6 +1097,28 @@ def get_setup_payload_info(self) -> SetupPayloadInfo:

return info

def wait_for_user_input(self,
prompt_msg: str,
input_msg: str = "Press Enter when done.\n",
prompt_msg_placeholder: str = "Submit anything to continue",
default_value: str = "y") -> str:
"""Ask for user input and wait for it.
Args:
prompt_msg (str): Message for TH UI prompt. Indicates what is expected from the user.
input_msg (str, optional): Prompt for input function, used when running tests manually. Defaults to "Press Enter when done.\n".
prompt_msg_placeholder (str, optional): TH UI prompt input placeholder. Defaults to "Submit anything to continue".
default_value (str, optional): TH UI prompt default value. Defaults to "y".
Returns:
str: User input
"""
if self.runner_hook:
self.runner_hook.show_prompt(msg=prompt_msg,
placeholder=prompt_msg_placeholder,
default_value=default_value)
return input(input_msg)


def generate_mobly_test_config(matter_test_config: MatterTestConfig):
test_run_config = TestRunConfig()
Expand Down

0 comments on commit 2e35d01

Please sign in to comment.