Esempio n. 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))
Esempio n. 2
0
 def matches(self, actual):
     if actual == self.expected:
         return match_success()
     else:
         return match_failure(
             "Text does not match:\n%s" %
             _diff_text(self.expected, actual, self.linesep))
Esempio n. 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))))
Esempio n. 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))
Esempio n. 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))
Esempio n. 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))
Esempio n. 7
0
 def matches(self, actual):
     return match_success(got_value(actual))
Esempio n. 8
0
 def matches(self, actual):
     if actual == self.expected:
         return match_success()
     else:
         return match_failure("JSON does not match:\n%s" % _diff_text(
             _format_json(self.expected), _format_json(actual), "\n"))