How to use the flexmock.FlexmockError function in flexmock

To help you get started, we’ve selected a few flexmock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github has207 / flexmock / flexmock.py View on Github external
def should_receive(self, name):
    """Replaces the specified attribute with a fake.

    Args:
      - name: string name of the attribute to replace

    Returns:
      - Expectation object which can be used to modify the expectations
        on the fake attribute
    """
    if name in UPDATED_ATTRS:
      raise FlexmockError('unable to replace flexmock methods')
    chained_methods = None
    obj = _getattr(self, '_object')
    if '.' in name:
      name, chained_methods = name.split('.', 1)
    name = _update_name_if_private(obj, name)
    _ensure_object_has_named_attribute(obj, name)
    if chained_methods:
      if (not isinstance(obj, Mock) and
          not hasattr(getattr(obj, name), '__call__')):
        return_value = _create_partial_mock(getattr(obj, name))
      else:
        return_value = Mock()
      self._create_expectation(obj, name, return_value)
      return return_value.should_receive(chained_methods)
    else:
      return self._create_expectation(obj, name)
github has207 / flexmock / flexmock.py View on Github external
def should_receive(self, method):
    """Adds a method Expectation to the provided class or instance.

    Args:
      - method: string name of the method to add

    Returns:
      - Expectation object
    """
    if method in Mock.UPDATED_ATTRS:
      raise FlexmockError('unable to replace flexmock methods')
    chained_methods = None
    return_value = None
    if '.' in method:
      method, chained_methods = method.split('.', 1)
    if (method.startswith('__') and
        (not inspect.isclass(self._object) and
        not inspect.ismodule(self._object))):
      method = ('_%s__%s' % (self._object.__class__.__name__,
                             method.lstrip('_')))
    if (not isinstance(self._object, Mock) and
        not hasattr(self._object, method)):
      raise MethodDoesNotExist('%s does not have method %s' %
                               (self._object, method))
    if chained_methods:
      return_value = Mock()
      chained_expectation = return_value.should_receive(chained_methods)
github has207 / flexmock / flexmock.py View on Github external
pass


class MethodSignatureError(FlexmockError):
  pass


class ExceptionClassError(FlexmockError):
  pass


class ExceptionMessageError(FlexmockError):
  pass


class StateError(FlexmockError):
  pass


class MethodCallError(FlexmockError):
  pass


class CallOrderError(FlexmockError):
  pass


class ReturnValue(object):
  def __init__(self, value=None, raises=None):
    self.value = value
    self.raises = raises
github has207 / flexmock / flexmock.py View on Github external
pass


class InvalidExceptionClass(FlexmockError):
  pass


class InvalidExceptionMessage(FlexmockError):
  pass


class MethodNotCalled(FlexmockError):
  pass


class MethodCalledOutOfOrder(FlexmockError):
  pass


class MethodDoesNotExist(FlexmockError):
  pass


class AlreadyMocked(FlexmockError):
  pass


class ReturnValue(object):
  def __init__(self, value=None, raises=None):
    self.value = value
    self.raises = raises
github has207 / flexmock / flexmock.py View on Github external
return out


class InvalidMethodSignature(FlexmockError):
  pass


class InvalidExceptionClass(FlexmockError):
  pass


class InvalidExceptionMessage(FlexmockError):
  pass


class MethodNotCalled(FlexmockError):
  pass


class MethodCalledOutOfOrder(FlexmockError):
  pass


class MethodDoesNotExist(FlexmockError):
  pass


class AlreadyMocked(FlexmockError):
  pass


class ReturnValue(object):
github has207 / flexmock / flexmock.py View on Github external
def _ensure_object_has_named_attribute(obj, name):
  if not isinstance(obj, Mock) and not _hasattr(obj, name):
    exc_msg = '%s does not have attribute %s' % (obj, name)
    if name == '__new__':
       exc_msg = 'old-style classes do not have a __new__() method'
    raise FlexmockError(exc_msg)
github has207 / flexmock / flexmock.py View on Github external
pass


class MockBuiltinError(Exception):
  pass


class MethodSignatureError(FlexmockError):
  pass


class ExceptionClassError(FlexmockError):
  pass


class ExceptionMessageError(FlexmockError):
  pass


class StateError(FlexmockError):
  pass


class MethodCallError(FlexmockError):
  pass


class CallOrderError(FlexmockError):
  pass


class ReturnValue(object):