def test_set_existing(): keys = ["a", "b", "c"] values = [1, 2, 3] storage = strategy.erase((keys, values)) d = W_DictMultiObject(space, strategy, storage) assert d.getitem_str("a") == 1 assert d.getitem_str("b") == 2 assert d.getitem_str("c") == 3 assert d.setitem_str("a", 4) is None assert d.getitem_str("a") == 4 assert d.getitem_str("b") == 2 assert d.getitem_str("c") == 3 assert d.setitem_str("b", 5) is None assert d.getitem_str("a") == 4 assert d.getitem_str("b") == 5 assert d.getitem_str("c") == 3 assert d.setitem_str("c", 6) is None assert d.getitem_str("a") == 4 assert d.getitem_str("b") == 5 assert d.getitem_str("c") == 6 assert d.getitem(space.wrap("a")) == 4 assert d.getitem(space.wrap("b")) == 5 assert d.getitem(space.wrap("c")) == 6 assert d.w_keys() == keys assert d.values() == values assert keys == ["a", "b", "c"] assert values == [4, 5, 6]
def test_limit_size(): storage = strategy.get_empty_storage() d = W_DictMultiObject(space, strategy, storage) for i in range(100): assert d.setitem_str("d%s" % i, 4) is None assert d.strategy is not strategy assert "BytesDictStrategy" == d.strategy.__class__.__name__
def test_set_new(): keys = ["a", "b", "c"] values = [1, 2, 3] storage = strategy.erase((keys, values)) d = W_DictMultiObject(space, strategy, storage) assert d.getitem_str("a") == 1 assert d.getitem_str("b") == 2 assert d.getitem_str("c") == 3 assert d.getitem_str("d") is None assert d.setitem_str("d", 4) is None assert d.getitem_str("a") == 1 assert d.getitem_str("b") == 2 assert d.getitem_str("c") == 3 assert d.getitem_str("d") == 4 assert d.w_keys() == keys assert d.values() == values assert keys == ["a", "b", "c", "d"] assert values == [1, 2, 3, 4]
def test_from_empty_to_kwargs(): strategy = EmptyKwargsDictStrategy(space) storage = strategy.get_empty_storage() d = W_DictMultiObject(space, strategy, storage) d.setitem_str("a", 3) assert isinstance(d.strategy, KwargsDictStrategy)