1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
from __future__ import annotations
import os
import sys
from io import StringIO
from typing import TYPE_CHECKING
import pytest
from cleo.io.buffered_io import BufferedIO
from cleo.io.inputs.string_input import StringInput
if TYPE_CHECKING:
from typing import Callable
from typing import Iterator
from pytest_mock import MockerFixture
@pytest.fixture()
def io() -> BufferedIO:
input_ = StringInput("")
input_.set_stream(StringIO())
return BufferedIO(input_)
@pytest.fixture()
def ansi_io() -> BufferedIO:
input_ = StringInput("")
input_.set_stream(StringIO())
return BufferedIO(input_, decorated=True)
@pytest.fixture()
def environ() -> Iterator[None]:
current_environ = dict(os.environ)
yield
os.environ.clear()
os.environ.update(current_environ)
@pytest.fixture()
def argv() -> Iterator[None]:
current_argv = sys.argv
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
|