Skip to content

Commit ef3a915

Browse files
Refined logging messages format to improve readability.
1 parent 49df59b commit ef3a915

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

scripts/tests/run_tv_casting_test.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __exit__(self, exception_type, exception_value, traceback):
7878
def dump_temporary_logs_to_console(log_file_path: str):
7979
"""Dump log file to the console; log file will be removed once the function exits."""
8080
"""Write the entire content of `log_file_path` to the console."""
81-
print('\nDumping logs from: ', log_file_path)
81+
print(f'\nDumping logs from: {log_file_path}')
8282

8383
with open(log_file_path, 'r') as file:
8484
for line in file:
@@ -87,13 +87,13 @@ def dump_temporary_logs_to_console(log_file_path: str):
8787

8888
def handle_casting_failure(casting_state: str, log_file_paths: List[str]):
8989
"""Log '{casting_state} failed!' as error, dump log files to console, exit on error."""
90-
logging.error(casting_state + ' failed!')
90+
logging.error(f'{casting_state} failed!')
9191

9292
for log_file_path in log_file_paths:
9393
try:
9494
dump_temporary_logs_to_console(log_file_path)
9595
except Exception as e:
96-
logging.exception(f"Failed to dump {log_file_path}: {e}")
96+
logging.exception(f'Failed to dump {log_file_path}: {e}')
9797

9898
sys.exit(1)
9999

@@ -178,8 +178,8 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
178178
while True:
179179
# Check if we exceeded the maximum wait time for initiating 'cast request' from the Linux tv-casting-app to the Linux tv-app.
180180
if time.time() - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC:
181-
logging.error('The command `cast request ' + valid_discovered_commissioner_number +
182-
'` was not issued to the Linux tv-casting-app process within the timeout.')
181+
logging.error(
182+
f'The command `cast request {valid_discovered_commissioner_number}` was not issued to the Linux tv-casting-app process within the timeout.')
183183
return False
184184

185185
tv_casting_app_output_line = tv_casting_app_process.stdout.readline()
@@ -194,7 +194,9 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
194194
next_line = tv_casting_app_process.stdout.readline()
195195
linux_tv_casting_app_log_file.write(next_line)
196196
linux_tv_casting_app_log_file.flush()
197-
logging.info('Sent `' + next_line.rstrip('\n') + '` to the Linux tv-casting-app process.')
197+
next_line = next_line.rstrip('\n')
198+
logging.info(f'Sent `{next_line}` to the Linux tv-casting-app process.')
199+
198200
return True
199201

200202

@@ -291,8 +293,8 @@ def validate_tv_casting_request_approval(tv_app_info: Tuple[subprocess.Popen, Te
291293
tv_app_line = tv_app_process.stdout.readline()
292294
linux_tv_app_log_file.write(tv_app_line)
293295
linux_tv_app_log_file.flush()
294-
295-
logging.info('Sent `' + tv_app_line.rstrip('\n') + '` to the Linux tv-app process.')
296+
tv_app_line = tv_app_line.rstrip('\n')
297+
logging.info(f'Sent `{tv_app_line}` to the Linux tv-app process.')
296298
return True
297299

298300

@@ -512,6 +514,12 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
512514
expected_device_name, expected_vendor_id, expected_product_id = extract_device_info_from_tv_casting_app(
513515
tv_casting_app_info, 'Commissioning', log_paths)
514516

517+
if not expected_device_name or not expected_vendor_id or not expected_product_id:
518+
logging.error('The is an error with the expected device info values that were extracted from the `Identification Declaration` block.')
519+
logging.error(
520+
f'expected_device_name: {expected_device_name}, expected_vendor_id: {expected_vendor_id}, expected_product_id: {expected_product_id}')
521+
handle_casting_failure('Commissioning', log_paths)
522+
515523
if not validate_identification_declaration_message_on_tv_app(tv_app_info, expected_device_name, expected_vendor_id, expected_product_id, log_paths):
516524
handle_casting_failure('Commissioning', log_paths)
517525

0 commit comments

Comments
 (0)