(self)
| 2365 | |
| 2366 | @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: None != (('/home/fanninpm/Documents/GitHub/RustPy[74 chars]g'),) |
| 2367 | def test_origin_tracking(self): |
| 2368 | orig_depth = sys.get_coroutine_origin_tracking_depth() |
| 2369 | try: |
| 2370 | async def corofn(): |
| 2371 | pass |
| 2372 | |
| 2373 | sys.set_coroutine_origin_tracking_depth(0) |
| 2374 | self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0) |
| 2375 | |
| 2376 | with contextlib.closing(corofn()) as coro: |
| 2377 | self.assertIsNone(coro.cr_origin) |
| 2378 | |
| 2379 | sys.set_coroutine_origin_tracking_depth(1) |
| 2380 | self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 1) |
| 2381 | |
| 2382 | fname, lineno = self.here() |
| 2383 | with contextlib.closing(corofn()) as coro: |
| 2384 | self.assertEqual(coro.cr_origin, |
| 2385 | ((fname, lineno + 1, "test_origin_tracking"),)) |
| 2386 | |
| 2387 | sys.set_coroutine_origin_tracking_depth(2) |
| 2388 | self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 2) |
| 2389 | |
| 2390 | def nested(): |
| 2391 | return (self.here(), corofn()) |
| 2392 | fname, lineno = self.here() |
| 2393 | ((nested_fname, nested_lineno), coro) = nested() |
| 2394 | with contextlib.closing(coro): |
| 2395 | self.assertEqual(coro.cr_origin, |
| 2396 | ((nested_fname, nested_lineno, "nested"), |
| 2397 | (fname, lineno + 1, "test_origin_tracking"))) |
| 2398 | |
| 2399 | # Check we handle running out of frames correctly |
| 2400 | sys.set_coroutine_origin_tracking_depth(1000) |
| 2401 | with contextlib.closing(corofn()) as coro: |
| 2402 | self.assertTrue(2 < len(coro.cr_origin) < 1000) |
| 2403 | |
| 2404 | # We can't set depth negative |
| 2405 | with self.assertRaises(ValueError): |
| 2406 | sys.set_coroutine_origin_tracking_depth(-1) |
| 2407 | # And trying leaves it unchanged |
| 2408 | self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 1000) |
| 2409 | |
| 2410 | finally: |
| 2411 | sys.set_coroutine_origin_tracking_depth(orig_depth) |
| 2412 | |
| 2413 | @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: RuntimeWarning not triggered |
| 2414 | def test_origin_tracking_warning(self): |
nothing calls this directly
no test coverage detected