def test_weakkeyiddict_iter_functions(): """Tests iterkeys and iteritems""" in_d = {C(): 1, C(): 2, C(): 3} d = WeakKeyIDDictionary(in_d) keys = list(in_d) for key in d.iterkeys(): assert key in keys, "WeakKeyIDDictionary has extra key %d" % (key, ) keys.remove(key) assert len( keys) == 0, "Keys not found in WeakKeyIDDictionary: %r" % (keys, ) # copy, otherwise `d` will change size during iteration as references are removed in_d2 = dict(in_d) for k, v in d.iteritems(): assert k in in_d assert in_d2.pop(k) == v assert len( in_d2) == 0, "Keys not found in WeakKeyIDDictionary: %r" % (in_d2, )