Exemplo n.º 1
0
    def test_popitem(self):
        if sys_tools.is_pypy:
            raise nose.SkipTest("Pypy doesn't maintain dict order.")
        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 = CuteSleekValueDict(null_callback)
                b = CuteSleekValueDict(null_callback)
                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))
                    if copymode < 0:
                        self.assertEqual(ta, tb)
                self.assertFalse(a)
                self.assertFalse(b)

        d = CuteSleekValueDict(null_callback)
        self.assertRaises(KeyError, d.popitem)
    def test_popitem(self):
        if sys_tools.is_pypy:
            raise nose.SkipTest("Pypy doesn't maintain dict order.")
        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 = CuteSleekValueDict(null_callback)
                b = CuteSleekValueDict(null_callback)
                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))
                    if copymode < 0:
                        self.assertEqual(ta, tb)
                self.assertFalse(a)
                self.assertFalse(b)

        d = CuteSleekValueDict(null_callback)
        self.assertRaises(KeyError, d.popitem)
 def test_copy(self):
     d = CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
     self.assertEqual(
         d.copy(),
         CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
     )
     self.assertEqual(
         CuteSleekValueDict(null_callback).copy(),
         CuteSleekValueDict(null_callback)
     )
     self.assertRaises(TypeError, d.copy, None)
 def test_copy(self):
     d = CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
     self.assertEqual(
         d.copy(),
         CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
     )
     self.assertEqual(
         CuteSleekValueDict(null_callback).copy(),
         CuteSleekValueDict(null_callback)
     )
     self.assertRaises(TypeError, d.copy, None)