Exemplo n.º 1
0
def test_compare_None_with_dict():
    a = {"a": "str", "b": {"a": 0}}
    b = {"a": "str", "b": None}
    result, _, _ = DictExt(b).issubset(a)
    assert not result
    result, _, _ = DictExt(a).issubset(b)
    assert not result
Exemplo n.º 2
0
def test_merge_negative_case_nested_list():
    a = {"a":[['1', '3']]}
    b = {"a":[['1', '2']]}
    try:
        DictExt(a) + DictExt(b)
        assert False
    except:
        pass
Exemplo n.º 3
0
def test_merge_negative_case_dict_to_list():
    a = {"a":{'1': '1', '3': '3'}}
    b = {"a":['1', '2']}
    try:
        DictExt(a) + DictExt(b)
        assert False
    except:
        pass
Exemplo n.º 4
0
def test_merge_negative_not_supported_type():
    class NOT_SUPPORTED_TYPE:
        pass
    a = {"a": NOT_SUPPORTED_TYPE()}
    b = {"a": NOT_SUPPORTED_TYPE()}
    try:
        DictExt(a).merge(DictExt(b))
        assert False
    except:
        pass
Exemplo n.º 5
0
def test_simple():
    assert DictExt({
        "aa": 3,
        "a": 1,
        "b": 2
    }) == DictExt({
        "b": 2,
        "a": 1,
        "aa": 3
    })
Exemplo n.º 6
0
def test_not_present_dict_part_2():
    a = {"a": [{"a": {"a": "str", "b": 123}}, {"b": {"b": "str", "c": 123}}]}
    b = {"a": [{"b": {"b": "str", "c": 123}}]}
    result, not_present, changed = DictExt(a).issubset(b)
    assert not result
    assert not changed
    assert not_present == {"a": [{"a": {"a": "str", "b": 123}}]}
Exemplo n.º 7
0
def test_simple_not_present_dict_part():
    a = {"a": {"a": "str", "b": 123}}
    b = {"b": {"b": "str1", "c": 1234}}
    result, not_present, changed = DictExt(b).issubset(a)
    assert not result
    assert not changed
    assert not_present == b
Exemplo n.º 8
0
def test_skip_path_other_order():
    a = {"a":[{'b': '1', 'c': '2'},{'a': '1', 'b': '2'}]}
    b = {"a":[{'a': '1', 'b': '2'},{'b': '10', 'c': '20'}]}
    result, not_present, changed = DictExt(a).issubset(b, skip=['a.b'])
    assert not result
    assert not not_present
    assert changed == {"a":[{'c': {"old": "2", "new": "20"}}]}
Exemplo n.º 9
0
def test_skip_path():
    a = {"a":[{'b': '1', 'c': {'a': '2'}},{'a': '1', 'b': '2'}]}
    b = {"a":[{'b': '10', 'c': {'a': '20'}},{'a': '1', 'b': '2'}]}
    result, not_present, changed = DictExt(a).issubset(b, skip=['a.c.a'])
    assert not result
    assert not not_present
    assert changed == {"a":[{'b': {"old": "1", "new": "10"}}]}
Exemplo n.º 10
0
def test_simple_list_in_dict_part():
    a = {"a": {"a": "str", "b": 123}}
    b = {"a": {"a": "str", "b": 1234}}
    result, not_present, changed = DictExt(b).issubset(a)
    assert not result
    assert changed == {
        "a": {"b": {"old": 1234, "new": 123} }
    }
    assert not not_present
Exemplo n.º 11
0
def test_less_changed_diff():
    a = {"a":[{'a': '1', 'd': '2'},{'a': '21', 'd': '22'}]}
    b = {"a":[{'a': '1', 'd': '20'},{'a': '1', 'd': '2'}]}
    result, not_present, changed = DictExt(b).issubset(a)
    assert not result
    assert not not_present
    assert len(changed['a']) == 1
    assert len(changed['a'][0]) == 1, 'Found more diff than expected'
    assert changed['a'][0]['d']['old'] == '20'
    assert changed['a'][0]['d']['new'] == '2'
Exemplo n.º 12
0
def test_simple_diff_part():
    a = {"a": "str", "b": 321}
    b = {"a": "str1", "b": 123, "c": 12.1}
    result, not_present, changed = DictExt(b).issubset(a)
    assert not result
    assert changed == {
        "a": {"old": "str1", "new": "str"},
        "b": {"old": 123, "new": 321},
    }
    assert not_present == {"c": 12.1}
Exemplo n.º 13
0
def test_compare_0_int():
    a = {"a": 0}
    b = {"a": 0}
    result, _, _ = DictExt(b).issubset(a)
    assert result
Exemplo n.º 14
0
def test_different_order():
    assert DictExt({"a": 1, "b": 2}) == DictExt({"b": 2, "a": 1})
    assert DictExt({"b": 2, "a": 1}) == DictExt({"a": 1, "b": 2})
Exemplo n.º 15
0
def test_full_diff():
    a = {"a":[{'a': '1', 'd': '2'},{'b': '2', 'dd': '20'}]}
    b = {"a":[{'bb': '2', 'cc': '20'},{'aa': '1', 'dd': '2'}]}
    _, not_present, _ = DictExt(b).issubset(a)
    assert not_present == DictExt(b)
Exemplo n.º 16
0
def test_get_pretty_key():
    a = DictExt({ "a": { 'b': 2 } })
    assert a.a.b == 2
Exemplo n.º 17
0
def test_less_not_present_diff():
    a = {"a":[{'a': '1', 'd': '2'},{'b': '2', 'd': '20'}]}
    b = {"a":[{'b': '2', 'c': '20'},{'a': '1', 'd': '2'}]}
    result = DictExt(b) - DictExt(a)
    assert result == DictExt({"a":[{'c': '20'}]})
Exemplo n.º 18
0
def test_empty_lists():
    a = {"a": [[]]}
    b = {"a": [[]]}
    result, _, _ = DictExt(b).issubset(a)
    assert result
Exemplo n.º 19
0
def test_compare_int_with_str():
    a = {"a":['1', 2]}
    b = {"a":[1, '2']}

    result, _, _ = DictExt(b).issubset(a)
    assert result
Exemplo n.º 20
0
def test_simple_part():
    a = {"a": "str", "b": 123}
    b = {"a": "str", "b": 123}
    assert DictExt(a) >= DictExt(b)
    assert DictExt(b) <= DictExt(a)
Exemplo n.º 21
0
def test_merge_float():
    a = {"a": 1.2}
    b = {"a": 1.3}
    assert (DictExt(a) + DictExt(b))['a'] == 1.3
Exemplo n.º 22
0
def test_issubset_regex_mask():
    a = {"a":[{'1': '1', '2': 'Test string to test 215 regex'},{'1': '1', '2': 'bla 2'}]}
    b = {"a":[{'1': '1', '2': 'test \d{3}'}, {'1': '1', '2': '^bl'}]}
    result, _, _ = DictExt(b).issubset(a, regex_mask=True)
    assert result
Exemplo n.º 23
0
def test_merge_simple():
    a = {"a":[{'1': '1', '2': '2'},{'1': '1', '2': '2'}]}
    b = {"a":[{'1': '1', '2': '2'},{'3': '3', '2': '2'}]}
    #assert DictExt(a, b)['a'][0] == {'1': '1', '2': '2', '3': '3'}
    m = DictExt(a) + DictExt(b)
    assert m['a'][1] == DictExt({'1': '1', '2': '2', '3': '3'})
Exemplo n.º 24
0
def test_with_list():
    assert DictExt({"a": [1, 1, 3]}) == DictExt({"a": [3, 1, 1]})
Exemplo n.º 25
0
def test_not_equel():
    assert DictExt({"a": "1"}) != DictExt({"a": 1})
Exemplo n.º 26
0
def test_nested():
    assert DictExt({"a": {"a": 1}}) == DictExt({"a": {"a": 1}})
Exemplo n.º 27
0
def test_issubset_regex_mask_off_swicher():
    a = {"a":[{'1': '1', '2': 'Test string to test 215 regex'}]}
    b = {"a":[{'1': '1', '2': 'test'}]}
    result, _, _ = DictExt(b).issubset(a)
    assert not result
Exemplo n.º 28
0
def test_compare_None():
    a = {"a": None, "b": 0}
    b = {"a": "", "b": None}
    result, _, _ = DictExt(b).issubset(a)
    assert result
Exemplo n.º 29
0
def test_merge_diff_types():
    a = {"a": False}
    b = {"a":"True"}
    assert (DictExt(a) + DictExt(b))['a'] == True
Exemplo n.º 30
0
def test_merge_dict_with_list_with_str():
    a = {"a":['1', '2']}
    b = {"a":['1', '3']}
    assert (DictExt(a) + DictExt(b))['a'] == ["1", "2", "3"]