Skip to content

Commit b88cdf1

Browse files
Run restyle.
1 parent 416b23f commit b88cdf1

File tree

3 files changed

+90
-83
lines changed

3 files changed

+90
-83
lines changed

scripts/tests/linux/tv_casting_test_sequence_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Additionally, it provides helper functions to retrieve specific test sequences or all defined test sequences.
2525
"""
2626

27+
2728
class App(Enum):
2829
"""An enumeration of the supported applications."""
2930

@@ -59,7 +60,8 @@ def __init__(
5960
):
6061
# Validate that either `output_msg` or `input_cmd` is provided, but not both.
6162
if output_msg is not None and input_cmd is not None:
62-
raise ValueError('Step cannot contain both `output_msg` and `input_cmd`. Either `output_msg` or `input_cmd` should be provided.')
63+
raise ValueError(
64+
'Step cannot contain both `output_msg` and `input_cmd`. Either `output_msg` or `input_cmd` should be provided.')
6365
elif output_msg is None and input_cmd is None:
6466
raise ValueError('Step must contain either `output_msg` or `input_cmd`. Both are `None`.')
6567

@@ -87,7 +89,6 @@ def __init__(self, name: str, steps: List[Step]):
8789
self.name = name
8890
self.steps = steps
8991

90-
9192
@staticmethod
9293
def get_test_sequence_by_name(test_sequences: List['Sequence'], test_sequence_name: str) -> Optional['Sequence']:
9394
"""Retrieve a test sequence from a list of sequences by its name."""
@@ -97,11 +98,10 @@ def get_test_sequence_by_name(test_sequences: List['Sequence'], test_sequence_na
9798
return sequence
9899
return None
99100

100-
101101
@staticmethod
102102
def get_test_sequences() -> List['Sequence']:
103103
"""Retrieve all the test sequences to validate the casting experience between the Linux tv-casting-app and the Linux tv-app."""
104104

105105
from linux.tv_casting_test_sequences import test_sequences
106-
107-
return test_sequences
106+
107+
return test_sequences

scripts/tests/linux/tv_casting_test_sequences.py

+52-52
Original file line numberDiff line numberDiff line change
@@ -78,75 +78,75 @@
7878
ATTRIBUTE_CURRENT_PLAYBACK_STATE = '0x0000_0000' # Application Cluster Spec 6.10.6 Attribute ID: Current State of Playback
7979

8080
test_sequences = [
81-
Sequence(
82-
name='commissionee_generated_passcode_test',
83-
steps=[
84-
# Signal to start the tv-app.
85-
Step(app=App.TV_APP, input_cmd=START_APP),
81+
Sequence(
82+
name='commissionee_generated_passcode_test',
83+
steps=[
84+
# Signal to start the tv-app.
85+
Step(app=App.TV_APP, input_cmd=START_APP),
8686

87-
# Validate that the tv-app is up and running.
88-
Step(app=App.TV_APP, timeout_sec=APP_MAX_START_WAIT_SEC, output_msg=['Started commissioner']),
87+
# Validate that the tv-app is up and running.
88+
Step(app=App.TV_APP, timeout_sec=APP_MAX_START_WAIT_SEC, output_msg=['Started commissioner']),
8989

90-
# Signal to start the tv-casting-app.
91-
Step(app=App.TV_CASTING_APP, input_cmd=START_APP),
90+
# Signal to start the tv-casting-app.
91+
Step(app=App.TV_CASTING_APP, input_cmd=START_APP),
9292

93-
# Validate that the server is properly initialized in the tv-casting-app output.
94-
Step(app=App.TV_CASTING_APP, timeout_sec=APP_MAX_START_WAIT_SEC, output_msg=['Server initialization complete']),
93+
# Validate that the server is properly initialized in the tv-casting-app output.
94+
Step(app=App.TV_CASTING_APP, timeout_sec=APP_MAX_START_WAIT_SEC, output_msg=['Server initialization complete']),
9595

96-
# Validate that there is a valid discovered commissioner with {VENDOR_ID}, {PRODUCT_ID}, and {DEVICE_TYPE_CASTING_VIDEO_PLAYER} in the tv-casting-app output.
97-
Step(app=App.TV_CASTING_APP, output_msg=['Discovered Commissioner #0', f'Vendor ID: {VENDOR_ID}', f'Product ID: {PRODUCT_ID}',
98-
f'Device Type: {DEVICE_TYPE_CASTING_VIDEO_PLAYER}', 'Supports Commissioner Generated Passcode: true']),
96+
# Validate that there is a valid discovered commissioner with {VENDOR_ID}, {PRODUCT_ID}, and {DEVICE_TYPE_CASTING_VIDEO_PLAYER} in the tv-casting-app output.
97+
Step(app=App.TV_CASTING_APP, output_msg=['Discovered Commissioner #0', f'Vendor ID: {VENDOR_ID}', f'Product ID: {PRODUCT_ID}',
98+
f'Device Type: {DEVICE_TYPE_CASTING_VIDEO_PLAYER}', 'Supports Commissioner Generated Passcode: true']),
9999

100-
# Validate that we are ready to send `cast request` command to the tv-casting-app subprocess.
101-
Step(app=App.TV_CASTING_APP, output_msg=['Example: cast request 0']),
100+
# Validate that we are ready to send `cast request` command to the tv-casting-app subprocess.
101+
Step(app=App.TV_CASTING_APP, output_msg=['Example: cast request 0']),
102102

103-
# Send `cast request {valid_discovered_commissioner_number}\n` command to the tv-casting-app subprocess.
104-
Step(app=App.TV_CASTING_APP, input_cmd='cast request 0\n'),
103+
# Send `cast request {valid_discovered_commissioner_number}\n` command to the tv-casting-app subprocess.
104+
Step(app=App.TV_CASTING_APP, input_cmd='cast request 0\n'),
105105

106-
# Validate that the `Identification Declaration` message block in the tv-casting-app output has the expected values for `device Name`, `vendor id`, and `product id`.
107-
Step(app=App.TV_CASTING_APP, output_msg=['Identification Declaration Start', f'device Name: {TEST_TV_CASTING_APP_DEVICE_NAME}',
108-
f'vendor id: {VENDOR_ID}', f'product id: {PRODUCT_ID}', 'Identification Declaration End']),
106+
# Validate that the `Identification Declaration` message block in the tv-casting-app output has the expected values for `device Name`, `vendor id`, and `product id`.
107+
Step(app=App.TV_CASTING_APP, output_msg=['Identification Declaration Start', f'device Name: {TEST_TV_CASTING_APP_DEVICE_NAME}',
108+
f'vendor id: {VENDOR_ID}', f'product id: {PRODUCT_ID}', 'Identification Declaration End']),
109109

110-
# Validate that the `Identification Declaration` message block in the tv-app output has the expected values for `device Name`, `vendor id`, and `product id`.
111-
Step(app=App.TV_APP, output_msg=['Identification Declaration Start', f'device Name: {TEST_TV_CASTING_APP_DEVICE_NAME}',
110+
# Validate that the `Identification Declaration` message block in the tv-app output has the expected values for `device Name`, `vendor id`, and `product id`.
111+
Step(app=App.TV_APP, output_msg=['Identification Declaration Start', f'device Name: {TEST_TV_CASTING_APP_DEVICE_NAME}',
112112
f'vendor id: {VENDOR_ID}', f'product id: {PRODUCT_ID}', 'Identification Declaration End']),
113113

114-
# Validate that we received the cast request from the tv-casting-app on the tv-app output.
115-
Step(app=App.TV_APP,
116-
output_msg=['PROMPT USER: Test TV casting app is requesting permission to cast to this TV, approve?']),
114+
# Validate that we received the cast request from the tv-casting-app on the tv-app output.
115+
Step(app=App.TV_APP,
116+
output_msg=['PROMPT USER: Test TV casting app is requesting permission to cast to this TV, approve?']),
117117

118-
# Validate that we received the instructions on the tv-app output for sending the `controller ux ok` command.
119-
Step(app=App.TV_APP, output_msg=['Via Shell Enter: controller ux ok|cancel']),
118+
# Validate that we received the instructions on the tv-app output for sending the `controller ux ok` command.
119+
Step(app=App.TV_APP, output_msg=['Via Shell Enter: controller ux ok|cancel']),
120120

121-
# Send `controller ux ok` command to the tv-app subprocess.
122-
Step(app=App.TV_APP, input_cmd='controller ux ok\n'),
121+
# Send `controller ux ok` command to the tv-app subprocess.
122+
Step(app=App.TV_APP, input_cmd='controller ux ok\n'),
123123

124-
# Validate that pairing succeeded between the tv-casting-app and the tv-app.
125-
Step(app=App.TV_APP, output_msg=['Secure Pairing Success']),
124+
# Validate that pairing succeeded between the tv-casting-app and the tv-app.
125+
Step(app=App.TV_APP, output_msg=['Secure Pairing Success']),
126126

127-
# Validate that commissioning succeeded in the tv-casting-app output.
128-
Step(app=App.TV_CASTING_APP, output_msg=['Commissioning completed successfully']),
127+
# Validate that commissioning succeeded in the tv-casting-app output.
128+
Step(app=App.TV_CASTING_APP, output_msg=['Commissioning completed successfully']),
129129

130-
# Validate that commissioning succeeded in the tv-app output.
131-
Step(app=App.TV_APP, output_msg=['------PROMPT USER: commissioning success']),
130+
# Validate that commissioning succeeded in the tv-app output.
131+
Step(app=App.TV_APP, output_msg=['------PROMPT USER: commissioning success']),
132132

133-
# Validate the subscription state by looking at the `Cluster` and `Attribute` values in the `ReportDataMessage` block in the tv-casting-app output.
134-
Step(app=App.TV_CASTING_APP, output_msg=[
135-
'ReportDataMessage =', f'Cluster = {CLUSTER_MEDIA_PLAYBACK}', f'Attribute = {ATTRIBUTE_CURRENT_PLAYBACK_STATE}', 'InteractionModelRevision =', '}']),
133+
# Validate the subscription state by looking at the `Cluster` and `Attribute` values in the `ReportDataMessage` block in the tv-casting-app output.
134+
Step(app=App.TV_CASTING_APP, output_msg=[
135+
'ReportDataMessage =', f'Cluster = {CLUSTER_MEDIA_PLAYBACK}', f'Attribute = {ATTRIBUTE_CURRENT_PLAYBACK_STATE}', 'InteractionModelRevision =', '}']),
136136

137-
# Validate the LaunchURL in the tv-app output.
138-
Step(app=App.TV_APP,
139-
output_msg=['ContentLauncherManager::HandleLaunchUrl TEST CASE ContentURL=https://www.test.com/videoid DisplayString=Test video']),
137+
# Validate the LaunchURL in the tv-app output.
138+
Step(app=App.TV_APP,
139+
output_msg=['ContentLauncherManager::HandleLaunchUrl TEST CASE ContentURL=https://www.test.com/videoid DisplayString=Test video']),
140140

141-
# Validate the LaunchURL in the tv-casting-app output.
142-
Step(app=App.TV_CASTING_APP, output_msg=['InvokeResponseMessage =',
143-
'exampleData', 'InteractionModelRevision =', '},']),
141+
# Validate the LaunchURL in the tv-casting-app output.
142+
Step(app=App.TV_CASTING_APP, output_msg=['InvokeResponseMessage =',
143+
'exampleData', 'InteractionModelRevision =', '},']),
144144

145-
# Signal to stop the tv-casting-app as we finished validation.
146-
Step(app=App.TV_CASTING_APP, input_cmd=STOP_APP),
145+
# Signal to stop the tv-casting-app as we finished validation.
146+
Step(app=App.TV_CASTING_APP, input_cmd=STOP_APP),
147147

148-
# Signal to stop the tv-app as we finished validation.
149-
Step(app=App.TV_APP, input_cmd=STOP_APP)
150-
]
151-
)
152-
]
148+
# Signal to stop the tv-app as we finished validation.
149+
Step(app=App.TV_APP, input_cmd=STOP_APP)
150+
]
151+
)
152+
]

scripts/tests/run_tv_casting_test.py

+33-26
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import sys
2222
import tempfile
2323
import time
24-
from linux.tv_casting_test_sequence_utils import App, Sequence, Step
25-
from linux.tv_casting_test_sequences import START_APP, STOP_APP
2624
from typing import List, TextIO, Tuple
2725

2826
import click
27+
from linux.tv_casting_test_sequence_utils import App, Sequence, Step
28+
from linux.tv_casting_test_sequences import START_APP, STOP_APP
2929

3030
"""
3131
This script can be used to validate the casting experience between the Linux tv-casting-app and the Linux tv-app.
@@ -101,10 +101,11 @@ def stop_app(test_sequence_name: str, app_name: str, app: subprocess.Popen):
101101
logging.info(f'{test_sequence_name}: {app_name} stopped by {signal_number} (SIGTERM) signal.')
102102
return True
103103
else:
104-
logging.error(f'{test_sequence_name}: {app_name} stopped by signal {signal_number} instead of {signal.SIGTERM.value} (SIGTERM).')
104+
logging.error(
105+
f'{test_sequence_name}: {app_name} stopped by signal {signal_number} instead of {signal.SIGTERM.value} (SIGTERM).')
105106
else:
106107
logging.error(f'{test_sequence_name}: {app_name} exited with unexpected exit code {app_exit_code}.')
107-
108+
108109
return False
109110

110111

@@ -116,7 +117,7 @@ def parse_output_msg_in_subprocess(
116117
test_sequence_step: Step
117118
):
118119
"""Parse the output of a given `app` subprocess and validate its output against the expected `output_msg` in the given `Step`."""
119-
120+
120121
if not test_sequence_step.output_msg:
121122
logging.error(f'{test_sequence_name} - No output message provided in the test sequence step.')
122123
return False
@@ -191,23 +192,23 @@ def send_input_cmd_to_subprocess(
191192

192193

193194
def handle_output_msg(
194-
tv_casting_app_info: Tuple[subprocess.Popen, TextIO],
195-
tv_app_info: Tuple[subprocess.Popen, TextIO],
196-
log_paths: List[str],
197-
test_sequence_name: str,
195+
tv_casting_app_info: Tuple[subprocess.Popen, TextIO],
196+
tv_app_info: Tuple[subprocess.Popen, TextIO],
197+
log_paths: List[str],
198+
test_sequence_name: str,
198199
test_sequence_step: Step
199200
):
200201
"""Handle the output message (`output_msg`) from a test sequence step."""
201-
202+
202203
if not parse_output_msg_in_subprocess(tv_casting_app_info, tv_app_info, log_paths, test_sequence_name, test_sequence_step):
203204
handle_casting_failure(test_sequence_name, log_paths)
204205

205206

206207
def handle_input_cmd(
207-
tv_casting_app_info: Tuple[subprocess.Popen, TextIO],
208-
tv_app_info: Tuple[subprocess.Popen, TextIO],
209-
log_paths: List[str],
210-
test_sequence_name: str,
208+
tv_casting_app_info: Tuple[subprocess.Popen, TextIO],
209+
tv_app_info: Tuple[subprocess.Popen, TextIO],
210+
log_paths: List[str],
211+
test_sequence_name: str,
211212
test_sequence_step: Step
212213
):
213214
"""Handle the input command (`input_cmd`) from a test sequence step."""
@@ -230,11 +231,11 @@ def handle_input_cmd(
230231

231232

232233
def run_test_sequence_steps(
233-
current_index: int,
234-
test_sequence_name: str,
235-
test_sequence_steps: List[Step],
236-
tv_casting_app_info: Tuple[subprocess.Popen, TextIO],
237-
tv_app_info: Tuple[subprocess.Popen, TextIO],
234+
current_index: int,
235+
test_sequence_name: str,
236+
test_sequence_steps: List[Step],
237+
tv_casting_app_info: Tuple[subprocess.Popen, TextIO],
238+
tv_app_info: Tuple[subprocess.Popen, TextIO],
238239
log_paths: List[str]
239240
):
240241
"""Run through the test steps from a test sequence starting from the current index and perform actions based on the presence of `output_msg` or `input_cmd`."""
@@ -271,7 +272,7 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
271272
linux_tv_app_log_path = os.path.join(temp_dir, LINUX_TV_APP_LOGS)
272273
linux_tv_casting_app_log_path = os.path.join(temp_dir, LINUX_TV_CASTING_APP_LOGS)
273274

274-
print(temp_dir) # SHAO remove when done
275+
print(temp_dir) # SHAO remove when done
275276

276277
with open(linux_tv_app_log_path, 'w') as linux_tv_app_log_file, open(linux_tv_casting_app_log_path, 'w') as linux_tv_casting_app_log_file:
277278

@@ -297,7 +298,8 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
297298

298299
current_index = 0
299300
if test_sequence_steps[current_index].input_cmd != START_APP:
300-
raise ValueError(f'{test_sequence_name}: The first step in the test sequence must contain `START_APP` as `input_cmd` to indicate starting the tv-app.')
301+
raise ValueError(
302+
f'{test_sequence_name}: The first step in the test sequence must contain `START_APP` as `input_cmd` to indicate starting the tv-app.')
301303
elif test_sequence_steps[current_index].app != App.TV_APP:
302304
raise ValueError(f'{test_sequence_name}: The first step in the test sequence must be to start up the tv-app.')
303305
current_index += 1
@@ -308,13 +310,16 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
308310
tv_app_info = (tv_app_process, linux_tv_app_log_file)
309311

310312
# Verify that the tv-app is up and running.
311-
handle_output_msg(None, tv_app_info, [linux_tv_app_log_path], test_sequence_name, test_sequence_steps[current_index])
313+
handle_output_msg(None, tv_app_info, [linux_tv_app_log_path],
314+
test_sequence_name, test_sequence_steps[current_index])
312315
current_index += 1
313316

314317
if test_sequence_steps[current_index].input_cmd != START_APP:
315-
raise ValueError(f'{test_sequence_name}: The third step in the test sequence must contain `START_APP` as `input_cmd` to indicate starting the tv-casting-app.')
318+
raise ValueError(
319+
f'{test_sequence_name}: The third step in the test sequence must contain `START_APP` as `input_cmd` to indicate starting the tv-casting-app.')
316320
elif test_sequence_steps[current_index].app != App.TV_CASTING_APP:
317-
raise ValueError(f'{test_sequence_name}: The third step in the test sequence must be to start up the tv-casting-app.')
321+
raise ValueError(
322+
f'{test_sequence_name}: The third step in the test sequence must be to start up the tv-casting-app.')
318323
current_index += 1
319324

320325
tv_casting_app_abs_path = os.path.abspath(tv_casting_app_rel_path)
@@ -324,10 +329,12 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
324329
tv_casting_app_info = (tv_casting_app_process, linux_tv_casting_app_log_file)
325330

326331
# Verify that the server initialization is completed in the tv-casting-app output.
327-
handle_output_msg(tv_casting_app_info, tv_app_info, log_paths, test_sequence_name, test_sequence_steps[current_index])
332+
handle_output_msg(tv_casting_app_info, tv_app_info, log_paths,
333+
test_sequence_name, test_sequence_steps[current_index])
328334
current_index += 1
329335

330-
run_test_sequence_steps(current_index, test_sequence_name, test_sequence_steps, tv_casting_app_info, tv_app_info, log_paths)
336+
run_test_sequence_steps(current_index, test_sequence_name, test_sequence_steps,
337+
tv_casting_app_info, tv_app_info, log_paths)
331338

332339

333340
if __name__ == '__main__':

0 commit comments

Comments
 (0)