Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument("first")
    parser.add_argument("second")
    parser.add_argument("-p", "--patch", action="store_true", default=False)
    parser.add_argument("-s",
                        "--syntax",
                        action="store",
                        type=str,
                        default="compact")
    parser.add_argument("-i",
                        "--indent",
                        action="store",
                        type=int,
                        default=None)

    args = parser.parse_args()

    with open(args.first, "r") as f:
        with open(args.second, "r") as g:
            jf = json.load(f)
            jg = json.load(g)
            if args.patch:
                x = jsondiff.patch(jf, jg, marshal=True, syntax=args.syntax)
            else:
                x = jsondiff.diff(jf, jg, marshal=True, syntax=args.syntax)

            json.dump(x, sys.stdout, indent=args.indent)
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument("first")
    parser.add_argument("second")
    parser.add_argument("-p", "--patch", action="store_true", default=False)
    parser.add_argument("-s", "--syntax", action="store", type=str, default="compact")
    parser.add_argument("-i", "--indent", action="store", type=int, default=None)

    args = parser.parse_args()

    with open(args.first, "r") as f:
        with open(args.second, "r") as g:
            jf = json.load(f)
            jg = json.load(g)
            if args.patch:
                x = jsondiff.patch(
                    jf,
                    jg,
                    marshal=True,
                    syntax=args.syntax
                )
            else:
                x = jsondiff.diff(
                    jf,
                    jg,
                    marshal=True,
                    syntax=args.syntax
                )

            json.dump(x, sys.stdout, indent=args.indent)
Esempio n. 3
0
def response_meets_expectation(response, expectation):
    logger.debug("Type of response: {}".format(type(response)))
    union = jsondiff.patch(response, expectation)
    difference = jsondiff.diff(response, union)
    if difference:
        raise JsonCompareError("Diff found: {}".format(difference))
    else:
        return True