MCPcopy Create free account
hub / github.com/apple/coremltools / MockMethod

Class MockMethod

deps/protobuf/python/mox.py:510–749  ·  view source on GitHub ↗

Callable mock method. A MockMethod should act exactly like the method it mocks, accepting parameters and returning a value, or throwing an exception (as specified). When this method is called, it can optionally verify whether the called method (name and signature) matches the expected meth

Source from the content-addressed store, hash-verified

508
509
510class MockMethod(object):
511 """Callable mock method.
512
513 A MockMethod should act exactly like the method it mocks, accepting parameters
514 and returning a value, or throwing an exception (as specified). When this
515 method is called, it can optionally verify whether the called method (name and
516 signature) matches the expected method.
517 """
518
519 def __init__(self, method_name, call_queue, replay_mode):
520 """Construct a new mock method.
521
522 Args:
523 # method_name: the name of the method
524 # call_queue: deque of calls, verify this call against the head, or add
525 # this call to the queue.
526 # replay_mode: False if we are recording, True if we are verifying calls
527 # against the call queue.
528 method_name: str
529 call_queue: list or deque
530 replay_mode: bool
531 """
532
533 self._name = method_name
534 self._call_queue = call_queue
535 if not isinstance(call_queue, deque):
536 self._call_queue = deque(self._call_queue)
537 self._replay_mode = replay_mode
538
539 self._params = None
540 self._named_params = None
541 self._return_value = None
542 self._exception = None
543 self._side_effects = None
544
545 def __call__(self, *params, **named_params):
546 """Log parameters and return the specified return value.
547
548 If the Mock(Anything/Object) associated with this call is in record mode,
549 this MockMethod will be pushed onto the expected call queue. If the mock
550 is in replay mode, this will pop a MockMethod off the top of the queue and
551 verify this call is equal to the expected call.
552
553 Raises:
554 UnexpectedMethodCall if this call is supposed to match an expected method
555 call and it does not.
556 """
557
558 self._params = params
559 self._named_params = named_params
560
561 if not self._replay_mode:
562 self._call_queue.append(self)
563 return self
564
565 expected_method = self._VerifyMethodCall()
566
567 if expected_method._side_effects:

Callers 3

_CreateMockMethodMethod · 0.85
__setitem__Method · 0.85
__getitem__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected