def test_where_subset_of(): a = WD({"a": 1, "b": {"child": {"a": 1, "b": 2, "c": 3}}}) b = a.where("child", "subset of", ["a", "b", "c", "d"]) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b" a = WD({"a": 1, "b": {"child": {"a": 1, "b": 2, "c": 3, "d": 4}}}) b = a.where("child", "subset of", ["e", "f", "g"]) assert len(b.keys()) == 0 a = WD({ "a": 1, "b": { "child": { "a": 1, "b": 2, "c": 3 } }, "bb": { "child": { "e": 1, "f": 2, "g": 3 } } }) b = a.where("child", "subset of", ["a", "b", "c", "e", "f"]) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b"
def test_where_does_not_have_all(): a = WD({"a": 1, "b": {"child": {"a": 1, "b": 2, "c": 3}}}) b = a.where("child", "does not have all", ["a", "d"]) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b" a = WD({"a": 1, "b": {"child": {"a": 1, "b": 2, "c": 3, "d": 4}}}) b = a.where("child", "does not have all", ["a", "d"]) assert len(b.keys()) == 0 a = WD({ "a": 1, "b": { "child": { "a": 1, "b": 2, "c": 3 } }, "bb": { "child": { "e": 1, "f": 2, "g": 3 } } }) b = a.where("child", "does not have all", ["a", "c"]) assert len(b.keys()) == 1 assert list(b.keys())[0] == "bb"
def test_where_has_all(): a = WD({"a": 1, "b": {"child": {"a": 1, "b": 2, "c": 3}}}) b = a.where("child", "has all", ["a", "d"]) assert len(b.keys()) == 0 a = WD({ "a": 1, "b": { "child": { "a": 1, "b": 2, "c": 3 } }, "bb": { "child": { "e": 1, "f": 2, "g": 3 } } }) b = a.where("child", "has all", ["a", "c"]) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b"
def test_where_does_not_have(): a = WD({"a": {"child": 1}, "b": {"child": [0, 1, 2]}, "c": {"child": "1"}}) b = a.where("child", "does not have", 1) assert len(b.keys()) == 2 assert len([key for key in b.keys() if key in ["a", "c"]]) == 2 a = WD({ "a": { "child1": "1" }, "b": { "child2": { "g_child": [0] } }, "bb": { "child2": { "g_child": [5] } }, "c": { "child3": [5] }, }) b = a.where("*/g_child", "does not have", 5) assert len(b.keys()) == 1 assert len([key for key in b.keys() if key in ["b"]]) == 1
def test_where_lt(): a = WD({"a": 1, "b": {"child": 1}}) b = a.where("child", "<", 2) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b" a = WD({"a": 1, "b": {"child": 1}}) b = a.where("child", "<", 1) assert len(b.keys()) == 0
def test_where_neq(): a = WD({"a": 1, "b": {"child": 1}}) b = a.where("child", "!=", 1) assert len(b.keys()) == 0 a = WD({"a": 1, "b": {"child": 1}}) b = a.where("child", "!=", 0) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b"
def test_where_has(): a = WD({"a": 1, "b": {"child": [0, 1, 2]}}) b = a.where("child", "has", 1) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b" a = WD({"a": 1, "b": {"child": [0, 1, 2, 5]}, "bb": {"child": [0, 1, 2]}}) b = a.where("child", "has", 5) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b"
def test_where_in(): a = WD({"a": {"child": 1}, "b": {"child": [0, 1, 2]}, "c": {"child": "A"}}) b = a.where("child", "in", ["A", 1]) assert len(b.keys()) == 2 assert len([key for key in b.keys() if key in ["a", "c"]]) == 2 a = WD({"a": {"child": 1}, "b": {"child": [0, 1, 2]}, "c": {"child": "A"}}) b = a.where("child", "in", "A") assert len(b.keys()) == 1 assert len([key for key in b.keys() if key in ["c"]]) == 1
def test_where_eq(): a = WD({ "a": 1, "b": { "child": { "gchild": 1, "a": 1 }, "son": { "gchild": 0 } }, "c": { "child": 1 } }) b = a.where("*/gchild", "==", 1) print(b) assert len(b.keys()) == 1 assert list(b.keys())[0] == "b"