def test_popitem(self):
        # dict.popitem()
        for copymode in -1, +1:
            # -1: b has same structure as a
            # +1: b is a.copy()
            for log2size in range(12):
                size = 2**log2size
                a = LazyDict()
                b = LazyDict()
                for i in range(size):
                    a[repr(i)] = i
                    if copymode < 0:
                        b[repr(i)] = i
                if copymode > 0:
                    b = a.copy()
                for i in range(size):
                    ka, va = ta = a.popitem()
                    self.assertEqual(va, int(ka))
                    kb, vb = tb = b.popitem()
                    self.assertEqual(vb, int(kb))
                    self.assertFalse(copymode < 0 and ta != tb)
                self.assertFalse(a)
                self.assertFalse(b)

        d = LazyDict()
        self.assertRaises(KeyError, d.popitem)
 def test_lazy_popitem(self):
     d = LazyDict({1: 1})
     d.set_stub(2, lambda x:x)
     k, v = d.popitem()
     self.assertEqual(k, v)
     k, v = d.popitem()
     self.assertEqual(k, v)
     self.assertEqual(k, 2)
     self.assertEqual(len(d._stubs), 0)
     self.assertRaises(KeyError, d.popitem)