示例#1
0
 def describe_mismatch(self, item: T,
                       mismatch_description: Description) -> None:
     if not os.path.isfile(item):
         mismatch_description.append_text('%s was not a file' % item)
     else:
         mismatch_description.append_text('a file with contents %s' %
                                          read(item))
示例#2
0
 def describe_mismatch(self, call: _Call,
                       mismatch_description: Description) -> None:
     mismatch_description.append_text("got arguments (").append_text(
         ", ".join(
             chain((repr(a) for a in call[1]),
                   (f"{k}={v!r}"
                    for k, v in call[2].items())))).append_text(")")
示例#3
0
文件: matchers.py 项目: ozonru/mbtest
    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)
示例#4
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)
示例#5
0
 def describe_mismatch(self, item: T,
                       mismatch_description: Description) -> None:
     super().describe_mismatch(item, mismatch_description)
     if not os.path.isdir(item):
         mismatch_description.append_text(' which is not a directory')
     else:
         mismatch_description.append_text(' which contains %s' %
                                          ', '.join(os.listdir(item)))
示例#6
0
 def describe_mismatch(self, matcher_under_test: Matcher[Any],
                       description: Description) -> None:
     actual_message = StringDescription()
     if matcher_under_test.matches(self.value_not_to_match, actual_message):
         description.append_text("matched")
         return
     description.append_text("got message ").append_description_of(
         actual_message)
     self.append_diff(actual_message, description)
示例#7
0
 def describe_to(self, description: Description) -> None:
     description.append_text("email with")
     append_matcher_description(self.to_name, "to_name", description)
     append_matcher_description(self.to_address, "to_address", description)
     append_matcher_description(self.from_name, "from_name", description)
     append_matcher_description(self.from_address, "from_address",
                                description)
     append_matcher_description(self.subject, "subject", description)
     append_matcher_description(self.body_text, "body_text", description)
示例#8
0
def describe_field_match(
    field_matcher: Matcher[Any],
    field_name: str,
    actual_value: Any,
    match_description: Description,
) -> None:
    if not isinstance(field_matcher, IsAnything) and field_matcher.matches(actual_value):
        match_description.append_text(f" {field_name}: ")
        field_matcher.describe_match(actual_value, match_description)
示例#9
0
 def describe_mismatch(self, json_string: str,
                       description: Description) -> None:
     try:
         loads = json.loads(json_string)
     except ValueError:
         description.append_text("Got invalid JSON ").append_description_of(
             json_string)
     else:
         self.matcher.describe_mismatch(loads, description)
示例#10
0
 def describe_match(self, item: Mapping[K, V],
                    match_description: Description) -> None:
     key_matches = self._matching_keys(item)
     if len(key_matches) == 1:
         key, value = key_matches.popitem()
         match_description.append_text("value for ").append_description_of(
             key).append_text(" ")
         self.value_matcher.describe_mismatch(value, match_description)
     else:
         super().describe_match(item, match_description)
示例#11
0
 def describe_mismatch(self, conn: Connection,
                       mismatch_description: Description) -> None:
     try:
         rows = self._get_rows(conn, self.select)
         self.row_matcher.describe_mismatch(rows, mismatch_description)
     except Exception as e:  # noqa: B902
         mismatch_description.append_text(
             "SQL statement ").append_description_of(
                 self.select).append_text(" gives ").append_description_of(
                     type(e).__name__).append_text(
                         " ").append_description_of(e)
示例#12
0
 def describe_mismatch(self, actual_call: _Call,
                       mismatch_description: Description) -> None:
     args = actual_call[2]
     if self.key in args:
         mismatch_description.append_text(
             "got mock.call with keyword argument ").append_description_of(
                 self.key).append_text(
                     " with value ").append_description_of(args[self.key])
     else:
         mismatch_description.append_text(
             "got mock.call with without keyword argument "
         ).append_description_of(self.key)
示例#13
0
    def describe_to(self, description: Description) -> None:
        """
        Describe this matcher to the passed in description.

        Args:
            description: the description that is being built.
        """
        description.append_text("an object with a method '").append_text(
            self.method_name).append_text(
                "' whose return value when called with ").append_text(
                    self.get_callargs_str()).append_text(
                        " matches ").append_description_of(self.value_matcher)
示例#14
0
 def describe_mismatch(self, actual_call: _Call,
                       mismatch_description: Description) -> None:
     args = actual_call[1]
     if len(args) > self.index:
         mismatch_description.append_text(
             "got mock.call with argument index ").append_description_of(
                 self.index).append_text(
                     " with value ").append_description_of(args[self.index])
     else:
         mismatch_description.append_text(
             "got mock.call with without argument index "
         ).append_description_of(self.index)
示例#15
0
 def describe_to(self, description: Description) -> None:
     description.append_text("URL with")
     append_matcher_description(self.scheme, "scheme", description)
     append_matcher_description(self.username, "username", description)
     append_matcher_description(self.password, "password", description)
     append_matcher_description(self.host, "host", description)
     append_matcher_description(self.port, "port", description)
     append_matcher_description(self.path, "path", description)
     append_matcher_description(self.path_segments, "path segments",
                                description)
     append_matcher_description(self.query, "query", description)
     append_matcher_description(self.fragment, "fragment", description)
示例#16
0
 def describe_to(self, description: Description) -> None:
     description.append_text("response with")
     append_matcher_description(self.status_code, "status_code",
                                description)
     append_matcher_description(self.body, "body", description)
     append_matcher_description(self.content, "content", description)
     append_matcher_description(self.json, "json", description)
     append_matcher_description(self.headers, "headers", description)
     append_matcher_description(self.cookies, "cookies", description)
     append_matcher_description(self.elapsed, "elapsed", description)
     append_matcher_description(self.history, "history", description)
     append_matcher_description(self.url, "url", description)
     append_matcher_description(self.encoding, "encoding", description)
示例#17
0
 def describe_to(self, description: Description) -> None:
     description.append_text("tag with")
     if self.name != ANYTHING:
         description.append_text(" name matching ").append_description_of(
             self.name)
     if self.string != ANYTHING:
         description.append_text(" string matching ").append_description_of(
             self.string)
     if self.clazz != ANYTHING:
         description.append_text(" class matching ").append_description_of(
             self.clazz)
     if self.attributes != ANYTHING:
         description.append_text(
             " attributes matching ").append_description_of(self.attributes)
示例#18
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])
示例#19
0
 def describe_to(self, description: Description) -> None:
     description.append_text("HTML with tag")
     if self.name:
         description.append_text(" name=").append_description_of(self.name)
     if self.id_:
         description.append_text(" id=").append_description_of(self.id_)
     description.append_text(" matching ").append_description_of(
         self.tag_matcher)
示例#20
0
 def describe_mismatch(self, actual_email: str,
                       mismatch_description: Description) -> None:
     email = self._parse_email(actual_email)
     mismatch_description.append_text("was email with")
     describe_field_mismatch(self.to_name, "to_name", email.to_name,
                             mismatch_description)
     describe_field_mismatch(self.to_address, "to_address",
                             email.to_address, mismatch_description)
     describe_field_mismatch(self.from_name, "from_name", email.from_name,
                             mismatch_description)
     describe_field_mismatch(self.from_address, "from_address",
                             email.from_address, mismatch_description)
     describe_field_mismatch(self.subject, "subject", email.subject,
                             mismatch_description)
     describe_field_mismatch(self.body_text, "body", email.body_text,
                             mismatch_description)
示例#21
0
 def describe_to(self, description: Description) -> None:
     description.append_text(
         f"table with {'header ' if self.header_row else ''}row")
     if self.cells_matcher != ANYTHING:
         description.append_text(" cells matching ")
         self.cells_matcher.describe_to(description)
     if self.row_matcher != ANYTHING:
         description.append_text(" row matching ")
         self.row_matcher.describe_to(description)
     if self.index_matcher != ANYTHING:
         description.append_text(" index matching ")
         self.index_matcher.describe_to(description)
示例#22
0
 def describe_mismatch(self, actual,
                       mismatch_description: Description) -> None:
     mismatch_description.append_text("got HTML with tag")
     if self.name:
         mismatch_description.append_text(" name=").append_description_of(
             self.name)
     if self.id_:
         mismatch_description.append_text(" id=").append_description_of(
             self.id_)
     found = self.findall(actual)
     mismatch_description.append_list(" values [", ", ", "]",
                                      [repr(t) for t in found])
示例#23
0
 def describe_match(self, url: Union[furl, str],
                    match_description: Description) -> None:
     url = furl(url)
     match_description.append_text("was URL with")
     describe_field_match(self.scheme, "scheme", url.scheme,
                          match_description)
     describe_field_match(self.username, "username", url.username,
                          match_description)
     describe_field_match(self.password, "password", url.password,
                          match_description)
     describe_field_match(self.host, "host", url.host, match_description)
     describe_field_match(self.port, "port", url.port, match_description)
     describe_field_match(self.path, "path", url.path, match_description)
     describe_field_match(self.path_segments, "path segments",
                          url.path.segments, match_description)
     describe_field_match(self.query, "query", url.query.params,
                          match_description)
     describe_field_match(self.fragment, "fragment", url.fragment,
                          match_description)
示例#24
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(">")
示例#25
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)
示例#26
0
文件: matchers.py 项目: ozonru/mbtest
 def describe_mismatch(
     self, actual: Union[Imposter, MountebankServer], description: Description
 ) -> None:
     description.append_text("found ").append_description_of(len(self.matching_requests))
     description.append_text(" matching requests: ").append_description_of(
         self.matching_requests
     )
     description.append_text(". All requests: ").append_description_of(self.all_requests)
示例#27
0
 def describe_match(self, response: Response,
                    match_description: Description) -> None:
     match_description.append_text("was response with")
     describe_field_match(self.status_code, "status code",
                          response.status_code, match_description)
     describe_field_match(self.body, "body", response.text,
                          match_description)
     describe_field_match(self.content, "content", response.content,
                          match_description)
     describe_field_match(self.json, "json",
                          self._get_response_json(response),
                          match_description)
     describe_field_match(self.headers, "headers", response.headers,
                          match_description)
     describe_field_match(self.cookies, "cookies", response.cookies,
                          match_description)
     describe_field_match(self.elapsed, "elapsed", response.elapsed,
                          match_description)
     describe_field_match(self.history, "history", response.history,
                          match_description)
     describe_field_match(self.url, "url", response.url, match_description)
     describe_field_match(self.encoding, "encoding", response.encoding,
                          match_description)
示例#28
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, cast(
                type, 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)))
示例#29
0
 def describe_to(self, description: Description) -> None:
     description.append_text("a dictionary containing {")
     first = True
     for key, value in self.value_matchers:
         if not first:
             description.append_text(", ")
         self.describe_keyvalue(key, value, description)
         first = False
     description.append_text("}")
示例#30
0
文件: matchers.py 项目: ozonru/mbtest
    def describe_mismatch(
        self, actual: Union[Imposter, MountebankServer], description: Description
    ) -> None:
        sent_email = self.get_sent_email(actual)
        matching_emails = self.get_matching_emails(sent_email)

        description.append_text("found ").append_description_of(len(matching_emails))
        description.append_text(" matching emails: ").append_description_of(matching_emails)
        description.append_text(". All emails: ").append_description_of(sent_email)