blob: e42eafdba4a046d5fb82caa23426858dece2a288 (
plain)
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
|
from __future__ import absolute_import, division, unicode_literals
import six
from mock import Mock
from . import support
def _createReprMock(r):
"""Creates a mock with a __repr__ returning r
Also provides __str__ mock with default mock behaviour"""
mock = Mock()
mock.__repr__ = Mock()
mock.__repr__.return_value = r
mock.__str__ = Mock(wraps=mock.__str__)
return mock
def test_errorMessage():
# Create mock objects to take repr of
input = _createReprMock("1")
expected = _createReprMock("2")
actual = _createReprMock("3")
# Run the actual test
r = support.errorMessage(input, expected, actual)
# Assertions!
if six.PY2:
assert b"Input:\n1\nExpected:\n2\nRecieved\n3\n" == r
else:
assert six.PY3
assert "Input:\n1\nExpected:\n2\nRecieved\n3\n" == r
assert input.__repr__.call_count == 1
assert expected.__repr__.call_count == 1
assert actual.__repr__.call_count == 1
assert not input.__str__.called
assert not expected.__str__.called
assert not actual.__str__.called
|