Skip to content

Commit cea5801

Browse files
woody-appleccruzagralopesrestyled-commits
authored
Support user input for python tests in TH (#32299) (#32325)
* 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: Carolina Lopes <116589288+ccruzagralopes@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 4c3c76b commit cea5801

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

scripts/py_matter_yamltests/matter_yamltests/hooks.py

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
from typing import Optional
17+
1618
from .parser import TestStep
1719

1820

@@ -213,6 +215,15 @@ async def step_manual(self):
213215
"""
214216
pass
215217

218+
def show_prompt(self,
219+
msg: str,
220+
placeholder: Optional[str] = None,
221+
default_value: Optional[str] = None) -> None:
222+
"""
223+
This method is called when the step needs to ask the user to perform some action or provide some value.
224+
"""
225+
pass
226+
216227

217228
class WebSocketRunnerHooks():
218229
def connecting(self, url: str):

src/python_testing/TC_RVCOPSTATE_2_4.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,51 @@ async def test_TC_RVCOPSTATE_2_4(self):
115115
self.write_to_app_pipe('{"Name": "Reset"}')
116116

117117
if self.check_pics("RVCOPSTATE.S.M.ST_ERROR"):
118-
self.print_step(2, "Manually put the device in the ERROR operational state")
118+
step_name = "Manually put the device in the ERROR operational state"
119+
self.print_step(2, step_name)
119120
if self.is_ci:
120121
self.write_to_app_pipe('{"Name": "ErrorEvent", "Error": "UnableToStartOrResume"}')
121122
else:
122-
input("Press Enter when done.\n")
123+
self.wait_for_user_input(step_name)
123124

124125
await self.read_operational_state_with_check(3, op_states.kError)
125126

126127
await self.send_go_home_cmd_with_check(4, op_errors.kCommandInvalidInState)
127128

128129
if self.check_pics("RVCOPSTATE.S.M.ST_CHARGING"):
129-
self.print_step(5, "Manually put the device in the CHARGING operational state")
130+
step_name = "Manually put the device in the CHARGING operational state"
131+
self.print_step(5, step_name)
130132
if self.is_ci:
131133
self.write_to_app_pipe('{"Name": "Reset"}')
132134
self.write_to_app_pipe('{"Name": "Docked"}')
133135
self.write_to_app_pipe('{"Name": "Charging"}')
134136
else:
135-
input("Press Enter when done.\n")
137+
self.wait_for_user_input(step_name)
136138

137139
await self.read_operational_state_with_check(6, rvc_op_states.kCharging)
138140

139141
await self.send_go_home_cmd_with_check(7, op_errors.kCommandInvalidInState)
140142

141143
if self.check_pics("RVCOPSTATE.S.M.ST_DOCKED"):
142-
self.print_step(8, "Manually put the device in the DOCKED operational state")
144+
step_name = "Manually put the device in the DOCKED operational state"
145+
self.print_step(8, step_name)
143146
if self.is_ci:
144147
self.write_to_app_pipe('{"Name": "Charged"}')
145148
else:
146-
input("Press Enter when done.\n")
149+
self.wait_for_user_input(step_name)
147150

148151
await self.read_operational_state_with_check(9, rvc_op_states.kDocked)
149152

150153
await self.send_go_home_cmd_with_check(10, op_errors.kCommandInvalidInState)
151154

152155
if self.check_pics("PICS_M_ST_SEEKING_CHARGER"):
153-
self.print_step(8, "Manually put the device in the SEEKING CHARGER operational state")
156+
step_name = "Manually put the device in the SEEKING CHARGER operational state"
157+
self.print_step(8, step_name)
154158
if self.is_ci:
155159
await self.send_run_change_to_mode_cmd(rvc_app_run_mode_cleaning)
156160
await self.send_run_change_to_mode_cmd(rvc_app_run_mode_idle)
157161
else:
158-
input("Press Enter when done.\n")
162+
self.wait_for_user_input(step_name)
159163

160164
await self.read_operational_state_with_check(9, rvc_op_states.kSeekingCharger)
161165

src/python_testing/matter_testing_support.py

+28
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ def step_unknown(self):
346346
"""
347347
pass
348348

349+
def show_prompt(self,
350+
msg: str,
351+
placeholder: Optional[str] = None,
352+
default_value: Optional[str] = None) -> None:
353+
pass
354+
349355

350356
@dataclass
351357
class MatterTestConfig:
@@ -1091,6 +1097,28 @@ def get_setup_payload_info(self) -> SetupPayloadInfo:
10911097

10921098
return info
10931099

1100+
def wait_for_user_input(self,
1101+
prompt_msg: str,
1102+
input_msg: str = "Press Enter when done.\n",
1103+
prompt_msg_placeholder: str = "Submit anything to continue",
1104+
default_value: str = "y") -> str:
1105+
"""Ask for user input and wait for it.
1106+
1107+
Args:
1108+
prompt_msg (str): Message for TH UI prompt. Indicates what is expected from the user.
1109+
input_msg (str, optional): Prompt for input function, used when running tests manually. Defaults to "Press Enter when done.\n".
1110+
prompt_msg_placeholder (str, optional): TH UI prompt input placeholder. Defaults to "Submit anything to continue".
1111+
default_value (str, optional): TH UI prompt default value. Defaults to "y".
1112+
1113+
Returns:
1114+
str: User input
1115+
"""
1116+
if self.runner_hook:
1117+
self.runner_hook.show_prompt(msg=prompt_msg,
1118+
placeholder=prompt_msg_placeholder,
1119+
default_value=default_value)
1120+
return input(input_msg)
1121+
10941122

10951123
def generate_mobly_test_config(matter_test_config: MatterTestConfig):
10961124
test_run_config = TestRunConfig()

0 commit comments

Comments
 (0)