コード例 #1
0
ファイル: test_celldict.py プロジェクト: abhinavthomas/pypy
    def test_same_key_set_twice(self):
        strategy = ModuleDictStrategy(space)
        storage = strategy.get_empty_storage()
        d = W_ModuleDictObject(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
コード例 #2
0
 def moduledict_and_key(self):
     strategy = ModuleDictStrategy(space)
     storage = strategy.get_empty_storage()
     d = W_ModuleDictObject(space, strategy, storage)
     key = "a"
     w_key = self.FakeString(key)
     return d, key, w_key
コード例 #3
0
    def test_devolve(self):
        strategy = ModuleDictStrategy(space)
        storage = strategy.get_empty_storage()
        d = W_ModuleDictObject(space, strategy, storage)

        key = "a"
        w_key = self.FakeString(key)
        d.setitem(w_key, 1)
        c = d.get_global_cache(key)
        assert c.getvalue(space) == 1
        assert c.valid

        d.setitem(5, 1)
        assert not c.valid
コード例 #4
0
    def test_same_key_set_twice(self):
        strategy = ModuleDictStrategy(space)
        storage = strategy.get_empty_storage()
        d = W_ModuleDictObject(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
コード例 #5
0
    def test_basic_property_cells(self):
        strategy = ModuleDictStrategy(space)
        storage = strategy.get_empty_storage()
        d = W_ModuleDictObject(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.get_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.get_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.get_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.get_strategy().getdictvalue_no_unwrapping(d, key) is None
コード例 #6
0
 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_ModuleDictObject(cls.space, strategy, storage)
コード例 #7
0
ファイル: test_celldict.py プロジェクト: abhinavthomas/pypy
    def test_basic_property_cells(self):
        strategy = ModuleDictStrategy(space)
        storage = strategy.get_empty_storage()
        d = W_ModuleDictObject(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.get_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.get_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.get_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.get_strategy().getdictvalue_no_unwrapping(d, key) is None
コード例 #8
0
 def setup_method(self, method):
     space = self.space
     strategy = ModuleDictStrategy(space)
     storage = strategy.get_empty_storage()
     self.w_d = W_ModuleDictObject(space, strategy, storage)
コード例 #9
0
    def test_getcache_and_builtins(self):
        space = FakeSpace()
        strategy = ModuleDictStrategy(space)
        storage = strategy.get_empty_storage()
        builtindict = W_ModuleDictObject(space, strategy, storage)
        builtindict.setitem_str("len", 2)
        builtindict.setitem_str("list", 19)

        class FakeModule:
            w_dict = builtindict

        space.builtin = FakeModule()
        storage = strategy.get_empty_storage()
        d = W_ModuleDictObject(space, strategy, storage)

        # just in the builtins
        c = d.get_global_cache("len")
        assert c.cell is None
        assert c.builtincache.cell == 2

        # in both dicts
        d.setitem_str("list", 23)
        c = d.get_global_cache("list")
        assert c.cell == 23
        assert c.builtincache is None

        # not in the builtins but in the normal dict
        d.setitem_str("a", 45)
        c = d.get_global_cache("a")
        assert c.cell == 45
        assert c.builtincache is None

        # not in either dict
        c = d.get_global_cache("b")
        assert c.cell is None
        assert c.builtincache is None