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})
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)
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))
def test_construct_empty(): "An empty environment is not None" assert Environ(dict()) != None
def l1p0(): return Environ({ "bastard": "William", "confessor": "Edward", "terrible": "Ivan" })
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}
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)
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
def test_construct_nonempty(): "An environment with a populated dict is not None" assert Environ({ "one": 1, "two": 2, }) != None