def test_set_attr(self): # set data keys obj = Object({"a": 1, "const": 0}, const_attrs={"const"}) obj.a = 1 assert obj.a == 1 obj.b = 1 assert obj.b == 1 # set const keys with pytest.raises(RuntimeError, match="is const"): obj.const = 1 # set .call attribute obj.call = lambda _: "pong" assert obj("ping") == "pong" # set .data attribute obj.data = {} assert obj.a is None with pytest.raises(ValueError, match="must be a dictionary"): obj.data = None # set other attributes with pytest.raises(RuntimeError, match="should not set"): obj.__dict__ = {}
def test_call(self): obj = Object() obj("original_call") obj.call = lambda _: "pong" assert obj("ping") == "pong"