Esempio n. 1
0
    def describe_mismatch(self, item, description):
        if not is_callable(item):
            description.append_text('%s is not callable' % item)
            return

        function = None if self.function is None else self.function()
        if function is None or function is not item:
            self.function = ref(item)
            if not self._call_function(item):
                return

        if self.actual is None:
            description.append_text('No exception raised.')
        elif isinstance(self.actual, self.expected) and self.pattern is not None:
            description.append_text('Correct assertion type raised, but the expected pattern ("%s") not found.' % self.pattern)
            description.append_text('\n          message was: "%s"' % str(self.actual))
        else:
            description.append_text('%r of type %s was raised instead' % (self.actual, type(self.actual)))
Esempio n. 2
0
    def describe_mismatch(self, item, description):
        if not is_callable(item):
            description.append_text('%s is not callable' % item)
            return

        function = None if self.function is None else self.function()
        if function is None or function is not item:
            self.function = ref(item)
            if not self._call_function(item):
                return

        if self.actual is None:
            description.append_text('No exception raised.')
        elif isinstance(self.actual, self.expected) and self.pattern is not None:
            description.append_text('Correct assertion type raised, but the expected pattern ("%s") not found.' % self.pattern)
            description.append_text('\n          message was: "%s"' % str(self.actual))
        else:
            description.append_text('%s was raised instead' % type(self.actual))
Esempio n. 3
0
    def describe_mismatch(self, item, description):
        if not is_callable(item):
            description.append_text('%s is not callable' % item)
            return

        function = None if self.function is None else self.function()
        if function is None or function is not item:
            self.function = ref(item)
            if not self._call_function(item):
                return

        if self.actual is None:
            description.append_text('No exception raised.')
        elif isinstance(self.actual, self.expected) and self.matcher is not None:
            description.append_text('Exception did not match ')
            description.append_description_of(self.matcher) \
                       .append_text(' because ')
            self.matcher.describe_mismatch(self.actual, description)
        else:
            description.append_text('%s was raised instead: %s' % (type(self.actual), six.text_type(self.actual)))
Esempio n. 4
0
    def _matches(self, function):
        if not is_callable(function):
            return False

        self.function = ref(function)
        return self._call_function(function)
Esempio n. 5
0
    def _matches(self, function):
        if not is_callable(function):
            return False

        self.function = ref(function)
        return self._call_function(function)