Public Member Functions | Private Attributes | List of all members
mox.MockObject Class Reference
Inheritance diagram for mox.MockObject:
Inheritance graph
[legend]

Public Member Functions

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

Private Attributes

 _class_to_mock
 
 _expected_calls_queue
 
 _known_methods
 
 _known_vars
 
 _replay_mode
 

Detailed Description

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

Definition at line 359 of file bloaty/third_party/protobuf/python/mox.py.

Constructor & Destructor Documentation

◆ __init__() [1/2]

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

Definition at line 362 of file bloaty/third_party/protobuf/python/mox.py.

◆ __init__() [2/2]

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

Definition at line 362 of file protobuf/python/mox.py.

Member Function Documentation

◆ __call__() [1/2]

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

Definition at line 490 of file bloaty/third_party/protobuf/python/mox.py.

◆ __call__() [2/2]

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

Definition at line 490 of file protobuf/python/mox.py.

◆ __class__() [1/2]

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

Definition at line 504 of file bloaty/third_party/protobuf/python/mox.py.

◆ __class__() [2/2]

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

Definition at line 504 of file protobuf/python/mox.py.

◆ __eq__() [1/2]

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

Reimplemented from mox.MockAnything.

Definition at line 419 of file protobuf/python/mox.py.

◆ __eq__() [2/2]

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

Reimplemented from mox.MockAnything.

Definition at line 419 of file bloaty/third_party/protobuf/python/mox.py.

◆ __getattr__() [1/2]

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.

Reimplemented from mox.MockAnything.

Definition at line 386 of file protobuf/python/mox.py.

◆ __getattr__() [2/2]

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.

Reimplemented from mox.MockAnything.

Definition at line 386 of file bloaty/third_party/protobuf/python/mox.py.

◆ __getitem__() [1/2]

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__.

Definition at line 459 of file bloaty/third_party/protobuf/python/mox.py.

◆ __getitem__() [2/2]

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__.

Definition at line 459 of file protobuf/python/mox.py.

◆ __setitem__() [1/2]

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__.

Definition at line 427 of file bloaty/third_party/protobuf/python/mox.py.

◆ __setitem__() [2/2]

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__.

Definition at line 427 of file protobuf/python/mox.py.

Member Data Documentation

◆ _class_to_mock

mox.MockObject._class_to_mock
private

Definition at line 379 of file bloaty/third_party/protobuf/python/mox.py.

◆ _expected_calls_queue

mox.MockObject._expected_calls_queue
private

Definition at line 425 of file bloaty/third_party/protobuf/python/mox.py.

◆ _known_methods

mox.MockObject._known_methods
private

Definition at line 377 of file bloaty/third_party/protobuf/python/mox.py.

◆ _known_vars

mox.MockObject._known_vars
private

Definition at line 378 of file bloaty/third_party/protobuf/python/mox.py.

◆ _replay_mode

mox.MockObject._replay_mode
private

Definition at line 424 of file bloaty/third_party/protobuf/python/mox.py.


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


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:41