Exemplo n.º 1
0
def to_have_an_error_message_of(topic, expected):
    '''Asserts that `topic` has an error message of `expected`.'''
    if utils.text_type(topic) != expected:
        msg = 'Expected topic({0!r}) to be an error with message {1!r}'
        values = utils.text_type(topic), expected
        err = AssertionError(msg.format(*values))
        raise err
Exemplo n.º 2
0
    def __exit__(self, exc_type, exc_val, exc_tb):
        has_exception = exc_type is not None
        is_subclass = has_exception and (exc_type is self.error_class or issubclass(exc_type, self.error_class)) or False

        if has_exception and self.message is not None:
            error_msg = getattr(exc_val, 'message', utils.text_type(exc_val))
            if error_msg != self.message:
                raise AssertionError('Expected "%s.%s" to have a message of "%s", but the actual error was "%s".' % (
                    self.error_class.__module__,
                    self.error_class.__name__,
                    self.message,
                    error_msg
                ))

        if has_exception and not is_subclass:
            raise AssertionError('Expected "%s.%s" not to happen but "%s.%s" happened during execution of with block.' % (
                self.error_class.__module__,
                self.error_class.__name__,
                exc_type.__module__,
                exc_type.__name__
            ))

        if has_exception:
            raise AssertionError('Expected "%s.%s" not to happen but it happened during execution of with block.' % (
                self.error_class.__module__,
                self.error_class.__name__,
            ))
Exemplo n.º 3
0
 def we_get_an_understandable_message(self, topic):
     expected_message = "Expected topic({0!r}) to be an error with message {1!r}".format(
             utils.text_type(ValueError('some bogus error')),
             'some bogus'
             )
     expect(topic).to_have_an_error_message_of(expected_message)