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
def test_merge_negative_case_nested_list(): a = {"a":[['1', '3']]} b = {"a":[['1', '2']]} try: DictExt(a) + DictExt(b) assert False except: pass
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
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
def test_simple(): assert DictExt({ "aa": 3, "a": 1, "b": 2 }) == DictExt({ "b": 2, "a": 1, "aa": 3 })
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}}]}
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
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"}}]}
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"}}]}
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
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'
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}
def test_compare_0_int(): a = {"a": 0} b = {"a": 0} result, _, _ = DictExt(b).issubset(a) assert result
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})
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)
def test_get_pretty_key(): a = DictExt({ "a": { 'b': 2 } }) assert a.a.b == 2
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'}]})
def test_empty_lists(): a = {"a": [[]]} b = {"a": [[]]} result, _, _ = DictExt(b).issubset(a) assert result
def test_compare_int_with_str(): a = {"a":['1', 2]} b = {"a":[1, '2']} result, _, _ = DictExt(b).issubset(a) assert result
def test_simple_part(): a = {"a": "str", "b": 123} b = {"a": "str", "b": 123} assert DictExt(a) >= DictExt(b) assert DictExt(b) <= DictExt(a)
def test_merge_float(): a = {"a": 1.2} b = {"a": 1.3} assert (DictExt(a) + DictExt(b))['a'] == 1.3
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
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'})
def test_with_list(): assert DictExt({"a": [1, 1, 3]}) == DictExt({"a": [3, 1, 1]})
def test_not_equel(): assert DictExt({"a": "1"}) != DictExt({"a": 1})
def test_nested(): assert DictExt({"a": {"a": 1}}) == DictExt({"a": {"a": 1}})
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
def test_compare_None(): a = {"a": None, "b": 0} b = {"a": "", "b": None} result, _, _ = DictExt(b).issubset(a) assert result
def test_merge_diff_types(): a = {"a": False} b = {"a":"True"} assert (DictExt(a) + DictExt(b))['a'] == True
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"]