示例#1
0
    def matches(self, actual):
        from lemoncheesecake.matching import DISPLAY_DETAILS_WHEN_EQUAL

        if actual == self.expected:
            return match_success(got_value(
                actual)) if DISPLAY_DETAILS_WHEN_EQUAL else match_success()
        else:
            return match_failure(got_value(actual))
示例#2
0
 def matches(self, actual):
     try:
         match = self.expected.search(actual)
     except TypeError:
         return match_failure("Invalid value %s (%s)" %
                              (repr(actual), type(actual)))
     return match_result(match is not None, got_value(actual))
示例#3
0
 def matches(self, actual):
     if type(actual) in self.types:
         if self.value_matcher:
             return self.value_matcher.matches(actual)
         else:
             return match_success(got_value(actual))
     else:
         return match_failure(
             got("%s (%s)" %
                 (serialize_value(actual), get_value_type_name(actual))))
示例#4
0
    def matches(self, actual):
        missing = []
        for expected in self.expected:
            if expected not in actual:
                missing.append(expected)

        if missing:
            return match_failure("Missing values: %s" %
                                 serialize_values(missing))
        else:
            return match_success(got_value(actual))
示例#5
0
    def matches(self, actual):
        try:
            value = self.key_matcher.get_entry(actual)
        except KeyError:
            return match_failure('No entry %s' %
                                 self.key_matcher.description())

        if self.value_matcher:
            return self.value_matcher.matches(value)
        else:
            return match_success(got_value(value))
示例#6
0
    def matches(self, actual):
        expected = list(self.expected)
        extra = []
        for value in actual:
            if value in expected:
                expected.remove(value)
            else:
                extra.append(value)

        if len(expected) == 0 and len(extra) == 0:
            return match_success(got_value(actual))
        else:
            details = []
            if len(expected) > 0:
                details.append("Missing values: %s" %
                               serialize_values(expected))
            if len(extra) > 0:
                details.append("Extra values: %s" % serialize_values(extra))
            return match_failure("; ".join(details))
示例#7
0
 def matches(self, actual):
     return match_result(self.min <= actual <= self.max, got_value(actual))
示例#8
0
 def matches(self, actual):
     return match_result(comparison_func(actual, self.expected),
                         got_value(actual))
示例#9
0
 def matches(self, actual):
     return match_success(got_value(actual))
示例#10
0
 def matches(self, actual):
     return match_result(self.expected in actual, got_value(actual))
示例#11
0
 def matches(self, actual):
     return match_result(actual.endswith(self.expected), got_value(actual))