Example #1
0
 def g(x):
     if x:
         d = RWeakValueDictionary(X)
     else:
         d = RWeakValueDictionary(Y)
     d.set("x", X())
     return 41
Example #2
0
 class A(object):
     def __init__(self):
         self.d = RWeakValueDictionary(A)
     def f(self, key):
         a = A()
         self.d.set(key, a)
         return a
Example #3
0
 def f(n):
     x = X()
     if n:
         d = empty
     else:
         d = RWeakValueDictionary(str, X)
         d.set("a", x)
     return d.get("a") is x
Example #4
0
 def f(n):
     x = X()
     if n:
         d = empty
     else:
         d = RWeakValueDictionary(X)
         d.set("a", x)
     return d.get("a") is x
Example #5
0
def test_rpython_prebuilt():
    d = RWeakValueDictionary(X)
    living = [X() for i in range(8)]
    for i in range(8):
        d.set(str(i), living[i])
    #
    def f():
        x = X()
        for i in range(8, 13):
            d.set(str(i), x)
        for i in range(0, 8):
            assert d.get(str(i)) is living[i]
        for i in range(8, 13):
            assert d.get(str(i)) is x
        assert d.get("foobar") is None
    #
    f()
    interpret(f, [])
Example #6
0
 def f():
     d = RWeakValueDictionary(keyclass, X)
     x1, x3 = g(d)
     rgc.collect()
     rgc.collect()
     assert d.get(keys[0]) is x1
     assert d.get(keys[1]) is None
     assert d.get(keys[2]) is x3
     assert d.get(keys[3]) is None
     d.set(keys[0], None)
     assert d.get(keys[0]) is None
     assert d.get(keys[1]) is None
     assert d.get(keys[2]) is x3
     assert d.get(keys[3]) is None
     # resizing should also work
     for i in range(loop):
         d.set(make_key(i), x1)
     for i in range(loop):
         assert d.get(make_key(i)) is x1
     assert d.get(keys[0]) is None
     assert d.get(keys[1]) is None
     assert d.get(keys[2]) is x3
     assert d.get(keys[3]) is None
     # a subclass
     y = Y()
     d.set(keys[3], y)
     assert d.get(keys[3]) is y
     # storing a lot of Nones
     for i in range(loop, loop * 2 - 5):
         d.set(make_key(1000 + i), x1)
     for i in range(loop):
         d.set(make_key(i), None)
     for i in range(loop):
         assert d.get(make_key(i)) is None
     assert d.get(keys[0]) is None
     assert d.get(keys[1]) is None
     assert d.get(keys[2]) is x3
     assert d.get(keys[3]) is y
     for i in range(loop, loop * 2 - 5):
         assert d.get(make_key(1000 + i)) is x1
Example #7
0
 def f():
     d = RWeakValueDictionary(X)
     x1, x3 = g(d)
     rgc.collect(); rgc.collect()
     assert d.get("abc") is x1
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is None
     d.set("abc", None)
     assert d.get("abc") is None
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is None
     # resizing should also work
     for i in range(loop):
         d.set(str(i), x1)
     for i in range(loop):
         assert d.get(str(i)) is x1
     assert d.get("abc") is None
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is None
     # a subclass
     y = Y()
     d.set("hello", y)
     assert d.get("hello") is y
     # storing a lot of Nones
     for i in range(loop, loop*2-5):
         d.set('%dfoobar' % i, x1)
     for i in range(loop):
         d.set(str(i), None)
     for i in range(loop):
         assert d.get(str(i)) is None
     assert d.get("abc") is None
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is y
     for i in range(loop, loop*2-5):
         assert d.get('%dfoobar' % i) is x1
Example #8
0
 def g(x):
     if x:
         d = RWeakValueDictionary(str, X)
     else:
         d = RWeakValueDictionary(str, Y)
     d.set("x", X())