Skip to content

Commit

Permalink
Try to handle enum format changes between 3.10 and 3.11+
Browse files Browse the repository at this point in the history
f'{Foo.A}' uses str.__format__ in 3.10 but enum.__format__ in 3.11+.
Use the name attribute to work with the string directly to ensure the
same behaviour in both environments.
  • Loading branch information
tpoliaw committed Sep 9, 2024
1 parent f10bb22 commit 87f2a8d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/blueapi/cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def display_compact(obj: Any, stream: Stream):
case DataEvent(name=name):
print(f"Data Event: {name}")
case WorkerEvent(state=state):
print(f"Worker Event: {state}")
print(f"Worker Event: {state.name}")
case ProgressEvent(statuses=stats):
prog = (
max(100 * (s.percentage or 0) for s in stats.values())
Expand Down
6 changes: 2 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,11 @@ def test_event_formatting():
""""errors": [], "warnings": []}\n"""
),
)
_assert_matching_formatting(
OutputFormat.COMPACT, worker, "Worker Event: WorkerState.RUNNING\n"
)
_assert_matching_formatting(OutputFormat.COMPACT, worker, "Worker Event: RUNNING\n")
_assert_matching_formatting(
OutputFormat.FULL,
worker,
"WorkerEvent: WorkerState.RUNNING\n task_id: count\n",
"WorkerEvent: RUNNING\n task_id: count\n",
)

_assert_matching_formatting(
Expand Down

0 comments on commit 87f2a8d

Please sign in to comment.