def testPluralityCheckableIteratorWith2Exceptions(self):
    """Tests PluralityCheckableIterator with 2 elements that both raise."""

    class IterTest(object):

      def __init__(self):
        self.position = 0

      def __iter__(self):
        return self

      def next(self):
        if self.position < 2:
          self.position += 1
          raise CustomTestException('Test exception %s' % self.position)
        else:
          raise StopIteration()

    pcit = PluralityCheckableIterator(IterTest())
    try:
      pcit.PeekException()
      self.fail('Expected exception 1 from PeekException')
    except CustomTestException, e:
      self.assertIn(e.message, 'Test exception 1')
    try:
      for _ in pcit:
        pass
      self.fail('Expected exception 1 from iterator')
    except CustomTestException, e:
      self.assertIn(e.message, 'Test exception 1')
    try:
      pcit.PeekException()
      self.fail('Expected exception 2 from PeekException')
    except CustomTestException, e:
      self.assertIn(e.message, 'Test exception 2')
    try:
      for _ in pcit:
        pass
      self.fail('Expected exception 2 from iterator')
    except CustomTestException, e:
      self.assertIn(e.message, 'Test exception 2')
    for _ in pcit:
      self.fail('Expected StopIteration')
dataset/ETHPy150Open GoogleCloudPlatform/gsutil/gslib/tests/test_plurality_checkable_iterator.py/PluralityCheckableIteratorTests.testPluralityCheckableIteratorWith2Exceptions/original