Beispiel #1
0
 def test_popitem(self):
     BasicTestMappingProtocol.test_popitem(self)
     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 = self._empty_mapping()
             b = self._empty_mapping()
             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 and test_support.check_impl_detail():
                     # popitem() is not guaranteed to be deterministic on
                     # all implementations
                     self.assertEqual(ta, tb)
             self.assertTrue(not a)
             self.assertTrue(not b)
Beispiel #2
0
 def test_popitem(self):
     BasicTestMappingProtocol.test_popitem(self)
     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 = self._empty_mapping()
             b = self._empty_mapping()
             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 and test_support.check_impl_detail():
                     # popitem() is not guaranteed to be deterministic on
                     # all implementations
                     self.assertEqual(ta, tb)
             self.assertTrue(not a)
             self.assertTrue(not b)
Beispiel #3
0
    def test_folding_of_binops_on_constants(self):
        for line, elem in (
            ('a = 2+3+4', '(9)'),                   # chained fold
            ('"@"*4', "('@@@@')"),                  # check string ops
            ('a="abc" + "def"', "('abcdef')"),      # check string ops
            ('a = 3**4', '(81)'),                   # binary power
            ('a = 3*4', '(12)'),                    # binary multiply
            ('a = 13//4', '(3)'),                   # binary floor divide
            ('a = 14%4', '(2)'),                    # binary modulo
            ('a = 2+3', '(5)'),                     # binary add
            ('a = 13-4', '(9)'),                    # binary subtract
            ('a = (12,13)[1]#detail', '(13)'),      # binary subscr
            ('a = 13 << 2', '(52)'),                # binary lshift
            ('a = 13 >> 2', '(3)'),                 # binary rshift
            ('a = 13 & 7', '(5)'),                  # binary and
            ('a = 13 ^ 7', '(10)'),                 # binary xor
            ('a = 13 | 7', '(15)'),                 # binary or
            ):
            if line.endswith('#detail') and not check_impl_detail():
                continue
            asm = dis_single(line)
            self.assert_(elem in asm, asm)
            self.assert_('BINARY_' not in asm)

        # Verify that unfoldables are skipped
        asm = dis_single('a=2+"b"')
        self.assert_('(2)' in asm)
        self.assert_("('b')" in asm)

        # Verify that large sequences do not result from folding
        asm = dis_single('a="x"*1000')
        self.assert_('(1000)' in asm)
Beispiel #4
0
    def test_folding_of_binops_on_constants(self):
        for line, elem in (
            ('a = 2+3+4', '(9)'),  # chained fold
            ('"@"*4', "('@@@@')"),  # check string ops
            ('a="abc" + "def"', "('abcdef')"),  # check string ops
            ('a = 3**4', '(81)'),  # binary power
            ('a = 3*4', '(12)'),  # binary multiply
            ('a = 13//4', '(3)'),  # binary floor divide
            ('a = 14%4', '(2)'),  # binary modulo
            ('a = 2+3', '(5)'),  # binary add
            ('a = 13-4', '(9)'),  # binary subtract
            ('a = (12,13)[1]#detail', '(13)'),  # binary subscr
            ('a = 13 << 2', '(52)'),  # binary lshift
            ('a = 13 >> 2', '(3)'),  # binary rshift
            ('a = 13 & 7', '(5)'),  # binary and
            ('a = 13 ^ 7', '(10)'),  # binary xor
            ('a = 13 | 7', '(15)'),  # binary or
        ):
            if line.endswith('#detail') and not check_impl_detail():
                continue
            asm = dis_single(line)
            self.assert_(elem in asm, asm)
            self.assert_('BINARY_' not in asm)

        # Verify that unfoldables are skipped
        asm = dis_single('a=2+"b"')
        self.assert_('(2)' in asm)
        self.assert_("('b')" in asm)

        # Verify that large sequences do not result from folding
        asm = dis_single('a="x"*1000')
        self.assert_('(1000)' in asm)