webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
Public Member Functions | List of all members
mox.MockObject Class Reference
Inheritance diagram for mox.MockObject:
mox.MockAnything

Public Member Functions

def __init__ (self, class_to_mock)
 
def __getattr__ (self, name)
 
def __eq__ (self, rhs)
 
def __setitem__ (self, key, value)
 
def __getitem__ (self, key)
 
def __call__ (self, params, named_params)
 
def __class__ (self)
 
- Public Member Functions inherited from mox.MockAnything
def __init__ (self)
 
def __getattr__ (self, method_name)
 
def __nonzero__ (self)
 
def __eq__ (self, rhs)
 
def __ne__ (self, rhs)
 

Detailed Description

A mock object that simulates the public/protected interface of a class.

Constructor & Destructor Documentation

◆ __init__()

def mox.MockObject.__init__ (   self,
  class_to_mock 
)
Initialize a mock object.

This determines the methods and properties of the class and stores them.

Args:
  # class_to_mock: class to be mocked
  class_to_mock: class

Member Function Documentation

◆ __call__()

def mox.MockObject.__call__ (   self,
  params,
  named_params 
)
Provide custom logic for mocking classes that are callable.

◆ __class__()

def mox.MockObject.__class__ (   self)
Return the class that is being mocked.

◆ __eq__()

def mox.MockObject.__eq__ (   self,
  rhs 
)
Provide custom logic to compare objects.

◆ __getattr__()

def mox.MockObject.__getattr__ (   self,
  name 
)
Intercept attribute request on this object.

If the attribute is a public class variable, it will be returned and not
recorded as a call.

If the attribute is not a variable, it is handled like a method
call. The method name is checked against the set of mockable
methods, and a new MockMethod is returned that is aware of the
MockObject's state (record or replay).  The call will be recorded
or replayed by the MockMethod's __call__.

Args:
  # name: the name of the attribute being requested.
  name: str

Returns:
  Either a class variable or a new MockMethod that is aware of the state
  of the mock (record or replay).

Raises:
  UnknownMethodCallError if the MockObject does not mock the requested
  method.

◆ __getitem__()

def mox.MockObject.__getitem__ (   self,
  key 
)
Provide custom logic for mocking classes that are subscriptable.

Args:
  key: Key to return the value for.

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

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

◆ __setitem__()

def mox.MockObject.__setitem__ (   self,
  key,
  value 
)
Provide custom logic for mocking classes that support item assignment.

Args:
  key: Key to set the value for.
  value: Value to set.

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

Raises:
  TypeError if the underlying class does not support item assignment.
  UnexpectedMethodCallError if the object does not expect the call to
__setitem__.

The documentation for this class was generated from the following file: