示例#1
0
def l2p0():
    kings = {"bastard": "William", "confessor": "Edward", "terrible": "Ivan"}
    fruits = {
        "apple": "Mmm, delicious",
        "orange": "Pithy indeed",
        "banana": "Not a phone"
    }
    return Environ({"fruits": fruits, "kings": kings})
示例#2
0
文件: sublist.py 项目: basalisk/jt
 def output(self, obj: Environ) -> str:
     """ Outputs the value of the path in the current object """
     if self.path == ():
         return str(obj)
     try:
         possible = obj.lookup(self.path, absolute=self.absolute)
     except (LookupError):
         possible = self.default
     if possible == None:
         raise LookupError
     return str(possible)
示例#3
0
def l1p1():
    first = {"shadow": "Son of Odin", "low-key": "Oh, you know who"}
    second = {"shadow": "You must never go there", "mufasa": "Simba's dad"}
    return Environ(first, parent=Environ(second))
示例#4
0
def test_construct_empty():
    "An empty environment is not None"
    assert Environ(dict()) != None
示例#5
0
def l1p0():
    return Environ({
        "bastard": "William",
        "confessor": "Edward",
        "terrible": "Ivan"
    })
示例#6
0
def test_empty_path():
    "An empty path should return our top level dict"
    e = Environ({"a": 1, "b": 2})
    assert e.lookup(list()) == {"a": 1, "b": 2}
示例#7
0
def test_empty():
    "Empty environment, no parents, shouldn't be able to lookup anything"
    e = Environ(dict())
    with pytest.raises(LookupError) as k:
        e.lookup(("who", "cares"))
    assert "who" in str(k.value)
示例#8
0
def test_construct_empty_with_parent():
    "An environment with an empty dict but a reasonable parent is not None"
    assert Environ(dict(), parent=Environ({
        "one": 1,
        "two": 2,
    })) != None
示例#9
0
def test_construct_nonempty():
    "An environment with a populated dict is not None"
    assert Environ({
        "one": 1,
        "two": 2,
    }) != None