def test_topath_append(): lst = [] topath("[0]", lst, 5) topath("[1]", lst, 6) assert 2 == len(lst) # Concatenate a list of values to the end of existing list. set_path(lst, "[++]", [7, 8, 9]) assert 5 == len(lst) assert 9 == get_path(lst, "[4]") # Add an item set_path(lst, "[+]", 10) assert 6 == len(lst) assert 10 == lst.pop()
def getValue(obj, key) -> str: if isinstance(key, str): v = get_path(obj, key) else: v = key(obj) return str(v)
def topath(path, obj, val): set_path(obj, path, val) assert val == get_path(obj, path)
def frompath(path, obj, val): assert val == get_path(obj, path)
def get_path(self, key): """ Fetch a value from current scope, given a path to the value. """ return get_path(self, key)