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
|
MYPY = False
if MYPY:
import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression
from unittest.mock import DEFAULT, Mock
from stone.backend import Backend
def _mock_output(backend):
# type: (Backend) -> typing.Callable[[], str]
"""
Mock out Backend's .emit function, and return a list containing all params
emit was called with.
"""
recorded_output = [] # type: typing.List[str]
output_buffer_to_string = backend.output_buffer_to_string
def record_output():
recorded_output.append(output_buffer_to_string())
return DEFAULT
backend.output_buffer_to_string = Mock( # type: ignore
wraps=output_buffer_to_string,
side_effect=record_output)
def get_output():
backend.output_buffer_to_string = output_buffer_to_string
return recorded_output[0] if recorded_output else ''
return get_output
|