def test_collapse__function_arg(self): a = NestedDict({"k1": {"k2": {"$foo": {"k3": {"k4": "v"}}}}}) def detect_operator(key, *args): return key[0] == "$" b = a.collapse(func=detect_operator) self.assertEqual(b, {("k1", "k2"): {"$foo": {("k3", "k4"): "v"}}})
def test_collapse__function_arg__stop_at_root(self): a = NestedDict({"k1": {"k2": {"$foo": {"k3": {"k4": "v"}}}}}) def detect_operator(key, *args): return key == "k1" b = a.collapse(func=detect_operator) self.assertEqual(b, {"k1": {("k2", "$foo", "k3", "k4"): "v"}})
def test__expand(self): a = NestedDict({"k1": {"k2": {"k3": "v"}}}) b = a._expand(a.collapse()) self.assertEqual(b, a.get())
def test_collapse(self): a = NestedDict({"k1": {"k2": {"k3": "v"}}}) b = a.collapse() self.assertEqual(b, {("k1", "k2", "k3"): "v"})