コード例 #1
0
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()
コード例 #2
0
def getValue(obj, key) -> str:
    if isinstance(key, str):
        v = get_path(obj, key)
    else:
        v = key(obj)
    return str(v)
コード例 #3
0
def topath(path, obj, val):
    set_path(obj, path, val)
    assert val == get_path(obj, path)
コード例 #4
0
def frompath(path, obj, val):
    assert val == get_path(obj, path)
コード例 #5
0
ファイル: objdict.py プロジェクト: sifive/scribble
 def get_path(self, key):
     """
     Fetch a value from current scope, given a path to the value.
     """
     return get_path(self, key)