Skip to content

Commit

Permalink
Use custom string to represent args_validator in exceptions (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
toddsifleet authored Apr 25, 2018
1 parent f69bac5 commit c7eb40d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doubles/allowance.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,7 @@ def _expected_argument_string(self):

if self.args is _any and self.kwargs is _any:
return 'any args'
elif self._custom_matcher:
return "custom matcher: '{}'".format(self._custom_matcher.__name__)
else:
return build_argument_repr_string(self.args, self.kwargs)
19 changes: 19 additions & 0 deletions test/expect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@


class TestExpect(object):
def test_with_args_validator_not_called(self):
subject = InstanceDouble('doubles.testing.User')

def arg_matcher(*args):
return True
expect(subject).method_with_varargs.with_args_validator(arg_matcher)
with raises(MockExpectationError) as e:
verify()
teardown()

assert re.match(
r"Expected 'method_with_varargs' to be called on "
r"<InstanceDouble of <class '?doubles.testing.User'?"
r"(?: at 0x[0-9a-f]{9})?> object at .+> "
r"with custom matcher: 'arg_matcher', but was not."
r" \(.*doubles/test/expect_test.py:\d+\)",
str(e.value)
)

def test_with_args_validator(self):
subject = InstanceDouble('doubles.testing.User')

Expand Down

0 comments on commit c7eb40d

Please sign in to comment.