Beispiel #1
0
 def describe_to(self,
                 description: Description) -> None:  # pragma: no cover
     description.append_text("a sequence containing ")
     for matcher in self.matchers[:-1]:
         description.append_description_of(matcher)
         description.append_text(" followed by ")
     description.append_description_of(self.matchers[-1])
Beispiel #2
0
    def describe_to(self, description: Description) -> None:
        if isinstance(self.times, IsAnything):
            description.append_text("call with")
        else:
            description.append_description_of(self.times).append_text(" call(s) with")

        self._optional_description(description)
Beispiel #3
0
    def describe_mismatch(self, item, description: Description) -> None:
        if not 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):
            if self.pattern is not None or self.matcher is not None:
                description.append_text("Correct assertion type raised, but ")
                if self.pattern is not None:
                    description.append_text('the expected pattern ("%s") ' %
                                            self.pattern)
                if self.pattern is not None and self.matcher is not None:
                    description.append_text("and ")
                if self.matcher is not None:
                    description.append_description_of(self.matcher)
                    description.append_text(" ")
                description.append_text(
                    'not found. Exception message was: "%s"' %
                    str(self.actual))
        else:
            description.append_text("%r of type %s was raised instead" %
                                    (self.actual, type(self.actual)))
Beispiel #4
0
    def describe_mismatch(self, item: object,
                          mismatch_description: Description) -> None:
        """
        Describe the mismatch to the passed-in description.

        Args:
            item: the object that was tested.
            mismatch_description: the description that is being built.
        """
        if item is None:
            mismatch_description.append_text("was None")
            return

        if not hasattr(item, self.method_name):
            mismatch_description.append_description_of(item).append_text(
                " did not have a ").append_description_of(
                    self.method_name).append_text(" method")
            return

        mismatch_description.append_text("method ").append_description_of(
            self.method_name).append_text(" called with ").append_text(
                self.get_callargs_str()).append_text(" ")

        self.value_matcher.describe_mismatch(self.get_return_value(item),
                                             mismatch_description)
Beispiel #5
0
 def describe_to(self, description: Description) -> None:
     nested_matcher = isinstance(self.object, Matcher)
     if nested_matcher:
         description.append_text("<")
     description.append_description_of(self.object)
     if nested_matcher:
         description.append_text(">")
Beispiel #6
0
 def describe_mismatch(self, item: Number, mismatch_description: Description) -> None:
     if not isnumeric(item):
         super(IsCloseTo, self).describe_mismatch(item, mismatch_description)
     else:
         actual_delta = self._diff(item)
         mismatch_description.append_description_of(item).append_text(
             " differed by "
         ).append_description_of(actual_delta)
    def describe_to(self, description: Description) -> None:
        text_start = 0
        for match in re.finditer(ARG_PATTERN, self.template):
            description.append_text(self.template[text_start : match.start()])
            arg_index = int(match.group()[1:])
            description.append_description_of(self.values[arg_index])
            text_start = match.end()

        if text_start < len(self.template):
            description.append_text(self.template[text_start:])
Beispiel #8
0
    def describe_mismatch(self, item: object,
                          mismatch_description: Description) -> None:
        if item is None:
            mismatch_description.append_text("was None")
            return

        if not hasattr(item, self.property_name):
            mismatch_description.append_description_of(item).append_text(
                " did not have the ").append_description_of(
                    self.property_name).append_text(" property")
            return

        mismatch_description.append_text("property ").append_description_of(
            self.property_name).append_text(" ")
        value = getattr(item, self.property_name)
        self.value_matcher.describe_mismatch(value, mismatch_description)
Beispiel #9
0
 def describe_keyvalue(self, index: int, value: V, description: Description) -> None:
     """Describes key-value pair at given index."""
     description.append_description_of(index).append_text(": ").append_description_of(value)
 def describe_to(self, description: Description) -> None:
     description.append_description_of(self.original_string).append_text(" ignoring case")
 def describe_to(self, description: Description) -> None:
     """Generates a description of the value."""
     description.append_description_of(self.value)
Beispiel #12
0
 def describe_mismatch(self, item: T,
                       mismatch_description: Description) -> None:
     mismatch_description.append_text("was ")
     if item is not None:
         mismatch_description.append_text(hex(id(item))).append_text(" ")
     mismatch_description.append_description_of(item)
Beispiel #13
0
 def describe_to(self, description: Description):
     description.append_description_of(self.matcher)