| 155 | |
| 156 | |
| 157 | def 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 | |
| 199 | def test_rollback(): |