def test_ContainedProxy_instances_have_no_instance_dictionaries(): """Make sure that proxies do'nt have dictionnaries. """ class C(object): pass c = C() c.x = 1 assert c.__dict__ == {'x': 1} p = ContainedProxy(c) assert p.__dict__ == {} p.y = 3 assert p.__dict__ == {}
def test_basic_proxy_attribute_management_and_picklability(): """Contained-object proxy This is a picklable proxy that can be put around objects that don't implement IContained. """ l = [1, 2, 3] p = ContainedProxy(l) p.__parent__ = 'Dad' p.__name__ = 'p' assert p == [1, 2, 3] assert p.__parent__ == 'Dad' assert p.__name__ == 'p' 'p' with pytest.raises(TypeError): # A proxy is not pickable. pickle.loads(pickle.dumps(p))