Example #1
0
def test_weakkeydict_delitem():
    d = WeakKeyIDDictionary()
    o1 = C()
    o2 = C()
    d[o1] = 'something'
    d[o2] = 'something'
    assert len(d) == 2
    del d[o1]
    assert len(d) == 1
    assert list(d.keys()) == [o2]
Example #2
0
def test_weakkeydict_delitem():
    d = WeakKeyIDDictionary()
    o1 = C()
    o2 = C()
    d[o1] = 'something'
    d[o2] = 'something'
    assert len(d) == 2
    del d[o1]
    assert len(d) == 1
    assert list(d.keys()) == [o2]
Example #3
0
def test_weakkeydict_update(in_d={C(): 1, C(): 2, C(): 3}):
    """This exercises d.update(), len(d), d.keys(), in d,  d.get(), d[]."""
    d = WeakKeyIDDictionary()
    d.update(in_d)
    assert len(d) == len(in_d)
    for k in d.keys():
        assert k in in_d, "mysterious new key appeared in weak dict"
        v = in_d.get(k)
        assert v is d[k]
        assert v is d.get(k)
    for k in in_d.keys():
        assert k in d, "original key disappeared in weak dict"
        v = in_d[k]
        assert v is d[k]
        assert v is d.get(k)
Example #4
0
def test_weakkeydict_update(in_d={C(): 1, C(): 2, C(): 3}):
    """This exercises d.update(), len(d), d.keys(), in d,  d.get(), d[]."""
    d = WeakKeyIDDictionary()
    d.update(in_d)
    assert len(d) == len(in_d)
    for k in d.keys():
        assert k in in_d, "mysterious new key appeared in weak dict"
        v = in_d.get(k)
        assert v is d[k]
        assert v is d.get(k)
    for k in in_d.keys():
        assert k in d, "original key disappeared in weak dict"
        v = in_d[k]
        assert v is d[k]
        assert v is d.get(k)