def __iter__(self):
    """Provide custom logic for mocking classes that are iterable.

    Returns:
      Expected return value in replay mode.  A MockMethod object for the
      __iter__ method that has already been called if not in replay mode.

    Raises:
      TypeError if the underlying class is not iterable.
      UnexpectedMethodCallError if the object does not expect the call to
        __iter__.

    """
    methods = dir(self._class_to_mock)

    # Verify the class supports iteration.
    if '__iter__' not in methods:
      # If it doesn't have iter method and we are in replay method, then try to
      # iterate using subscripts.
      if '__getitem__' not in methods or not self._replay_mode:
        raise TypeError('not iterable object')
      else:
        results = []
        index = 0
        try:
          while True:
            results.append(self[index])
            index += 1
        except IndexError:
          return iter(results)

    # If we are in replay mode then simply call the mock __iter__ method.
    if self._replay_mode:
      return MockMethod('__iter__', self._expected_calls_queue,
                        self._replay_mode)()


    # Otherwise, create a mock method __iter__.
    return self._CreateMockMethod('__iter__')()
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/mox/mox.py/MockObject.__iter__/original