Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: speed up test suite #354

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
os: [Ubuntu, macOS, Windows]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
include:
- python-version: "3.7"
install-args: --version=1.5.1
- os: Ubuntu
image: ubuntu-22.04
- os: Windows
Expand All @@ -39,7 +41,7 @@ jobs:

- name: Install Poetry
run: |
curl -sL https://install.python-poetry.org | python - -y
curl -sL https://install.python-poetry.org | python - -y ${{ matrix.install-args }}

- name: Update PATH
if: ${{ matrix.os != 'Windows' }}
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@


if TYPE_CHECKING:
from typing import Callable
from typing import Iterator

from pytest_mock import MockerFixture


@pytest.fixture()
def io() -> BufferedIO:
Expand Down Expand Up @@ -49,3 +52,15 @@ def argv() -> Iterator[None]:
yield

sys.argv = current_argv


@pytest.fixture()
def sleep(mocker: MockerFixture) -> Iterator[Callable[[float], None]]:
now = 0.0
mocker.patch("time.time", side_effect=lambda: now)

def _sleep(secs: float) -> None:
nonlocal now
now += secs

yield _sleep
10 changes: 5 additions & 5 deletions tests/ui/test_progress_bar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import time

from typing import TYPE_CHECKING

import pytest
Expand All @@ -11,6 +9,8 @@


if TYPE_CHECKING:
from typing import Callable

from cleo.io.buffered_io import BufferedIO


Expand Down Expand Up @@ -486,16 +486,16 @@ def test_overwrite_multiple_progress_bars_with_section_outputs(


def test_min_and_max_seconds_between_redraws(
ansi_bar: ProgressBar, ansi_io: BufferedIO
ansi_bar: ProgressBar, ansi_io: BufferedIO, sleep: Callable[[float], None]
) -> None:
ansi_bar.min_seconds_between_redraws(0.5)
ansi_bar.max_seconds_between_redraws(2 - 1)

ansi_bar.start()
ansi_bar.set_progress(1)
time.sleep(1)
sleep(1)
ansi_bar.set_progress(2)
time.sleep(2)
sleep(2)
ansi_bar.set_progress(3)

output = [
Expand Down
40 changes: 20 additions & 20 deletions tests/ui/test_progress_indicator.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
from __future__ import annotations

import time

from typing import TYPE_CHECKING

from cleo.ui.progress_indicator import ProgressIndicator


if TYPE_CHECKING:
from typing import Callable

from cleo.io.buffered_io import BufferedIO


def test_default_indicator(ansi_io: BufferedIO) -> None:
def test_default_indicator(ansi_io: BufferedIO, sleep: Callable[[float], None]) -> None:
bar = ProgressIndicator(ansi_io)
bar.start("Starting...")
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.set_message("Advancing...")
bar.advance()
bar.finish("Done...")
bar.start("Starting Again...")
time.sleep(0.101)
sleep(0.101)
bar.advance()
bar.finish("Done Again...")
bar.start("Starting Again...")
time.sleep(0.101)
sleep(0.101)
bar.advance()
bar.finish("Done Again...", reset_indicator=True)

Expand Down Expand Up @@ -68,29 +68,29 @@ def test_default_indicator(ansi_io: BufferedIO) -> None:
assert expected == ansi_io.fetch_error()


def test_explicit_format(ansi_io: BufferedIO) -> None:
def test_explicit_format(ansi_io: BufferedIO, sleep: Callable[[float], None]) -> None:
bar = ProgressIndicator(ansi_io, ProgressIndicator.NORMAL)
bar.start("Starting...")
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.advance()
time.sleep(0.101)
sleep(0.101)
bar.set_message("Advancing...")
bar.advance()
bar.finish("Done...")
bar.start("Starting Again...")
time.sleep(0.101)
sleep(0.101)
bar.advance()
bar.finish("Done Again...")
bar.start("Starting Again...")
time.sleep(0.101)
sleep(0.101)
bar.advance()
bar.finish("Done Again...", reset_indicator=True)

Expand Down