Skip to content
Merged
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions scripts/gha/summarize_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,17 @@ def combine_config(platform, config, config_value, k):
if len(config_value) > 1 and len(config) == len(config_value):
config = ["All %d %s" % (len(config_value), config_name)]
elif config_name == "ios_device":
ftl_devices = set(filter(lambda device: get_test_device(device).get("type") in "ftl", config_value))
simulators = set(filter(lambda device: get_test_device(device).get("type") in "virtual", config_value))
ftl_devices = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "ftl", config_value))
simulators = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "virtual", config_value))
Comment on lines +391 to +392
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the added check for get_test_device(device) correctly prevents a crash, this implementation can be improved for readability and efficiency.

  1. Repeated function calls: get_test_device(device) is called twice in the lambda for each device, and config_value is iterated over twice (once for ftl_devices, once for simulators).
  2. Confusing string check: Using in "ftl" or in "virtual" is confusing and less precise than ==. It works here because the only possible values are "ftl" and "virtual", but it's brittle.

I suggest refactoring this to a single loop that categorizes devices. This is more efficient and readable.

Suggested change
ftl_devices = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "ftl", config_value))
simulators = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "virtual", config_value))
ftl_devices = set()
simulators = set()
for device in config_value:
test_device = get_test_device(device)
if not test_device:
continue
device_type = test_device.get("type")
if device_type == "ftl":
ftl_devices.add(device)
elif device_type == "virtual":
simulators.add(device)

if len(ftl_devices) > 1 and ftl_devices.issubset(set(config)):
config.insert(0, "All %d FTL Devices" % len(ftl_devices))
config = [x for x in config if (x not in ftl_devices)]
if len(simulators) > 1 and simulators.issubset(set(config)):
config.insert(0, "All %d Local Simulators" % len(simulators))
config = [x for x in config if (x not in simulators)]
elif config_name == "android_device":
ftl_devices = set(filter(lambda device: get_test_device(device).get("type") in "ftl", config_value))
emulators = set(filter(lambda device: get_test_device(device).get("type") in "virtual", config_value))
ftl_devices = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "ftl", config_value))
emulators = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "virtual", config_value))
Comment on lines +400 to +401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the ios_device case, this logic can be refactored to be more efficient and readable by using a single loop. This avoids iterating over config_value multiple times and calling get_test_device repeatedly inside the lambdas. This change also replaces the confusing in "string" check with a clearer == comparison.

Suggested change
ftl_devices = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "ftl", config_value))
emulators = set(filter(lambda device: get_test_device(device) and get_test_device(device).get("type") in "virtual", config_value))
ftl_devices = set()
emulators = set()
for device in config_value:
test_device = get_test_device(device)
if not test_device:
continue
device_type = test_device.get("type")
if device_type == "ftl":
ftl_devices.add(device)
elif device_type == "virtual":
emulators.add(device)

if len(ftl_devices) > 1 and ftl_devices.issubset(set(config)):
config.insert(0, "All %d FTL Devices" % len(ftl_devices))
config = [x for x in config if (x not in ftl_devices)]
Expand Down
Loading