def test_same_key_set_twice(self): strategy = ModuleDictStrategy(space) storage = strategy.get_empty_storage() d = W_DictMultiObject(space, strategy, storage) v1 = strategy.version x = object() d.setitem("a", x) v2 = strategy.version assert v1 is not v2 d.setitem("a", x) v3 = strategy.version assert v2 is v3
def newdict(self, module=False, instance=False, classofinstance=None, from_strdict_shared=None, strdict=False): from pypy.objspace.std.dictmultiobject import W_DictMultiObject return W_DictMultiObject.allocate_and_init_instance( self, module=module, instance=instance, classofinstance=classofinstance, from_strdict_shared=from_strdict_shared, strdict=strdict)
def descr_fromkeys(space, w_type, w_keys, w_fill=None): from pypy.objspace.std.dictmultiobject import W_DictMultiObject if w_fill is None: w_fill = space.w_None if space.is_w(w_type, space.w_dict): w_dict = W_DictMultiObject.allocate_and_init_instance(space, w_type) for w_key in space.listview(w_keys): w_dict.setitem(w_key, w_fill) else: w_dict = space.call_function(w_type) for w_key in space.listview(w_keys): space.setitem(w_dict, w_key, w_fill) return w_dict
def newdict(self, module=False, instance=False, classofinstance=None): return W_DictMultiObject.allocate_and_init_instance( self, module=module, instance=instance, classofinstance=classofinstance)
def newdict(self, module=False, instance=False, kwargs=False, strdict=False): return W_DictMultiObject.allocate_and_init_instance( self, module=module, instance=instance, strdict=strdict, kwargs=kwargs)
def descr__new__(space, w_dicttype, __args__): from pypy.objspace.std.dictmultiobject import W_DictMultiObject w_obj = W_DictMultiObject.allocate_and_init_instance(space, w_dicttype) return w_obj
def test_basic_property_cells(self): strategy = ModuleDictStrategy(space) storage = strategy.get_empty_storage() d = W_DictMultiObject(space, strategy, storage) v1 = strategy.version d.setitem("a", 1) v2 = strategy.version assert v1 is not v2 assert d.getitem("a") == 1 assert d.strategy.getdictvalue_no_unwrapping(d, "a") == 1 d.setitem("a", 2) v3 = strategy.version assert v2 is not v3 assert d.getitem("a") == 2 assert d.strategy.getdictvalue_no_unwrapping(d, "a").w_value == 2 d.setitem("a", 3) v4 = strategy.version assert v3 is v4 assert d.getitem("a") == 3 assert d.strategy.getdictvalue_no_unwrapping(d, "a").w_value == 3 d.delitem("a") v5 = strategy.version assert v5 is not v4 assert d.getitem("a") is None assert d.strategy.getdictvalue_no_unwrapping(d, "a") is None
def newdict(self, module=False, instance=False, classofinstance=None, strdict=False): return W_DictMultiObject.allocate_and_init_instance( self, module=module, instance=instance, classofinstance=classofinstance, strdict=strdict)
def test_basic_property_cells(self): strategy = ModuleDictStrategy(space) storage = strategy.get_empty_storage() d = W_DictMultiObject(space, strategy, storage) v1 = strategy.version key = "a" w_key = self.FakeString(key) d.setitem(w_key, 1) v2 = strategy.version assert v1 is not v2 assert d.getitem(w_key) == 1 assert d.strategy.getdictvalue_no_unwrapping(d, key) == 1 d.setitem(w_key, 2) v3 = strategy.version assert v2 is not v3 assert d.getitem(w_key) == 2 assert d.strategy.getdictvalue_no_unwrapping(d, key).w_value == 2 d.setitem(w_key, 3) v4 = strategy.version assert v3 is v4 assert d.getitem(w_key) == 3 assert d.strategy.getdictvalue_no_unwrapping(d, key).w_value == 3 d.delitem(w_key) v5 = strategy.version assert v5 is not v4 assert d.getitem(w_key) is None assert d.strategy.getdictvalue_no_unwrapping(d, key) is None
def setup_method(self, method): space = self.space strategy = ModuleDictStrategy(space) storage = strategy.get_empty_storage() self.w_d = W_DictMultiObject(space, strategy, storage)
def setup_class(cls): if cls.runappdirect: py.test.skip("__repr__ doesn't work on appdirect") strategy = ModuleDictStrategy(cls.space) storage = strategy.get_empty_storage() cls.w_d = W_DictMultiObject(cls.space, strategy, storage)
def get_impl(self): strategy = self.StrategyClass(self.fakespace) storage = strategy.get_empty_storage() w_dict = self.fakespace.allocate_instance(W_DictMultiObject, None) W_DictMultiObject.__init__(w_dict, self.fakespace, strategy, storage) return w_dict
def newdict(self, module=False, instance=False): return W_DictMultiObject.allocate_and_init_instance(self, module=module, instance=instance)
def test_basic_property(self): strategy = ModuleDictStrategy(space) storage = strategy.get_empty_storage() d = W_DictMultiObject(space, strategy, storage) # replace getcell with getcell from strategy def f(key, makenew): return strategy.getcell(d, key, makenew) d.getcell = f d.setitem("a", 1) assert d.getcell("a", False) is d.getcell("a", False) acell = d.getcell("a", False) d.setitem("b", 2) assert d.getcell("b", False) is d.getcell("b", False) assert d.getcell("c", True) is d.getcell("c", True) assert d.getitem("a") == 1 assert d.getitem("b") == 2 d.delitem("a") py.test.raises(KeyError, d.delitem, "a") assert d.getitem("a") is None assert d.getcell("a", False) is acell assert d.length() == 1 d.clear() assert d.getitem("a") is None assert d.getcell("a", False) is acell assert d.length() == 0
def __init__(w_self, space, w_type): W_DictMultiObject.__init__(w_self, space) w_self.w_type = w_type