def test_debug_mode_manages_coroutine_origin_tracking(self): async def start(): self.assertTrue(sys.get_coroutine_origin_tracking_depth() > 0) self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0) self.loop.set_debug(True) self.loop.run_until_complete(start()) self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0)
def test_debug_mode_manages_coroutine_origin_tracking(self): async def start(): self.assertTrue(sys.get_coroutine_origin_tracking_depth() > 0) self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0) self.loop.set_debug(True) self.loop.run_until_complete(start()) self.assertEqual(sys.get_coroutine_origin_tracking_depth(), 0)
def test_coroutine_origin_tracking_depth(self): import sys depth = sys.get_coroutine_origin_tracking_depth() assert depth == 0 try: sys.set_coroutine_origin_tracking_depth(6) depth = sys.get_coroutine_origin_tracking_depth() assert depth == 6 with raises(ValueError): sys.set_coroutine_origin_tracking_depth(-5) finally: sys.set_coroutine_origin_tracking_depth(0)
def test_loop_get_set_debug_restores_coroutine_origin_tracking_depth( loop: GLibEventLoop): sys.set_coroutine_origin_tracking_depth(123) loop.set_debug(True) loop.set_debug(False) assert sys.get_coroutine_origin_tracking_depth() == 123
def test_loop_get_set_debug(loop: GLibEventLoop): loop.set_debug(True) assert loop.get_debug() is True assert sys.get_coroutine_origin_tracking_depth( ) == aioglib.constants.DEBUG_STACK_DEPTH loop.set_debug(False) assert loop.get_debug() is False
def _set_coroutine_origin_tracking(self, enabled: bool) -> None: # Requires sys.get_coroutine_origin_tracking_depth(), added in Python 3.7. if not PY_37: return if bool(enabled) == bool(self._coroutine_origin_tracking_enabled): return if enabled: # Save tracking depth to restore later. self._cot_saved_depth = sys.get_coroutine_origin_tracking_depth() sys.set_coroutine_origin_tracking_depth( constants.DEBUG_STACK_DEPTH) else: # Restore original depth. if self._cot_saved_depth is not None: sys.set_coroutine_origin_tracking_depth(self._cot_saved_depth) self._cot_saved_depth = None self._coroutine_origin_tracking_enabled = enabled
def test_pickling_origin(self): old_coroutine_origin_tracking_depth = sys.get_coroutine_origin_tracking_depth( ) self.addCleanup(sys.set_coroutine_origin_tracking_depth, old_coroutine_origin_tracking_depth) sys.set_coroutine_origin_tracking_depth(5) c = self.c() self.assertEqual(c.send(None), 1) orig_origin = c.cr_origin self.assertIsInstance(orig_origin, tuple) p = self.dumps(c) c = self.loads(p) self.assertIsInstance(c, types.CoroutineType) self.assertIsNotNone(c.cr_await) self.assertIsNotNone(c.cr_frame) origin = c.cr_origin self.assertIsInstance(origin, tuple) self.assertIsNot(origin, orig_origin) self.assertTupleEqual(orig_origin, origin) self.assertRaises(StopIteration, c.send, None)
async def start(): self.assertTrue(sys.get_coroutine_origin_tracking_depth() > 0)
print(sys.getwindowsversion()) def firstiter(): print('from firstiter.') def finalizer(): print('from finalizer.') sys.set_asyncgen_hooks(firstiter, finalizer) print(sys.get_asyncgen_hooks()) print(sys.get_coroutine_origin_tracking_depth()) print(sys.hash_info) print(sys.hexversion) print(sys.implementation) print(sys.int_info) print(sys.__interactivehook__) s1 = sys.intern('hello!哈哈') s2 = 'hello!哈哈' s3 = ('hello!哈哈') print(s1 == s2) print(s1 is s3)
async def coroutine_wrapper_deprecated(): # set_coroutine_wrapper() and sys.get_coroutine_wrapper() will be removed in Python 3.8 sys.set_coroutine_wrapper(sys.get_coroutine_wrapper()) # and are deprecated in favor of sys.set_coroutine_origin_tracking_depth( sys.get_coroutine_origin_tracking_depth())
async def start(): self.assertTrue(sys.get_coroutine_origin_tracking_depth() > 0)