MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / test_subscribe

Function test_subscribe

test/mitmproxy/test_optmanager.py:157–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155
156
157def test_subscribe():
158 o = TO()
159 r = Rec()
160
161 # pytest.raises keeps a reference here that interferes with the cleanup test
162 # further down.
163 try:
164 o.subscribe(r, ["unknown"])
165 except exceptions.OptionsError:
166 pass
167 else:
168 raise AssertionError
169
170 assert len(o._subscriptions) == 0
171
172 o.subscribe(r, ["two"])
173 o.one = 2
174 assert not r.called
175 o.two = 3
176 assert r.called
177
178 assert len(o.changed.receivers) == 1
179 del r
180 o.two = 4
181 assert len(o._subscriptions) == 0
182
183 class binder:
184 def __init__(self):
185 self.o = TO()
186 self.called = False
187 self.o.subscribe(self.bound, ["two"])
188
189 def bound(self, *args, **kwargs):
190 self.called = True
191
192 t = binder()
193 t.o.one = 3
194 assert not t.called
195 t.o.two = 3
196 assert t.called
197
198
199def test_rollback():

Callers

nothing calls this directly

Calls 4

RecClass · 0.85
binderClass · 0.85
subscribeMethod · 0.80
TOClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…