| 197 | |
| 198 | |
| 199 | def test_rollback(): |
| 200 | o = TO() |
| 201 | |
| 202 | rec = [] |
| 203 | |
| 204 | def sub(updated): |
| 205 | rec.append(copy.copy(o)) |
| 206 | |
| 207 | recerr = [] |
| 208 | |
| 209 | def errsub(**kwargs): |
| 210 | recerr.append(kwargs) |
| 211 | |
| 212 | def err(updated): |
| 213 | if o.one == 10: |
| 214 | raise exceptions.OptionsError() |
| 215 | if o.bool is True: |
| 216 | raise exceptions.OptionsError() |
| 217 | |
| 218 | o.changed.connect(sub) |
| 219 | o.changed.connect(err) |
| 220 | o.errored.connect(errsub) |
| 221 | |
| 222 | assert o.one is None |
| 223 | with pytest.raises(exceptions.OptionsError): |
| 224 | o.one = 10 |
| 225 | assert o.one is None |
| 226 | with pytest.raises(exceptions.OptionsError): |
| 227 | o.bool = True |
| 228 | assert o.bool is False |
| 229 | assert isinstance(recerr[0]["exc"], exceptions.OptionsError) |
| 230 | assert o.one is None |
| 231 | assert o.bool is False |
| 232 | assert len(rec) == 4 |
| 233 | assert rec[0].one == 10 |
| 234 | assert rec[1].one is None |
| 235 | assert rec[2].bool is True |
| 236 | assert rec[3].bool is False |
| 237 | |
| 238 | with pytest.raises(exceptions.OptionsError): |
| 239 | with o.rollback({"one"}, reraise=True): |
| 240 | raise exceptions.OptionsError() |
| 241 | |
| 242 | |
| 243 | def test_simple(): |