Lines Matching refs:self

79   def __init__(self, expected_methods):
93 Error.__init__(self)
94 self._expected_methods = expected_methods
96 def __str__(self):
98 for i, m in enumerate(self._expected_methods)])
109 def __init__(self, unexpected_method, expected):
121 Error.__init__(self)
122 self._unexpected_method = unexpected_method
123 self._expected = expected
125 def __str__(self):
127 (self._unexpected_method, self._expected)
133 def __init__(self, unknown_method_name):
142 Error.__init__(self)
143 self._unknown_method_name = unknown_method_name
145 def __str__(self):
147 self._unknown_method_name
158 def __init__(self):
161 self._mock_objects = []
162 self.stubs = stubout.StubOutForTesting()
164 def CreateMock(self, class_to_mock):
176 self._mock_objects.append(new_mock)
179 def CreateMockAnything(self):
186 self._mock_objects.append(new_mock)
189 def ReplayAll(self):
192 for mock_obj in self._mock_objects:
196 def VerifyAll(self):
199 for mock_obj in self._mock_objects:
202 def ResetAll(self):
205 for mock_obj in self._mock_objects:
208 def StubOutWithMock(self, obj, attr_name, use_mock_anything=False):
223 if type(attr_to_replace) in self._USE_MOCK_OBJECT and not use_mock_anything:
224 stub = self.CreateMock(attr_to_replace)
226 stub = self.CreateMockAnything()
228 self.stubs.Set(obj, attr_name, stub)
230 def UnsetStubs(self):
233 self.stubs.UnsetAll()
274 def __init__(self):
276 self._Reset()
278 def __getattr__(self, method_name):
293 return self._CreateMockMethod(method_name)
295 def _CreateMockMethod(self, method_name):
306 return MockMethod(method_name, self._expected_calls_queue,
307 self._replay_mode)
309 def __nonzero__(self):
314 def __eq__(self, rhs):
318 self._replay_mode == rhs._replay_mode and
319 self._expected_calls_queue == rhs._expected_calls_queue)
321 def __ne__(self, rhs):
324 return not self == rhs
326 def _Replay(self):
329 self._replay_mode = True
331 def _Verify(self):
340 if self._expected_calls_queue:
342 if (len(self._expected_calls_queue) == 1 and
343 isinstance(self._expected_calls_queue[0], MultipleTimesGroup) and
344 self._expected_calls_queue[0].IsSatisfied()):
347 raise ExpectedMethodCallsError(self._expected_calls_queue)
349 def _Reset(self):
353 self._expected_calls_queue = deque()
356 self._replay_mode = False
362 def __init__(self, class_to_mock):
374 MockAnything.__dict__['__init__'](self)
377 self._known_methods = set()
378 self._known_vars = set()
379 self._class_to_mock = class_to_mock
382 self._known_methods.add(method)
384 self._known_vars.add(method)
386 def __getattr__(self, name):
411 if name in self._known_vars:
412 return getattr(self._class_to_mock, name)
414 if name in self._known_methods:
415 return self._CreateMockMethod(name)
419 def __eq__(self, rhs):
423 self._class_to_mock == rhs._class_to_mock and
424 self._replay_mode == rhs._replay_mode and
425 self._expected_calls_queue == rhs._expected_calls_queue)
427 def __setitem__(self, key, value):
444 setitem = self._class_to_mock.__dict__.get('__setitem__', None)
451 if self._replay_mode:
452 return MockMethod('__setitem__', self._expected_calls_queue,
453 self._replay_mode)(key, value)
457 return self._CreateMockMethod('__setitem__')(key, value)
459 def __getitem__(self, key):
475 getitem = self._class_to_mock.__dict__.get('__getitem__', None)
482 if self._replay_mode:
483 return MockMethod('__getitem__', self._expected_calls_queue,
484 self._replay_mode)(key)
488 return self._CreateMockMethod('__getitem__')(key)
490 def __call__(self, *params, **named_params):
494 callable = self._class_to_mock.__dict__.get('__call__', None)
500 mock_method = self._CreateMockMethod('__call__')
504 def __class__(self):
507 return self._class_to_mock
519 def __init__(self, method_name, call_queue, replay_mode):
533 self._name = method_name
534 self._call_queue = call_queue
536 self._call_queue = deque(self._call_queue)
537 self._replay_mode = replay_mode
539 self._params = None
540 self._named_params = None
541 self._return_value = None
542 self._exception = None
543 self._side_effects = None
545 def __call__(self, *params, **named_params):
558 self._params = params
559 self._named_params = named_params
561 if not self._replay_mode:
562 self._call_queue.append(self)
563 return self
565 expected_method = self._VerifyMethodCall()
575 def __getattr__(self, name):
581 def _PopNextMethod(self):
584 return self._call_queue.popleft()
586 raise UnexpectedMethodCallError(self, None)
588 def _VerifyMethodCall(self):
600 expected = self._PopNextMethod()
605 expected, method = expected.MethodCalled(self)
610 if expected != self:
611 raise UnexpectedMethodCallError(self, expected)
615 def __str__(self):
617 [repr(p) for p in self._params or []] +
618 ['%s=%r' % x for x in sorted((self._named_params or {}).items())])
619 desc = "%s(%s) -> %r" % (self._name, params, self._return_value)
622 def __eq__(self, rhs):
631 self._name == rhs._name and
632 self._params == rhs._params and
633 self._named_params == rhs._named_params)
635 def __ne__(self, rhs):
643 return not self == rhs
645 def GetPossibleGroup(self):
651 this_method = self._call_queue.pop()
652 assert this_method == self
658 group = self._call_queue[-1]
664 def _CheckAndCreateNewGroup(self, group_name, group_class):
673 group = self.GetPossibleGroup()
677 group.AddMethod(self)
678 return self
682 new_group.AddMethod(self)
683 self._call_queue.append(new_group)
684 return self
686 def InAnyOrder(self, group_name="default"):
700 self
702 return self._CheckAndCreateNewGroup(group_name, UnorderedGroup)
704 def MultipleTimes(self, group_name="default"):
714 self
716 return self._CheckAndCreateNewGroup(group_name, MultipleTimesGroup)
718 def AndReturn(self, return_value):
725 self._return_value = return_value
728 def AndRaise(self, exception):
736 self._exception = exception
738 def WithSideEffects(self, side_effects):
748 self._side_effects = side_effects
749 return self
774 def equals(self, rhs):
783 def __eq__(self, rhs):
784 return self.equals(rhs)
786 def __ne__(self, rhs):
787 return not self.equals(rhs)
798 def __init__(self, class_name):
805 self._class_name = class_name
807 def equals(self, rhs):
819 return isinstance(rhs, self._class_name)
823 return type(rhs) == type(self._class_name)
825 def __repr__(self):
826 return str(self._class_name)
835 def __init__(self, float_value, places=7):
843 self._float_value = float_value
844 self._places = places
846 def equals(self, rhs):
857 return round(rhs-self._float_value, self._places) == 0
862 def __repr__(self):
863 return str(self._float_value)
874 def __init__(self, search_string):
882 self._search_string = search_string
884 def equals(self, rhs):
896 return rhs.find(self._search_string) > -1
900 def __repr__(self):
901 return '<str containing \'%s\'>' % self._search_string
910 def __init__(self, pattern, flags=0):
920 self.regex = re.compile(pattern, flags=flags)
922 def equals(self, rhs):
929 return self.regex.search(rhs) is not None
931 def __repr__(self):
932 s = '<regular expression \'%s\'' % self.regex.pattern
933 if self.regex.flags:
934 s += ', flags=%d' % self.regex.flags
946 def __init__(self, key):
953 self._key = key
955 def equals(self, rhs):
965 return self._key in rhs
967 def __repr__(self):
968 return '<sequence or map containing \'%s\'>' % self._key
978 def __init__(self, key, value):
986 self._key = key
987 self._value = value
989 def equals(self, rhs):
997 return rhs[self._key] == self._value
1001 def __repr__(self):
1002 return '<map containing the entry \'%s: %s\'>' % (self._key, self._value)
1012 def __init__(self, expected_seq):
1019 self._expected_seq = expected_seq
1021 def equals(self, actual_seq):
1032 expected = dict([(element, None) for element in self._expected_seq])
1036 expected = list(self._expected_seq)
1042 def __repr__(self):
1043 return '<sequence with same elements as \'%s\'>' % self._expected_seq
1050 def __init__(self, *args):
1057 self._comparators = args
1059 def equals(self, rhs):
1069 for comparator in self._comparators:
1075 def __repr__(self):
1076 return '<AND %s>' % str(self._comparators)
1083 def __init__(self, *args):
1090 self._comparators = args
1092 def equals(self, rhs):
1102 for comparator in self._comparators:
1108 def __repr__(self):
1109 return '<OR %s>' % str(self._comparators)
1129 def __init__(self, func):
1136 self._func = func
1138 def equals(self, rhs):
1150 return self._func(rhs)
1152 def __repr__(self):
1153 return str(self._func)
1166 def equals(self, unused_rhs):
1178 def __repr__(self):
1185 def __init__(self, group_name):
1186 self._group_name = group_name
1188 def group_name(self):
1189 return self._group_name
1191 def __str__(self):
1192 return '<%s "%s">' % (self.__class__.__name__, self._group_name)
1194 def AddMethod(self, mock_method):
1197 def MethodCalled(self, mock_method):
1200 def IsSatisfied(self):
1210 def __init__(self, group_name):
1211 super(UnorderedGroup, self).__init__(group_name)
1212 self._methods = []
1214 def AddMethod(self, mock_method):
1221 self._methods.append(mock_method)
1223 def MethodCalled(self, mock_method):
1241 for method in self._methods:
1247 self._methods.remove(mock_method)
1250 if not self.IsSatisfied():
1251 mock_method._call_queue.appendleft(self)
1253 return self, method
1255 raise UnexpectedMethodCallError(mock_method, self)
1257 def IsSatisfied(self):
1260 return len(self._methods) == 0
1271 def __init__(self, group_name):
1272 super(MultipleTimesGroup, self).__init__(group_name)
1273 self._methods = set()
1274 self._methods_called = set()
1276 def AddMethod(self, mock_method):
1283 self._methods.add(mock_method)
1285 def MethodCalled(self, mock_method):
1304 for method in self._methods:
1306 self._methods_called.add(mock_method)
1309 mock_method._call_queue.appendleft(self)
1310 return self, method
1312 if self.IsSatisfied():
1316 raise UnexpectedMethodCallError(mock_method, self)
1318 def IsSatisfied(self):
1323 tmp = self._methods.copy()
1324 for called in self._methods_called:
1371 def new_method(self, *args, **kwargs):
1372 mox_obj = getattr(self, 'mox', None)
1377 func(self, *args, **kwargs)
1400 def setUp(self):
1401 self.mox = Mox()