Skip to content

Commit

Permalink
Simplify test code for async progress bar
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <[email protected]>
  • Loading branch information
lebrice committed Jun 3, 2024
1 parent 9a47386 commit 855f6fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
25 changes: 5 additions & 20 deletions tests/utils/test_parallel_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@
OutT = TypeVar("OutT")


@pytest.fixture()
def mock_time_elapsed_column(monkeypatch: pytest.MonkeyPatch):
from rich.progress import Task, TimeElapsedColumn
from rich.text import Text

def render(self, task: Task) -> Text:
"""Show time elapsed."""
elapsed = task.finished_time if task.finished else task.elapsed
if elapsed is None:
return Text("-:--:--", style="progress.elapsed")
return Text("", style="progress.elapsed")

monkeypatch.setattr(TimeElapsedColumn, "render", render)


async def _async_task_fn(
report_progress: ReportProgressFn,
task_id: int,
Expand All @@ -62,9 +47,7 @@ async def _async_task_fn(
strict=True,
)
@pytest.mark.asyncio
async def test_async_progress_bar(
file_regression: FileRegressionFixture, mock_time_elapsed_column: None
):
async def test_async_progress_bar(file_regression: FileRegressionFixture):
num_tasks = 4
task_length = 5
task_lengths = [task_length for _ in range(num_tasks)]
Expand All @@ -80,7 +63,9 @@ async def test_async_progress_bar(
start_time = time.time()
with console.capture() as capture:
# NOTE: the results are returned as a list (all at the same time).
results = await run_async_tasks_with_progress_bar(task_fns)
results = await run_async_tasks_with_progress_bar(
task_fns, _show_elapsed_time=False
)
assert results == task_results

all_output = capture.get()
Expand All @@ -102,7 +87,7 @@ async def test_async_progress_bar(


@pytest.mark.asyncio
async def test_interrupt_progress_bar(mock_time_elapsed_column: None):
async def test_interrupt_progress_bar():
"""Test the case where one of the tasks raises an exception."""
num_tasks = 4
task_length = 5
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/test_parallel_progress/test_async_progress_bar.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
✓ All jobs progress: 20/20 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 0 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 1 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 2 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 3 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ All jobs progress: 20/20 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 0 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 1 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 2 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
✓ Task 3 - Done. 5/5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%

0 comments on commit 855f6fc

Please sign in to comment.