Skip to content

Commit

Permalink
Fix mismatch description with multiple calls
Browse files Browse the repository at this point in the history
  • Loading branch information
keis committed Nov 4, 2016
1 parent dcd693d commit aea7c76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion matchmock.py
Expand Up @@ -158,8 +158,10 @@ def describe_mismatch(self, item, mismatch_description):
if item.call_count > 0:
for i, call in enumerate(item.call_args_list):
if item.call_count > 1:
mismatch_description.append_text('in call ' + i)
mismatch_description.append_text('in call %s: ' % i)
self.call.describe_mismatch(call, mismatch_description)
if i != item.call_count - 1:
mismatch_description.append_text(', ')

def describe_to(self, desc):
desc.append_text('Mock called ')
Expand Down
12 changes: 12 additions & 0 deletions test_matchmock.py
Expand Up @@ -164,6 +164,18 @@ def test_called_with_failed(desc):
assert_that(str(desc), equal_to(expected))


def test_called_with_failed_multi(desc):
expected = "in call 0: argument 1: was 'bar', in call 1: 1 extra arguments"
matcher = called_with('foo', instance_of(int))
mock = Mock()
mock('foo', 'bar')
mock('foo', 'bar', 'baz')

ok = matcher.matches(mock, desc)
assert_that(ok, equal_to(False))
assert_that(str(desc), equal_to(expected))


def test_called_with_kwarg_failed(desc):
expected = "value for 'foo' was 'baz'"
matcher = called_with(foo='bar')
Expand Down

0 comments on commit aea7c76

Please sign in to comment.