|
| 1 | +from __future__importabsolute_import,division,unicode_literals |
| 2 | + |
| 3 | +importsix |
| 4 | +frommockimportMock |
| 5 | + |
| 6 | +from .importsupport |
| 7 | + |
| 8 | + |
| 9 | +def_createReprMock(r): |
| 10 | +"""Creates a mock with a __repr__ returning r |
| 11 | +
|
| 12 | + Also provides __str__ mock with default mock behaviour""" |
| 13 | +mock=Mock() |
| 14 | +mock.__repr__=Mock() |
| 15 | +mock.__repr__.return_value=r |
| 16 | +mock.__str__=Mock(wraps=mock.__str__) |
| 17 | +returnmock |
| 18 | + |
| 19 | + |
| 20 | +deftest_errorMessage(): |
| 21 | +# Create mock objects to take repr of |
| 22 | +input=_createReprMock("1") |
| 23 | +expected=_createReprMock("2") |
| 24 | +actual=_createReprMock("3") |
| 25 | + |
| 26 | +# Run the actual test |
| 27 | +r=support.errorMessage(input,expected,actual) |
| 28 | + |
| 29 | +# Assertions! |
| 30 | +ifsix.PY2: |
| 31 | +assertb"Input:\n1\nExpected:\n2\nRecieved\n3\n"==r |
| 32 | +else: |
| 33 | +assertsix.PY3 |
| 34 | +assert"Input:\n1\nExpected:\n2\nRecieved\n3\n"==r |
| 35 | + |
| 36 | +assertinput.__repr__.call_count==1 |
| 37 | +assertexpected.__repr__.call_count==1 |
| 38 | +assertactual.__repr__.call_count==1 |
| 39 | +assertnotinput.__str__.called |
| 40 | +assertnotexpected.__str__.called |
| 41 | +assertnotactual.__str__.called |