Example #1
0
def test_int_within_range():
    actual = [{"wtf": 5}, {"wtf1": 6}]
    expected = [{"wtf": 9}, {"wtf1": 4}]
    assert json_compare.are_same(expected,
                                 actual,
                                 rel_tolerance=2,
                                 abs_tolerance=5)[0]
Example #2
0
def test_float_within_range():
    actual = [{"wtf": 15.3}, {"wtf1": 5.5}]
    expected = [{"wtf": 5.5}, {"wtf1": 6.6}]
    assert json_compare.are_same(expected,
                                 actual,
                                 rel_tolerance=3,
                                 abs_tolerance=5)[0]
def test_nested_list_order_inner_val_sensitivity_false():
    a = {
        "failureReason": "Invalid request entity",
        "fieldValidationErrors": [
            {
                "field": "Catalog.catalogOwner",
                "reason": "may not be smelly"
            },
            {
                "field": "Catalog.name",
                "reason": "may not be null"
            }
        ]
    }
    b = {
        "failureReason": "Invalid request entity",
        "fieldValidationErrors": [
            {
                "field": "Catalog.name",
                "reason": "may not be null"
            },
            {
                "field": "Catalog.catalogOwner",
                "reason": "may not be null"
            }
        ]
    }
    assert not json_compare.are_same(a, b, True)[0]
Example #4
0
def test_float_int_compare():
    actual = [{"wtf": 12.3}, {"wtf1": 5}]
    expected = [{"wtf": 5}, {"wtf1": 6.6}]
    assert json_compare.are_same(expected,
                                 actual,
                                 rel_tolerance=3,
                                 abs_tolerance=.6,
                                 compare_ints_floats=True)[0]
Example #5
0
def test_expected_zero_has_range():
    actual = [{"wtf": 1}, {"wtf1": 7}]
    expected = [{"wtf": 0}, {"wtf1": 6}]
    assert json_compare.are_same(expected,
                                 actual,
                                 rel_tolerance=3,
                                 abs_tolerance=.6,
                                 compare_ints_floats=True)[0]
def test_expected_zero_has_range():
    actual = [
        {"wtf": 1},
        {"wtf1": 7}
    ]
    expected = [
        {"wtf": 0},
        {"wtf1": 6}
    ]
    assert json_compare.are_same(expected, actual, rel_tolerance=3, abs_tolerance=.6, compare_ints_floats=True)[0]
def test_list_of_hashes():
    a = [
        {"wtf": "omg"},
        {"wtf1": "omg1"}
    ]
    b = [
        {"wtf": "omg"},
        {"wtf1": "omg1"}
    ]
    assert json_compare.are_same(a, b)[0]
def test_list_of_hashes_ignore_key():
    a = [
        {"wtf1": "omg1"},
        {"wtf2": "omg"}
    ]
    b = [
        {"wtf1": "omg1"},
        {"wtf2": "omg3"}
    ]
    assert json_compare.are_same(a, b, True, ["wtf2"])[0]
def test_list_of_hashes_unordered():
    a = [
        {"wtf1": "omg1"},
        {"wtf": "omg"}
    ]
    b = [
        {"wtf": "omg"},
        {"wtf1": "omg1"}
    ]
    assert json_compare.are_same(a, b, True)[0]
def test_list_of_hashes_unordered_fail():
    a = [
        {"wtf1": "omg1"},
        {"wtf": "omg"}
    ]
    b = [
        {"wtf": "omg"},
        {"wtf1": "omg1"}
    ]
    assert not json_compare.are_same(a, b)[0]
def test_int_outside_range():
    actual = [
        {"wtf": 11},
        {"wtf1": 4}
    ]
    expected = [
        {"wtf": 5},
        {"wtf1": 1}
    ]
    assert not json_compare.are_same(expected, actual, rel_tolerance=.5, abs_tolerance=2)[0]
def test_int_within_range():
    actual = [
        {"wtf": 5},
        {"wtf1": 6}
    ]
    expected = [
        {"wtf": 9},
        {"wtf1": 4}
    ]
    assert json_compare.are_same(expected, actual, rel_tolerance=2, abs_tolerance=5)[0]
def test_float_within_range():
    actual = [
        {"wtf": 15.3},
        {"wtf1": 5.5}
    ]
    expected = [
        {"wtf": 5.5},
        {"wtf1": 6.6}
    ]
    assert json_compare.are_same(expected, actual, rel_tolerance=3, abs_tolerance=5)[0]
def test_float_outside_range():
    actual = [
        {"wtf": 18.3},
        {"wtf1": 0.5}
    ]
    expected = [
        {"wtf": 5.5},
        {"wtf1": 6.6}
    ]
    assert not json_compare.are_same(expected, actual, rel_tolerance=.5, abs_tolerance=5)[0]
def test_float_int_compare():
    actual = [
        {"wtf": 12.3},
        {"wtf1": 5}
    ]
    expected = [
        {"wtf": 5},
        {"wtf1": 6.6}
    ]
    assert json_compare.are_same(expected, actual, rel_tolerance=3, abs_tolerance=.6, compare_ints_floats=True)[0]
def test_list_vs_hash_fail():
    a = [
        {"wtf1": "omg1"}
    ]
    b = {
        "wtf": [
            {"wtf1": "omg1"},
            {"wtf": "omg"}
        ]
    }
    assert not json_compare.are_same(a, b)[0]
def test_hash_vs_list_size_fail():
    a = {
        "wtf": [
            {"wtf1": "omg1"},
            {"wtf": "omg"}
        ]
    }
    b = [
        {"wtf": "omg"},
        {"wtf1": "omg1"}
    ]
    assert not json_compare.are_same(a, b)[0]
Example #18
0
def test_infinity_is_same():
    actual = {
        "counts": [float("inf"), 1, 112, 57],
        "name": "Political Animals",
        "url": ""
    }
    expected = {
        "counts": [float("inf"), 0, 118, 53],
        "name": "Political Animals",
        "url": ""
    }
    assert json_compare.are_same(expected,
                                 actual,
                                 rel_tolerance=2,
                                 abs_tolerance=2)
Example #19
0
def test_inner_val_sensitivity_false():
    a = {
        "failureReason":
        "Invalid request entity",
        "fieldValidationErrors": [{
            "field": "Catalog.catalogOwner",
            "reason": "may not be smelly"
        }, {
            "field": "Catalog.name",
            "reason": "may not be null"
        }]
    }
    b = {
        "failureReason":
        "Invalid request entity",
        "fieldValidationErrors": [{
            "field": "Catalog.catalogOwner",
            "reason": "may not be null"
        }, {
            "field": "Catalog.name",
            "reason": "may not be null"
        }]
    }
    assert not json_compare.are_same(a, b, True)[0]
Example #20
0
def test_nested_list_order_sensitivity():
    a = {
        "failureReason":
        "Invalid request entity",
        "fieldValidationErrors": [{
            "field": "Catalog.catalogOwner",
            "reason": "may not be null"
        }, {
            "field": "Catalog.name",
            "reason": "may not be null"
        }]
    }
    b = {
        "failureReason":
        "Invalid request entity",
        "fieldValidationErrors": [{
            "field": "Catalog.name",
            "reason": "may not be null"
        }, {
            "field": "Catalog.catalogOwner",
            "reason": "may not be null"
        }]
    }
    assert json_compare.are_same(a, b, True)[0]
def test_infinity_is_same():
    actual = {"counts": [float("inf"), 1, 112, 57], "name": "Political Animals", "url": ""}
    expected = {"counts": [float("inf"), 0, 118, 53], "name": "Political Animals", "url": ""}
    assert json_compare.are_same(expected, actual, rel_tolerance=2, abs_tolerance=2)
Example #22
0
#!/usr/bin/env python

import json_compare

a = {
    "failureReason":
    "Invalid request entity",
    "fieldValidationErrors": [{
        "field": "normal value 1",
        "reason": "may not be smelly"
    }, {
        "field": "Catalog.name",
        "reason": "may not be null"
    }]
}
b = {
    "failureReason":
    "Invalid request entity",
    "fieldValidationErrors": [{
        "field": "crazy value 2",
        "reason": "may not be null"
    }, {
        "field": "Catalog.catalogOwner",
        "reason": "may not be null"
    }]
}
print(json_compare.are_same(a, b)[1])
Example #23
0
def test_int_outside_range():
    actual = [{"wtf": 11}, {"wtf1": 4}]
    expected = [{"wtf": 5}, {"wtf1": 1}]
    assert not json_compare.are_same(
        expected, actual, rel_tolerance=.5, abs_tolerance=2)[0]
Example #24
0
def test_list_of_hashes_ignore_key():
    a = [{"wtf1": "omg1"}, {"wtf2": "omg"}]
    b = [{"wtf1": "omg1"}, {"wtf2": "omg3"}]
    assert json_compare.are_same(a, b, True, ["wtf2"])[0]
Example #25
0
def test_hash_list_of_hashes_unordered_fail():
    a = {"wtf": [{"wtf1": "omg1"}, {"wtf": "omg"}]}
    b = {"wtf": [{"wtf": "omg"}, {"wtf1": "omg1"}]}
    assert not json_compare.are_same(a, b)[0]
Example #26
0
def test_float_outside_range():
    actual = [{"wtf": 18.3}, {"wtf1": 0.5}]
    expected = [{"wtf": 5.5}, {"wtf1": 6.6}]
    assert not json_compare.are_same(
        expected, actual, rel_tolerance=.5, abs_tolerance=5)[0]
Example #27
0
def test_list_of_hashes():
    a = [{"wtf": "omg"}, {"wtf1": "omg1"}]
    b = [{"wtf": "omg"}, {"wtf1": "omg1"}]
    assert json_compare.are_same(a, b)[0]
Example #28
0
def test_list_vs_hash_fail():
    a = [{"wtf1": "omg1"}]
    b = {"wtf": [{"wtf1": "omg1"}, {"wtf": "omg"}]}
    assert not json_compare.are_same(a, b)[0]
Example #29
0
def test_hash_vs_list_size_fail():
    a = {"wtf": [{"wtf1": "omg1"}, {"wtf": "omg"}]}
    b = [{"wtf": "omg"}, {"wtf1": "omg1"}]
    assert not json_compare.are_same(a, b)[0]
Example #30
0
def test_list_of_hashes_unordered():
    a = [{"wtf1": "omg1"}, {"wtf": "omg"}]
    b = [{"wtf": "omg"}, {"wtf1": "omg1"}]
    assert json_compare.are_same(a, b, True)[0]
Example #31
0
import json_compare

a = {
    "failureReason" : "Invalid request entity",
    "fieldValidationErrors" : [
        {
            "field" : "normal value 1",
            "reason" : "may not be smelly"
        },
        {
            "field" : "Catalog.name",
            "reason" : "may not be null"
        }
    ]
}
b = {
    "failureReason" : "Invalid request entity",
    "fieldValidationErrors" : [
        {
            "field" : "crazy value 2",
            "reason" : "may not be null"
        },
        {
            "field" : "Catalog.catalogOwner",
            "reason" : "may not be null"
        }
    ]
}
print(json_compare.are_same(a, b)[1])