forked from dropbox/stone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend_test_util.py
More file actions
28 lines (22 loc) · 863 Bytes
/
backend_test_util.py
File metadata and controls
28 lines (22 loc) · 863 Bytes
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
MYPY = False
if MYPY:
import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression
try:
# Works for Py 3.3+
from unittest.mock import Mock
except ImportError:
# See https://github.com/python/mypy/issues/1153#issuecomment-253842414
from mock import Mock # type: ignore
from stone.backend import Backend # noqa: F401 # pylint: disable=unused-import
def _mock_emit(backend):
# type: (Backend) -> typing.List[str]
"""
Mock out Backend's .emit function, and return a list containing all params
emit was called with.
"""
recorded_emits = [] # type: typing.List[str]
def record_emit(s):
recorded_emits.append(s)
orig_append = backend._append_output
backend._append_output = Mock(wraps=orig_append, side_effect=record_emit) # type: ignore
return recorded_emits