How to use the flexmock.MockBuiltinError 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 _attach_flexmock_methods(mock, flexmock_class, obj):
  try:
    for attr in UPDATED_ATTRS:
      if hasattr(obj, attr):
        if (_get_code(getattr(obj, attr)) is not
            _get_code(getattr(flexmock_class, attr))):
          return False
    for attr in UPDATED_ATTRS:
      _setattr(obj, attr, getattr(mock, attr))
  except TypeError:
    raise MockBuiltinError(
        'Python does not allow you to mock builtin objects or modules. '
        'Consider wrapping it in a class you can mock instead')
  except AttributeError:
    raise MockBuiltinError(
        'Python does not allow you to mock instances of builtin objects. '
        'Consider wrapping it in a class you can mock instead')
  return True
github has207 / flexmock / flexmock.py View on Github external
def _attach_flexmock_methods(mock, flexmock_class, obj):
  try:
    for attr in UPDATED_ATTRS:
      if hasattr(obj, attr):
        if (_get_code(getattr(obj, attr)) is not
            _get_code(getattr(flexmock_class, attr))):
          return False
    for attr in UPDATED_ATTRS:
      _setattr(obj, attr, getattr(mock, attr))
  except TypeError:
    raise MockBuiltinError(
        'Python does not allow you to mock builtin objects or modules. '
        'Consider wrapping it in a class you can mock instead')
  except AttributeError:
    raise MockBuiltinError(
        'Python does not allow you to mock instances of builtin objects. '
        'Consider wrapping it in a class you can mock instead')
  return True