Skip to content

Commit f9feee2

Browse files
committed
Clean up AI code
1 parent 64af17e commit f9feee2

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

tests/helpers/__init__.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,42 +301,28 @@ async def print_history(handle: WorkflowHandle):
301301

302302
async def print_interleaved_histories(*handles: WorkflowHandle) -> None:
303303
"""
304-
Print the interleaved history events from multiple workflow handles in columns,
305-
with each workflow's events in its own column, sorted chronologically.
306-
Each workflow's events are numbered independently.
304+
Print the interleaved history events from multiple workflow handles in columns.
307305
"""
308-
# Collect all events from all handles with their sequence numbers
309306
all_events: list[tuple[WorkflowHandle, HistoryEvent, int]] = []
310-
311307
for handle in handles:
312308
event_num = 1
313309
async for event in handle.fetch_history_events():
314310
all_events.append((handle, event, event_num))
315311
event_num += 1
316-
317-
# Sort by event time
318312
all_events.sort(key=lambda item: item[1].event_time.ToDatetime())
319-
320-
# Prepare column headers
321313
col_width = 40
322-
headers = [handle.id for handle in handles]
323314

324-
# Print headers
325-
print("\nInterleaved histories:")
326-
print("-" * (col_width * len(handles) + len(handles) - 1))
327-
print(" | ".join(f"{h[: col_width - 3]:<{col_width - 3}}" for h in headers))
328-
print("-" * (col_width * len(handles) + len(handles) - 1))
315+
def _format_row(items: list[str], truncate: bool = False) -> str:
316+
if truncate:
317+
items = [item[: col_width - 3] for item in items]
318+
return " | ".join(f"{item:<{col_width - 3}}" for item in items)
329319

330-
# Print events
320+
headers = [handle.id for handle in handles]
321+
print(_format_row(headers, truncate=True))
322+
print("-" * (col_width * len(handles) + len(handles) - 1))
331323
for handle, event, event_num in all_events:
332324
event_type = EventType.Name(event.event_type).removeprefix("EVENT_TYPE_")
333-
334-
# Create row with empty cells
335325
row = [""] * len(handles)
336-
337-
# Find which column this event belongs to
338326
col_idx = handles.index(handle)
339327
row[col_idx] = f"{event_num:2}: {event_type[: col_width - 5]}"
340-
341-
# Print the row
342-
print(" | ".join(f"{cell:<{col_width - 3}}" for cell in row))
328+
print(_format_row(row))

0 commit comments

Comments
 (0)