def StubOutWithMock(self, obj, attr_name, use_mock_anything=False):
    """Replace a method, attribute, etc. with a Mock.

    This will replace a class or module with a MockObject, and everything else
    (method, function, etc) with a MockAnything.  This can be overridden to
    always use a MockAnything by setting use_mock_anything to True.

    Args:
      obj: A Python object (class, module, instance, callable).
      attr_name: str.  The name of the attribute to replace with a mock.
      use_mock_anything: bool. True if a MockAnything should be used regardless
        of the type of attribute.
    """

    attr_to_replace = getattr(obj, attr_name)
    attr_type = type(attr_to_replace)

    if attr_type == MockAnything or attr_type == MockObject:
      raise TypeError('Cannot mock a MockAnything! Did you remember to '
                      'call UnsetStubs in your previous test?')

    if attr_type in self._USE_MOCK_OBJECT and not use_mock_anything:
      stub = self.CreateMock(attr_to_replace)
    else:
      stub = self.CreateMockAnything(description='Stub for %s' % attr_to_replace)

    self.stubs.Set(obj, attr_name, stub)
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/mox/mox.py/Mox.StubOutWithMock/original