()
| 267 | |
| 268 | |
| 269 | def test_cantrace(): |
| 270 | traced = [] |
| 271 | |
| 272 | def trace(frame, event, *args): |
| 273 | if frame.f_code == TestHook.__call__.__code__: |
| 274 | traced.append(event) |
| 275 | |
| 276 | old = sys.settrace(trace) |
| 277 | try: |
| 278 | with TestHook() as hook: |
| 279 | # No traced call |
| 280 | eval("1") |
| 281 | |
| 282 | # No traced call |
| 283 | hook.__cantrace__ = False |
| 284 | eval("2") |
| 285 | |
| 286 | # One traced call |
| 287 | hook.__cantrace__ = True |
| 288 | eval("3") |
| 289 | |
| 290 | # Two traced calls (writing to private member, eval) |
| 291 | hook.__cantrace__ = 1 |
| 292 | eval("4") |
| 293 | |
| 294 | # One traced call (writing to private member) |
| 295 | hook.__cantrace__ = 0 |
| 296 | finally: |
| 297 | sys.settrace(old) |
| 298 | |
| 299 | assertSequenceEqual(["call"] * 4, traced) |
| 300 | |
| 301 | |
| 302 | def test_mmap(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…