def testPython2Map(self):
    if sys.version_info < (3,):
      msg = map_unittest_pb2.TestMap()
      msg.map_int32_int32[2] = 4
      msg.map_int32_int32[3] = 6
      msg.map_int32_int32[4] = 8
      msg.map_int32_int32[5] = 10
      map_int32 = msg.map_int32_int32
      self.assertEqual(4, len(map_int32))
      msg2 = map_unittest_pb2.TestMap()
      msg2.ParseFromString(msg.SerializeToString())

      def CheckItems(seq, iterator):
        self.assertEqual(next(iterator), seq[0])
        self.assertEqual(list(iterator), seq[1:])

      CheckItems(map_int32.items(), map_int32.iteritems())
      CheckItems(map_int32.keys(), map_int32.iterkeys())
      CheckItems(map_int32.values(), map_int32.itervalues())

      self.assertEqual(6, map_int32.get(3))
      self.assertEqual(None, map_int32.get(999))
      self.assertEqual(6, map_int32.pop(3))
      self.assertEqual(0, map_int32.pop(3))
      self.assertEqual(3, len(map_int32))
      key, value = map_int32.popitem()
      self.assertEqual(2 * key, value)
      self.assertEqual(2, len(map_int32))
      map_int32.clear()
      self.assertEqual(0, len(map_int32))

      with self.assertRaises(KeyError):
        map_int32.popitem()

      self.assertEqual(0, map_int32.setdefault(2))
      self.assertEqual(1, len(map_int32))

      map_int32.update(msg2.map_int32_int32)
      self.assertEqual(4, len(map_int32))

      with self.assertRaises(TypeError):
        map_int32.update(msg2.map_int32_int32,
                         msg2.map_int32_int32)
      with self.assertRaises(TypeError):
        map_int32.update(0)
      with self.assertRaises(TypeError):
        map_int32.update(value=12)