Пример #1
0
    def compare(self, ob1, ob2, validator):
        """
        :param ob1:expect result
        :param ob2: acutal result
        :param validator: validator mode
        :return:
        """
        from Compare import CompareMode

        compare = CompareMode.get_compare_mode(validator)
        if validator == "OBJECT":
            ob1 = self.object_in_filter(ob1)
            if self._diff_by:
                result = compare.diff(ob1, ob2, self._diff_by)
            else:
                result = compare.diff(ob1, ob2)
            result.update({result.keys()[0]: filter(self.object_out_filter, result[result.keys()[0]])})
            for k, v in result.items():
                if not v:
                    return "PASS"
                else:
                    return str(result)
        else:
            result = compare.diff(ob1, ob2)
            return "PASS" if not result else str(result)
Пример #2
0
    def compare(self, ob1, ob2, diff_by):
        # inspect the result by  compare

        def type_handler(text):
            for k, v in text.items():
                if isinstance(v, dict):
                    type_handler(v)
                if isinstance(v, str) and v.lower() in ("false", "true"):
                    text.update({k: json.loads(v.lower())})
            return text

        def is_placeholder(kv):
            """
            Takes {k, v} dict, returns True if it's a placeholder.
            """
            for k, v in kv.items():
                return not bool(k == "%s")

        compare = CompareMode.get_compare_mode("OBJECT")
        result = compare.diff(compare.dict_to_object(type_handler(ob1)), compare.dict_to_object(ob2), diff_by)

        # because fitnesse cell in table is not support null collection(dict,list,set,tuple),so use '%s' for placeholder .
        # so,'%s' should be ignore
        result.update({result.keys()[0]: filter(is_placeholder, result[result.keys()[0]])})
        for k, v in result.items():
            if not v:
                return "PASS"
            else:
                return str(result)