Lines Matching refs:self
29 def get_behaviors(self): argument
48 def __init__(self, reply_stage_factory): argument
49 self._reply_stage_factory = reply_stage_factory
50 self._instances = []
51 self._invoked_obj = []
52 self._invoked_condition = Condition()
53 self.set_default_to_crash()
55 def begin(self, matcher): argument
56 return PersistenceStage(self, matcher, self._reply_stage_factory)
58 def append(self, behavior_instance): argument
59 self._instances.append(behavior_instance)
61 def set_default(self, fn): argument
63 self._default_fn = fn
65 def set_default_to_crash(self): argument
66 self._default_fn = None
68 def set_default_to_ignore(self): argument
69 self._default_fn = IGNORE_UNHANDLED
71 def run(self, obj): argument
72 for instance in self._instances:
74 self.__obj_invoked(obj)
76 if self._default_fn is not None:
78 self._default_fn(obj)
79 self.__obj_invoked(obj)
82 … "%s: behavior for %s went unhandled" % (self._reply_stage_factory().__class__.__name__, obj),
85 def __obj_invoked(self, obj): argument
86 self._invoked_condition.acquire()
87 self._invoked_obj.append(obj)
88 self._invoked_condition.notify()
89 self._invoked_condition.release()
91 def wait_until_invoked(self, matcher, times, timeout): argument
96 invoked_times = sum((matcher(i) for i in self._invoked_obj))
97 self._invoked_condition.acquire()
98 self._invoked_condition.wait(remaining.total_seconds())
99 self._invoked_condition.release()
105 def __init__(self, behavior, matcher, reply_stage_factory): argument
106 self._behavior = behavior
107 self._matcher = matcher
108 self._reply_stage_factory = reply_stage_factory
110 def then(self, times=1): argument
111 reply_stage = self._reply_stage_factory()
112 reply_stage.init(self._behavior, self._matcher, times)
115 def always(self): argument
116 return self.then(times=-1)
121 def init(self, behavior, matcher, persistence): argument
122 self._behavior = behavior
123 self._matcher = matcher
124 self._persistence = persistence
126 def _commit(self, fn): argument
127 self._behavior.append(BehaviorInstance(self._matcher, self._persistence, fn))
132 def __init__(self, matcher, persistence, fn): argument
133 self._matcher = matcher
134 self._persistence = persistence
135 self._fn = fn
136 self._called_count = 0
138 def try_run(self, obj): argument
139 if not self._matcher(obj):
141 if self._persistence >= 0:
142 if self._called_count >= self._persistence:
144 self._called_count += 1
145 self._fn(obj)
151 def __init__(self, behavior, matcher, timeout): argument
152 self._behavior = behavior
153 self._matcher = matcher
154 self._timeout = timeout
156 def times(self, times=1): argument
157 return self._behavior.wait_until_invoked(self._matcher, times, self._timeout)
162 def __init__(self, behaviors, timeout): argument
163 self._behaviors = behaviors
164 self._timeout = timeout
166 def __getattr__(self, item): argument
167 behavior = getattr(self._behaviors, item + "_behavior")
168 t = self._timeout