def __call__(self, expected): self._expected = expected return self def match(self, actual): self._actual = actual return self._actual is self._expected def message_for_failed_should(self): return "%r was expected to be %r" % (self._actual, self._expected) def message_for_failed_should_not(self): return "%r was not expected to be %r" % (self._actual, self._expected) matcher(Be) @matcher def include(): return (lambda container, item: item in container, "%r does %sinclude %r") @matcher def contain(): return (lambda container, item: item in container, "%r does %scontain %r") @matcher def equal_to(): return (lambda x, y: x == y, "%r is %sequal to %r")
def __call__(self, expected): self._expected = expected return self def match(self, actual): self._actual = actual return self._actual is self._expected def message_for_failed_should(self): return "%r was expected to be %r" % (self._actual, self._expected) def message_for_failed_should_not(self): return "%r was not expected to be %r" % (self._actual, self._expected) matcher(Be) class EqualTo(object): name = 'equal_to' def __call__(self, expected, diff=False, case_sensitive=True): self._expected = expected self._make_diff = diff self._case_sensitive = case_sensitive return self def match(self, actual): self._actual = actual self._diff = ''
status, self._actual ) if self._response_data: response = 'Response Data:\n"{0}"'.format(self._response_data) message = '\n'.join([message, response]) return message def message_for_failed_should_not(self): return 'Expected the status code not to be {0}'.format(status) return Checker # Make be_xxx matchers for all the status codes _status_codes = HTTP_STATUS_CODES.keys() for code in _status_codes: matcher(make_status_checker('be', code)) matcher(make_status_checker('abort', code)) matcher(make_status_checker('return', code)) @matcher class RedirectMatcher(object): ''' A matcher to check for redirects ''' name = 'redirect_to' def __call__(self, location): self._expected = 'http://localhost' + location self._status_ok = True return self def match(self, response):
def __call__(self, expected): self._expected = expected return self def match(self, actual): self._actual = actual return self._actual is self._expected def message_for_failed_should(self): return "%r was expected to be %r" % (self._actual, self._expected) def message_for_failed_should_not(self): return "%r was not expected to be %r" % (self._actual, self._expected) matcher(Be) @matcher def include(): return (lambda container, item: item in container, "%r does %sinclude %r") @matcher def contain(): return (lambda container, item: item in container, "%r does %scontain %r") @matcher def equal_to(): return (lambda x, y: x == y, '%r is %sequal to %r')
self._kwargs = kwargs return self def match(self, function): function() self._calls = self._called_dingus.calls('()', *self._args, **self._kwargs) if self._times: return len(self._calls) == self._times else: return len(self._calls) > 0 def message_for_failed_should(self): msg = repr(self._called_dingus) if not self._calls: msg += " has not been called" else: msg += (" was called %d times" % len(self._calls)) if self._args or self._kwargs: msg += " with params %r %r" % (self._args, self._kwargs) if self._times: msg += ", expected %d" % self._times return msg def message_for_failed_should_not(self): return "%s was unexpectedly called" % repr(self._called_dingus) matcher(Call)